all repos — Legends-RPG @ 4645ed014caaacc7e7e223db3fb522ffef4b1df1

A fantasy mini-RPG built with Python and Pygame.

data/components/attackitems.py (view raw)

 1"""
 2Attack equipment for battles.
 3"""
 4import copy
 5import pygame as pg
 6from .. import tools, setup
 7
 8
 9class Sword(object):
10    """
11    Sword that appears during regular attacks.
12    """
13    def __init__(self, player):
14        self.player = player
15        self.sprite_sheet = setup.GFX['shopsigns']
16        self.image_list = self.make_image_list()
17        self.index = 0
18        self.timer = 0.0
19
20    def make_image_list(self):
21        """
22        Make the list of two images for animation.
23        """
24        image_list = [tools.get_image(48, 0, 16, 16, self.sprite_sheet),
25                      tools.get_image(0, 0, 22, 16, setup.GFX['sword2'])]
26        return image_list
27
28    @property
29    def image(self):
30        new_image = self.image_list[self.index]
31        return pg.transform.scale2x(new_image)
32
33    @property
34    def rect(self):
35        new_rect = copy.copy(self.player.rect)
36        new_rect.bottom += 17
37        new_rect.right -= 16
38        return new_rect
39
40    def update(self, current_time):
41        if (current_time - self.timer) > 60:
42            self.timer = current_time
43            if self.index == 0:
44                self.index += 1
45            else:
46                self.index -= 1
47
48    def draw(self, surface):
49        """
50        Draw sprite to surface.
51        """
52        if self.player.state == 'attack':
53            surface.blit(self.image, self.rect)
54