pneuma-pygame/effects/weapon_effects.py

34 lines
1.1 KiB
Python
Raw Normal View History

import os
import pygame
class Weapon(pygame.sprite.Sprite):
def __init__(self, player, groups):
super().__init__(groups)
script_dir = os.path.dirname(os.path.abspath(__file__))
asset_path = os.path.join(
2023-11-14 21:44:43 +00:00
script_dir, '..', 'assets')
self.sprite_type = 'weapon'
2023-10-04 02:37:28 +00:00
direction = player._input.status.split('_')[0]
# Graphic
full_path = f"{asset_path}/graphics/weapons/{player._input.combat.weapon}/{direction}.png"
self.image = pygame.image.load(full_path).convert_alpha()
# Sprite Placement
if direction == 'right':
self.rect = self.image.get_rect(
midleft=player.rect.midright + pygame.math.Vector2(0, 16))
elif direction == 'left':
self.rect = self.image.get_rect(
midright=player.rect.midleft + pygame.math.Vector2(0, 16))
elif direction == 'down':
self.rect = self.image.get_rect(
midtop=player.rect.midbottom + pygame.math.Vector2(-10, 0))
else:
self.rect = self.image.get_rect(
midbottom=player.rect.midtop + pygame.math.Vector2(-10, 0))