data/components/attack.py (view raw)
1"""
2Sprites for attacks.
3"""
4import sys
5import pygame as pg
6from .. import setup, tools
7
8#Python 2/3 compatibility.
9if sys.version_info[0] == 2:
10 range = xrange
11
12class Fire(pg.sprite.Sprite):
13 """
14 Fire animation for attacks.
15 """
16 def __init__(self, x, y):
17 super(Fire, self).__init__()
18 self.spritesheet = setup.GFX['explosion']
19 self.get_image = tools.get_image
20 self.image_list = self.make_image_list()
21 self.index = 0
22 self.image = self.image_list[self.index]
23 self.rect = self.image.get_rect(left=x, top=y)
24 self.timer = 0.0
25
26 def make_image_list(self):
27 """
28 Make a list of images to cycle through for the
29 animation.
30 """
31 image_list = []
32
33 for row in range(8):
34 for column in range(8):
35 posx = column * 128
36 posy = row * 128
37 new_image = self.get_image(posx, posy, 128, 128,
38 self.spritesheet)
39 image_list.append(new_image)
40
41 return image_list
42
43 def update(self):
44 """
45 Update fire explosion.
46 """
47 if self.index < (len(self.image_list) - 1):
48 self.index += 1
49 self.image = self.image_list[self.index]
50 elif self.index == (len(self.image_list) - 1):
51 self.kill()