2023-09-27 18:03:37 +00:00
|
|
|
import os
|
2023-07-11 00:25:44 +00:00
|
|
|
import pygame
|
|
|
|
|
2023-11-29 10:53:30 +00:00
|
|
|
from utils.resource_loader import import_assets
|
|
|
|
|
2023-09-27 18:03:37 +00:00
|
|
|
|
2023-07-11 00:25:44 +00:00
|
|
|
class Weapon(pygame.sprite.Sprite):
|
2023-09-27 18:03:37 +00:00
|
|
|
|
2023-07-11 00:25:44 +00:00
|
|
|
def __init__(self, player, groups):
|
|
|
|
super().__init__(groups)
|
2023-09-27 18:03:37 +00:00
|
|
|
|
2023-07-11 00:25:44 +00:00
|
|
|
self.sprite_type = 'weapon'
|
2023-10-04 02:37:28 +00:00
|
|
|
direction = player._input.status.split('_')[0]
|
2023-09-27 18:03:37 +00:00
|
|
|
|
2023-07-11 00:25:44 +00:00
|
|
|
# Graphic
|
2023-11-29 10:53:30 +00:00
|
|
|
self.image = pygame.image.load(import_assets(os.path.join(
|
|
|
|
'graphics',
|
|
|
|
'weapons',
|
|
|
|
player._input.combat.weapon,
|
|
|
|
f"{direction}.png"))
|
|
|
|
).convert_alpha()
|
2023-09-27 18:03:37 +00:00
|
|
|
|
2023-07-11 00:25:44 +00:00
|
|
|
# Sprite Placement
|
|
|
|
if direction == 'right':
|
2023-09-27 18:03:37 +00:00
|
|
|
self.rect = self.image.get_rect(
|
2023-11-29 11:10:04 +00:00
|
|
|
midleft=player.animation.rect.midright + pygame.math.Vector2(0, 16))
|
2023-07-11 00:25:44 +00:00
|
|
|
elif direction == 'left':
|
2023-09-27 18:03:37 +00:00
|
|
|
self.rect = self.image.get_rect(
|
2023-11-29 11:10:04 +00:00
|
|
|
midright=player.animation.rect.midleft + pygame.math.Vector2(0, 16))
|
2023-07-11 00:25:44 +00:00
|
|
|
elif direction == 'down':
|
2023-09-27 18:03:37 +00:00
|
|
|
self.rect = self.image.get_rect(
|
2023-11-29 11:10:04 +00:00
|
|
|
midtop=player.animation.rect.midbottom + pygame.math.Vector2(-10, 0))
|
2023-07-11 00:25:44 +00:00
|
|
|
else:
|
2023-09-27 18:03:37 +00:00
|
|
|
self.rect = self.image.get_rect(
|
2023-11-29 11:10:04 +00:00
|
|
|
midbottom=player.animation.rect.midtop + pygame.math.Vector2(-10, 0))
|