-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweapon.py
23 lines (19 loc) · 947 Bytes
/
weapon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pygame
class Weapon(pygame.sprite.Sprite):
def __init__(self, player, groups):
super().__init__(groups)
direction = player.status.split('_', 1)[0]
# graphic
full_path = f'assets/images/weapons/{player.weapon}/{direction}.png'
self.image = pygame.image.load(full_path).convert_alpha()
# placement
if direction == 'up':
self.rect = self.image.get_rect(midbottom=player.rect.midtop + pygame.math.Vector2(-10, 0))
elif direction == 'down':
self.rect = self.image.get_rect(midtop=player.rect.midbottom + pygame.math.Vector2(-10, 0))
elif direction == 'left':
self.rect = self.image.get_rect(midright=player.rect.midleft + pygame.math.Vector2(0, 16))
elif direction == 'right':
self.rect = self.image.get_rect(midleft=player.rect.midright + pygame.math.Vector2(0, 16))
else:
print("Error")