-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfire.py
More file actions
34 lines (26 loc) · 1.06 KB
/
fire.py
File metadata and controls
34 lines (26 loc) · 1.06 KB
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
import pygame
from object import Object
from load_sprite_sheet import load_sprite_sheets
class Fire(Object):
ANIMATION_DELAY = 3
def __init__(self, x, y, width, height):
super().__init__(x, y, width, height, "fire")
self.fire = load_sprite_sheets("Traps", "Fire", width, height)
self.image = self.fire["off"][0]
self.mask = pygame.mask.from_surface(self.image)
self.animation_count = 0
self.animation_name = "off"
def on(self):
self.animation_name = "on"
def off(self):
self.animation_name = "off"
def loop(self):
sprites = self.fire[self.animation_name]
sprite_index = (self.animation_count //
self.ANIMATION_DELAY) % len(sprites)
self.image = sprites[sprite_index]
self.animation_count += 1
self.rect = self.image.get_rect(topleft=(self.rect.x, self.rect.y))
self.mask = pygame.mask.from_surface(self.image)
if self.animation_count // self.ANIMATION_DELAY > len(sprites):
self.animation_count = 0