-
Notifications
You must be signed in to change notification settings - Fork 0
/
magic.py
50 lines (44 loc) · 2.69 KB
/
magic.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pygame
from settings import *
from random import randint
class MagicPlayer:
def __init__(self, animation_player):
self.animation_player = animation_player
self.sounds = {
'heal': pygame.mixer.Sound('./audio/heal.wav'),
'flame': pygame.mixer.Sound('./audio/Fire.wav')
}
self.sounds['flame'].set_volume(0.6)
self.sounds['heal'].set_volume(0.6)
def heal(self, player, strength, cost, groups):
if player.energy >= cost:
self.sounds['heal'].play()
player.health += strength
player.energy -= cost
# prevents overhealing your hp bar
if player.health >= player.stats['health']:
player.health = player.stats['health']
self.animation_player.create_particles(
'aura', player.rect.center, groups)
self.animation_player.create_particles(
'heal', player.rect.center + pygame.math.Vector2(0, -60), groups) # the vector2 gives a small particle on top of player
def flame(self, player, cost, groups):
if player.energy >= cost:
self.sounds['flame'].play()
player.energy -= cost
# to prevent getting up_idle or up_attack, we only want word before _
if player.status.split('_')[0] == 'right': direction = pygame.math.Vector2(1, 0)
elif player.status.split('_')[0] == 'left': direction = pygame.math.Vector2(-1, 0)
elif player.status.split('_')[0] == 'up': direction = pygame.math.Vector2(0, -1)
else: direction = pygame.math.Vector2(0, 1) # player.stats.split('_')[0] == 'down':
for i in range(1, 6):# use i for offset, first element is 1, multiply 1 by tilesize to get offset of 64 pixels to player center
if direction.x: #horizontal
offset_x = (direction.x * i) * TILESIZE # more info on video at 6:15:44
x = player.rect.centerx + offset_x + randint(-TILESIZE // 3, TILESIZE // 3) # flames start from center of player, randint to randomize flame graphics
y = player.rect.centery + randint(-TILESIZE // 3, TILESIZE // 3)
self.animation_player.create_particles('flame', (x,y), groups)
else: #vertical
offset_y = (direction.y * i) * TILESIZE # more info on video at 6:15:44
x = player.rect.centerx + randint(-TILESIZE // 3, TILESIZE // 3) # flames start from center of player, randint to randomize flame graphics
y = player.rect.centery + offset_y + randint(-TILESIZE // 3, TILESIZE // 3)
self.animation_player.create_particles('flame', (x,y), groups)