mirror of
https://github.com/csd4ni3l/shatterstack.git
synced 2026-01-01 04:23:48 +01:00
Initial version
This commit is contained in:
50
game/sprites.py
Normal file
50
game/sprites.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import arcade, random
|
||||
from utils.constants import SHAPES, COLORS, CELL_SIZE, OUTLINE_WIDTH
|
||||
|
||||
class Shape():
|
||||
def __init__(self, x, y, shape_type, shape_color, sprite_list: arcade.SpriteList):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.sprite_list = sprite_list
|
||||
self.shape_type = shape_type
|
||||
self.shape_color = shape_color
|
||||
self.tiles = []
|
||||
|
||||
self.setup_grid()
|
||||
|
||||
def update(self, shape, color, x=None, y=None):
|
||||
if x:
|
||||
self.x = x
|
||||
if y:
|
||||
self.y = y
|
||||
|
||||
self.shape_type = shape
|
||||
self.shape_color = color
|
||||
|
||||
n = 0
|
||||
|
||||
for tile in self.tiles:
|
||||
tile.visible = False
|
||||
|
||||
for offset_col, offset_row in SHAPES[self.shape_type]:
|
||||
x = self.x + (offset_col * (CELL_SIZE + OUTLINE_WIDTH))
|
||||
y = self.y + (offset_row * (CELL_SIZE + OUTLINE_WIDTH))
|
||||
|
||||
if n < len(self.tiles):
|
||||
self.tiles[n].position = x, y, 0
|
||||
self.tiles[n].color = color
|
||||
self.tiles[n].visible = True
|
||||
else:
|
||||
self.tiles.append(arcade.SpriteSolidColor(width=CELL_SIZE, height=CELL_SIZE,
|
||||
color=color, center_x=x, center_y=y))
|
||||
self.sprite_list.append(self.tiles[-1])
|
||||
|
||||
n += 1
|
||||
|
||||
def setup_grid(self):
|
||||
for offset_col, offset_row in SHAPES[self.shape_type]:
|
||||
x = self.x + (offset_col * (CELL_SIZE + OUTLINE_WIDTH))
|
||||
y = self.y + (offset_row * (CELL_SIZE + OUTLINE_WIDTH))
|
||||
self.tiles.append(arcade.SpriteSolidColor(width=CELL_SIZE, height=CELL_SIZE,
|
||||
color=self.shape_color, center_x=x, center_y=y))
|
||||
self.sprite_list.append(self.tiles[-1])
|
||||
Reference in New Issue
Block a user