-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectile.py
More file actions
123 lines (78 loc) · 3.19 KB
/
Copy pathprojectile.py
File metadata and controls
123 lines (78 loc) · 3.19 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import pygame
from pygame import Vector2
from common import *
from entity import Entity
from animation import Animation
from vfx import VisualEffect
class Projectile(Entity):
def __init__(self, pos, direction, stats):
Entity.__init__(self, pos, stats.col_layer)
self.stats = stats
self.dir = direction
self.graphics = Animation(self.stats.anim_filepath, True, 2)
def update(self, delta):
self.pos += self.dir * (self.stats.speed * delta)
if self.pos.x < 0 or self.pos.x >= WIDTH or self.pos.y < 0 or self.pos.y >= HEIGHT:
self.die()
def collide(self, other):
self.die()
if self.stats.hit_effect is not None:
# play effect when hitting entitiy
if other.col_layer == EntityLayers.OBSTACLE: # if entity is obstacle play different effect
VisualEffect(self.pos.copy(), "assets/gfx/vfx/null_hit.png")
else:
VisualEffect(self.pos.copy(), self.stats.hit_effect)
class Spell(Projectile):
def __init__(self, pos, direction):
Projectile.__init__(self, pos, direction, projectile_types["Spell"])
# only needs to rotate according to direction
self.rot = self.dir.copy()
class PBomb(Projectile):
def __init__(self, pos, direction):
Projectile.__init__(self, pos, direction, projectile_types["Pumpkin Bomb"])
# must not loop animation
self.graphics.loop = False
def update(self, delta):
super().update(delta)
# explodes on animation end regardless of collision
if self.graphics.end:
self.explode()
# explode, spawning explosion entity
def explode(self):
self.die()
PBombExplode(self.pos.copy())
def collide(self, other):
self.explode()
class PBombExplode(Projectile):
def __init__(self, pos):
Projectile.__init__(self, pos, Vector2(1, 0), projectile_types["Bomb Explosion"])
self.graphics.loop = False
# is only removed on animation end
def update(self, delta):
if self.graphics.end:
self.die()
def collide(self, other):
pass
class Fish(Projectile):
def __init__(self, pos, direction):
Projectile.__init__(self, pos, direction, projectile_types["Fish"])
class Shark(Projectile):
def __init__(self, pos, direction):
Projectile.__init__(self, pos, direction, projectile_types["Shark"])
self.rect.size = (48, 48)
self.rot = self.dir.copy()
# does not die on collision
def collide(self, other):
if self.stats.hit_effect is not None:
if other.col_layer == EntityLayers.OBSTACLE:
VisualEffect(self.pos.copy(), "assets/gfx/vfx/null_hit.png")
self.die()
else:
VisualEffect(self.pos.copy(), self.stats.hit_effect)
class Spud(Projectile):
def __init__(self, pos, direction):
Projectile.__init__(self, pos, direction, projectile_types["Spud"])
# only dies if collider was the player itself (not their bullets)
def collide(self, other):
if other.col_layer == EntityLayers.PLAYER:
Projectile.collide(self, other)