pneuma-pygame/effects/magic_effects.py

66 lines
2.6 KiB
Python
Raw Normal View History

2023-10-04 02:37:28 +00:00
import os
2023-06-14 12:15:05 +00:00
import pygame
from random import randint
from configs.system.window_config import TILESIZE
2023-06-14 12:15:05 +00:00
class MagicPlayer:
def __init__(self, animation_player):
self.animation_player = animation_player
2023-10-04 02:37:28 +00:00
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')
2023-06-14 12:15:05 +00:00
# Sound Setup
2023-10-04 02:37:28 +00:00
self.sounds = {
'heal': pygame.mixer.Sound(f'{asset_path}/audio/heal.wav'),
'flame': pygame.mixer.Sound(f'{asset_path}/audio/flame.wav')
}
2023-11-19 03:27:47 +00:00
self.sounds['flame'].set_volume(0)
2023-06-14 12:15:05 +00:00
def heal(self, player, strength, cost, groups):
if player.stats.energy >= cost:
2023-10-04 02:37:28 +00:00
self.sounds['heal'].play()
player.stats.health += strength
player.stats.energy -= cost
if player.stats.health >= player.stats.stats['health']:
player.stats.health = player.stats.stats['health']
self.animation_player.generate_particles(
'aura', player.rect.center, groups)
self.animation_player.generate_particles(
'heal', player.rect.center + pygame.math.Vector2(0, -50), groups)
2023-06-14 12:15:05 +00:00
def flame(self, player, cost, groups):
if player.stats.energy >= cost:
player.stats.energy -= cost
2023-10-04 02:37:28 +00:00
self.sounds['flame'].play()
2023-10-04 02:37:28 +00:00
if player._input.status.split('_')[0] == 'right':
direction = pygame.math.Vector2(1, 0)
2023-10-04 02:37:28 +00:00
elif player._input.status.split('_')[0] == 'left':
direction = pygame.math.Vector2(-1, 0)
2023-10-04 02:37:28 +00:00
elif player._input.status.split('_')[0] == 'up':
direction = pygame.math.Vector2(0, -1)
2023-06-14 12:15:05 +00:00
else:
direction = pygame.math.Vector2(0, 1)
2023-06-14 12:15:05 +00:00
for i in range(1, 6):
if direction.x:
offset_x = direction.x * i * TILESIZE
x = player.rect.centerx + offset_x + \
randint(-TILESIZE // 3, TILESIZE // 3)
y = player.rect.centery + \
randint(-TILESIZE // 3, TILESIZE // 3)
self.animation_player.generate_particles(
'flame', (x, y), groups)
2023-06-14 12:15:05 +00:00
else:
offset_y = direction.y * i * TILESIZE
x = player.rect.centerx + \
randint(-TILESIZE // 3, TILESIZE // 3)
y = player.rect.centery + offset_y + \
randint(-TILESIZE // 3, TILESIZE // 3)
self.animation_player.generate_particles(
'flame', (x, y), groups)