-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
46 lines (37 loc) · 1.26 KB
/
player.py
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
35
36
37
38
39
40
41
42
43
44
45
46
from globals import *
from sprites import BaseCharacter, Harmable, sprites_to_render_first
from weapons import Halo, MagicWand
class Player(BaseCharacter, Harmable):
# default values
hit_points = 100
speed = PLAYER_BASE_SPEED
_weapons = None # this will get set the first time the instance property is accessed
halo = None
status = None
stunnable = False
def __init__(self, x, y):
super().__init__()
self.image = pygame.image.load("sprites/matador.png").convert_alpha()
self.rect = self.image.get_rect()
self.x = x
self.y = y
def __str__(self):
return f"Player {self.id}"
def die(self):
print(f"{self} has died")
self.kill()
def after_damage_taken(self, weapon):
weapon.report_damage_taken(self)
self.hurt_sound.play()
@property
def weapons(self):
if self._weapons is None:
self._weapons = pygame.sprite.Group()
return self._weapons
def update(self, control):
if self.velocity.length() > 0:
self.move(self.velocity)
def after_move(self):
if self.halo:
self.halo.x = (self.x + self.width/2) - self.halo.radius
self.halo.y = (self.y + self.height/2) - self.halo.radius