all repos — Legends-RPG @ 77d11c24818c6da89b2c8cc04817e3beb8274131

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 = tools.get_image(48, 0, 16, 16, self.sprite_sheet)
17        self.image = pg.transform.scale2x(self.image)
18
19    @property
20    def rect(self):
21        new_rect = copy.copy(self.player.rect)
22        new_rect.right -= 10
23        new_rect.top += 15
24        return new_rect
25
26    def draw(self, surface):
27        """
28        Draw sprite to surface.
29        """
30        if self.player.state == 'attack':
31            if self.player.x_vel % 5 == 0:
32                 surface.blit(self.image, self.rect)
33