all repos — Legends-RPG @ adcb4e5b63401d7a453cda039c1d39f6448070a4

A fantasy mini-RPG built with Python and Pygame.

data/components/attack.py (view raw)

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