-
Notifications
You must be signed in to change notification settings - Fork 1
/
weapon.py
31 lines (25 loc) · 1.36 KB
/
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
24
25
26
27
28
29
30
import pygame
class Weapon(pygame.sprite.Sprite):
def __init__(self,player,groups):
super().__init__(groups)
#keep ref to player
self.player = player
# gets us the player direction using status and splits the other player postions (ex. up_idle) at the _ so its just 'up'
self.sprite_type = 'weapon'
direction = player.status.split('_')[0]
# #graphic of the weapon (2:51)
full_path = f"./graphics/weapons/{player.weapon}/{direction}.png"
self.image = pygame.image.load(full_path).convert_alpha()
# #weapon placement
#sets the mid position of the player box to the middle opposite position of the weapons box + an offest to line up weapon where sprite's hand appears
if direction == 'right':
self.rect = self.image.get_rect(midleft = player.rect.midright + pygame.math.Vector2(-10,6))
elif direction == 'left':
self.rect = self.image.get_rect(midright = player.rect.midleft + pygame.math.Vector2(10,6))
elif direction == 'down':
self.rect = self.image.get_rect(midtop = player.rect.midbottom + pygame.math.Vector2(11,-4))
else:
self.rect = self.image.get_rect(midbottom = player.rect.midtop + pygame.math.Vector2(-15,7))
def update(self):
if self.player.vulnerable != True:
self.kill()