mirror of
https://github.com/csd4ni3l/shatterstack.git
synced 2026-01-01 04:23:48 +01:00
Add tile destroy animations
This commit is contained in:
35
game/play.py
35
game/play.py
@@ -1,4 +1,4 @@
|
|||||||
import os, arcade, arcade.gui, random, json, time, copy
|
import os, arcade, arcade.gui, random, json, time
|
||||||
|
|
||||||
from game.sprites import Shape
|
from game.sprites import Shape
|
||||||
from utils.constants import SHAPES, CELL_SIZE, ROWS, COLS, OUTLINE_WIDTH, COLORS, COMBO_TIME, button_style
|
from utils.constants import SHAPES, CELL_SIZE, ROWS, COLS, OUTLINE_WIDTH, COLORS, COMBO_TIME, button_style
|
||||||
@@ -33,6 +33,9 @@ class Game(arcade.gui.UIView):
|
|||||||
else:
|
else:
|
||||||
self.high_score = 0
|
self.high_score = 0
|
||||||
|
|
||||||
|
self.tiles_to_destroy: list[tuple[int, int]] = []
|
||||||
|
self.tiles_to_destroy_classes: dict[tuple[int, int], arcade.SpriteSolidColor] = {}
|
||||||
|
|
||||||
self.score = 0
|
self.score = 0
|
||||||
self.combo = 0
|
self.combo = 0
|
||||||
self.last_combo = time.perf_counter()
|
self.last_combo = time.perf_counter()
|
||||||
@@ -93,7 +96,7 @@ class Game(arcade.gui.UIView):
|
|||||||
tile_col = grid_col + offset_col
|
tile_col = grid_col + offset_col
|
||||||
tile_row = grid_row + offset_row
|
tile_row = grid_row + offset_row
|
||||||
|
|
||||||
if not (0 <= tile_row < ROWS and 0 <= tile_col < COLS) or self.occupied[tile_row][tile_col]:
|
if not (0 <= tile_row < ROWS and 0 <= tile_col < COLS) or self.occupied[tile_row][tile_col] or (tile_row, tile_col) in self.tiles_to_destroy:
|
||||||
self.can_place_shape = False
|
self.can_place_shape = False
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -164,9 +167,8 @@ class Game(arcade.gui.UIView):
|
|||||||
|
|
||||||
def update_game(self):
|
def update_game(self):
|
||||||
for row, col in self.collided_tile_positions:
|
for row, col in self.collided_tile_positions:
|
||||||
self.shape_list.remove(self.occupied[row][col])
|
self.tiles_to_destroy.append((row, col))
|
||||||
|
self.tiles_to_destroy_classes[(row, col)] = self.occupied[row][col]
|
||||||
self.create_empty_tile(row, col)
|
|
||||||
|
|
||||||
self.score += 25 + (10 * self.combo)
|
self.score += 25 + (10 * self.combo)
|
||||||
|
|
||||||
@@ -181,10 +183,29 @@ class Game(arcade.gui.UIView):
|
|||||||
self.high_score = self.score
|
self.high_score = self.score
|
||||||
self.high_score_label.text = f"High Score: {self.high_score}"
|
self.high_score_label.text = f"High Score: {self.high_score}"
|
||||||
|
|
||||||
|
self.check_game_over()
|
||||||
|
|
||||||
|
def on_update(self, _):
|
||||||
if time.perf_counter() - self.last_combo >= COMBO_TIME:
|
if time.perf_counter() - self.last_combo >= COMBO_TIME:
|
||||||
self.combo = 0
|
self.combo = 0
|
||||||
|
self.score_label.text = f"Score: {self.score}"
|
||||||
|
|
||||||
self.check_game_over()
|
for row, col in self.tiles_to_destroy[:]:
|
||||||
|
tile = self.tiles_to_destroy_classes.get((row, col))
|
||||||
|
if not tile:
|
||||||
|
self.tiles_to_destroy.remove((row, col))
|
||||||
|
self.tiles_to_destroy_classes.pop((row, col), None)
|
||||||
|
continue
|
||||||
|
|
||||||
|
tile.scale = (tile.scale_x - 0.05, tile.scale_y - 0.05)
|
||||||
|
|
||||||
|
if tile.scale_x <= 0.05:
|
||||||
|
self.tiles_to_destroy.remove((row, col))
|
||||||
|
self.tiles_to_destroy_classes.pop((row, col))
|
||||||
|
tile.remove_from_sprite_lists()
|
||||||
|
del tile
|
||||||
|
|
||||||
|
self.create_empty_tile(row, col)
|
||||||
|
|
||||||
def check_game_over(self):
|
def check_game_over(self):
|
||||||
for grid_row in range(ROWS):
|
for grid_row in range(ROWS):
|
||||||
@@ -195,7 +216,7 @@ class Game(arcade.gui.UIView):
|
|||||||
tile_col = grid_col + offset_col
|
tile_col = grid_col + offset_col
|
||||||
tile_row = grid_row + offset_row
|
tile_row = grid_row + offset_row
|
||||||
|
|
||||||
if not (0 <= tile_row < ROWS and 0 <= tile_col < COLS) or self.occupied[tile_row][tile_col]:
|
if not (tile_row, tile_col) in self.tiles_to_destroy and (not (0 <= tile_row < ROWS and 0 <= tile_col < COLS) or self.occupied[tile_row][tile_col]):
|
||||||
can_place = False
|
can_place = False
|
||||||
|
|
||||||
if can_place:
|
if can_place:
|
||||||
|
|||||||
6
uv.lock
generated
6
uv.lock
generated
@@ -212,9 +212,9 @@ requires-dist = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typing-extensions"
|
name = "typing-extensions"
|
||||||
version = "4.13.2"
|
version = "4.14.0"
|
||||||
source = { registry = "https://pypi.org/simple" }
|
source = { registry = "https://pypi.org/simple" }
|
||||||
sdist = { url = "https://files.pythonhosted.org/packages/f6/37/23083fcd6e35492953e8d2aaaa68b860eb422b34627b13f2ce3eb6106061/typing_extensions-4.13.2.tar.gz", hash = "sha256:e6c81219bd689f51865d9e372991c540bda33a0379d5573cddb9a3a23f7caaef", size = 106967, upload_time = "2025-04-10T14:19:05.416Z" }
|
sdist = { url = "https://files.pythonhosted.org/packages/d1/bc/51647cd02527e87d05cb083ccc402f93e441606ff1f01739a62c8ad09ba5/typing_extensions-4.14.0.tar.gz", hash = "sha256:8676b788e32f02ab42d9e7c61324048ae4c6d844a399eebace3d4979d75ceef4", size = 107423, upload_time = "2025-06-02T14:52:11.399Z" }
|
||||||
wheels = [
|
wheels = [
|
||||||
{ url = "https://files.pythonhosted.org/packages/8b/54/b1ae86c0973cc6f0210b53d508ca3641fb6d0c56823f288d108bc7ab3cc8/typing_extensions-4.13.2-py3-none-any.whl", hash = "sha256:a439e7c04b49fec3e5d3e2beaa21755cadbbdc391694e28ccdd36ca4a1408f8c", size = 45806, upload_time = "2025-04-10T14:19:03.967Z" },
|
{ url = "https://files.pythonhosted.org/packages/69/e0/552843e0d356fbb5256d21449fa957fa4eff3bbc135a74a691ee70c7c5da/typing_extensions-4.14.0-py3-none-any.whl", hash = "sha256:a1514509136dd0b477638fc68d6a91497af5076466ad0fa6c338e44e359944af", size = 43839, upload_time = "2025-06-02T14:52:10.026Z" },
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user