-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile.py
53 lines (42 loc) · 1.6 KB
/
tile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import pygame
from game_settings import ASSET_FOLDER, FPS
from utils import import_sprites
class Tile(pygame.sprite.Sprite):
"""
A basic Tile with (x,y) coordinates and an optional Sprite
"""
def __init__(self, position: tuple, sprite):
super().__init__()
self.image = sprite
self.rect = self.image.get_rect(topleft=position)
class Interactive(Tile):
def __init__(self, position: tuple, sprite):
super().__init__(position, sprite)
self.all_sprites = import_sprites(f"{ASSET_FOLDER}/tilesets/breakable.png")
self.animations = self.set_animation_sprites()
self.break_animation_speed = 0.75
self.frame_index = 0
self.break_duration = FPS
self.start_timer = 4 * FPS # start breaking after 4 secs
self.is_broken = False
def set_animation_sprites(self) -> dict:
return {"level_one": self.all_sprites[:4]}
def breaking_animation(self):
if self.break_duration == 0:
self.is_broken = True
else:
self.break_duration -= FPS / len(self.animations["level_one"])
self.frame_index += self.break_animation_speed
self.image = self.animations["level_one"][int(self.frame_index)]
def breaks(self):
if self.is_broken:
self.kill()
if self.start_timer == 0:
self.breaking_animation()
else:
self.start_timer -= 1
def update(self):
"""A breakable tile will start the destruction process when the explosion animation
of a bomb is almost over
"""
self.breaks()