-
Notifications
You must be signed in to change notification settings - Fork 1
/
particles.py
77 lines (66 loc) · 2.77 KB
/
particles.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import pygame
from support import import_folder
from random import choice
class AnimationPlayer:
def __init__(self):
self.frames = {
# magic
'flame': import_folder('graphics/particles/flame/frames'),
'aura': import_folder('graphics/particles/aura'),
'heal': import_folder('graphics/particles/heal/frames'),
# attacks
'claw': import_folder('graphics/particles/claw'),
'slash': import_folder('graphics/particles/slash'),
'sparkle': import_folder('graphics/particles/sparkle'),
'leaf_attack': import_folder('graphics/particles/leaf_attack'),
'thunder': import_folder('graphics/particles/thunder'),
# monster deaths
'squid': import_folder('graphics/particles/smoke_orange'),
'raccoon': import_folder('graphics/particles/raccoon'),
'spirit': import_folder('graphics/particles/nova'),
'bamboo': import_folder('graphics/particles/bamboo'),
# leafs
'leaf': (
import_folder('graphics/particles/leaf1'),
import_folder('graphics/particles/leaf2'),
import_folder('graphics/particles/leaf3'),
import_folder('graphics/particles/leaf4'),
import_folder('graphics/particles/leaf5'),
import_folder('graphics/particles/leaf6'),
self.reflect_images(import_folder('graphics/particles/leaf1')),
self.reflect_images(import_folder('graphics/particles/leaf2')),
self.reflect_images(import_folder('graphics/particles/leaf3')),
self.reflect_images(import_folder('graphics/particles/leaf4')),
self.reflect_images(import_folder('graphics/particles/leaf5')),
self.reflect_images(import_folder('graphics/particles/leaf6'))
)
}
def reflect_images(self, frames):
new_frames = []
for frame in frames:
flipped_frame = pygame.transform.flip(frame, True, False)
new_frames.append(flipped_frame)
return new_frames
def create_grass_particles(self, pos, groups):
animation_frames = choice(self.frames['leaf'])
ParticleEffect(pos, animation_frames, groups)
def create_particles(self, animation_type, pos, groups):
animation_frames = self.frames[animation_type]
ParticleEffect(pos, animation_frames, groups)
class ParticleEffect(pygame.sprite.Sprite):
def __init__(self, pos, animation_frames, groups):
super().__init__(groups)
self.sprite_type = 'magic'
self.frame_index = 0
self.animation_speed = 0.15
self.frames = animation_frames
self.image = self.frames[self.frame_index]
self.rect = self.image.get_rect(center=pos)
def animate(self):
self.frame_index += self.animation_speed
if self.frame_index >= len(self.frames):
self.kill()
else:
self.image = self.frames[int(self.frame_index)]
def update(self):
self.animate()