-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweapon.py
221 lines (183 loc) · 6.33 KB
/
weapon.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import pygame
import data
import support
import chunks
import particle
import random
import functools
from consts import *
class Weapon(chunks.Sprite):
def __init__(self, pos, kind, groups):
self.radius = WEAPONS[kind][WEAPON_RADID]
self.size = WEAPONS[kind][WEAPON_SIZEID]
self.pos = pygame.Vector2(pos)
self.duration = WEAPONS[kind][WEAPON_DURATIONID]
self.born_time = data.ticks
super().__init__(None, data.assets.get_weapon(kind), groups, pos)
def check_finish(self):
if data.ticks - self.born_time >= self.duration:
self.on_finish()
self.kill()
def on_finish(self): ...
def update(self):
self.check_finish()
class PurpleHole(Weapon):
def __init__(self, pos):
super().__init__(
pos,
"purple_hole",
[
data.game.purpleholes,
data.game.objects,
data.game.enemy_damages,
data.game.weapon_bodies,
data.game.asteroid_damages,
],
)
self.sucked = set()
def collidesuck(self, pos):
return self.pos.distance_to(pos) <= self.radius
def collidecenter(self, pos):
return self.pos.distance_to(pos) <= self.size / 4
def on_finish(self):
data.assets.play("suck")
particle.GrowParticle(
self.rect.center, self.rect.w, 2, WEAPON_DISAPPEAR_SPEED, self.image
)
class RedHoleClone(Weapon):
def __init__(self, pos):
super().__init__(
pos,
"red_hole",
[
data.game.objects,
data.game.enemy_damages,
data.game.weapon_bodies,
data.game.asteroid_damages,
],
)
self.duration += random.randint(500, 1200)
def collidecenter(self, pos):
return self.pos.distance_to(pos) <= self.radius / 2
def on_finish(self):
data.assets.play("suck")
particle.GrowParticle(
self.rect.center, self.rect.w, 2, WEAPON_DISAPPEAR_SPEED, self.image
)
class WhiteHole(Weapon):
def __init__(self, pos):
self.last_particle = data.ticks
super().__init__(
pos, "white_hole", [data.game.objects, data.game.weapon_bodies]
)
def collidecenter(self, pos):
return self.pos.distance_to(pos) <= self.size / 4
def shoot(self):
# if random.randint(0, 100) < 30:
data.assets.play("wh_attack")
particle.MoveParticle(
self.pos,
support.randvec(),
WHITEHOLE_PARTICLE_SPEED,
self.radius,
data.assets.get_particle(),
[data.game.enemy_damages, data.game.asteroid_damages],
)
def on_finish(self):
data.assets.play("suck")
particle.GrowParticle(
self.rect.center, self.rect.w, 2, WEAPON_DISAPPEAR_SPEED, self.image
)
def update(self):
if data.ticks - self.last_particle >= WHITEHOLE_SHOOT_COOLDOWN:
self.shoot()
self.last_particle = data.ticks
self.check_finish()
class Supernova(Weapon):
def __init__(self, pos):
super().__init__(pos, "supernova", [data.game.objects, data.game.weapon_bodies])
self.original_image = self.image
data.assets.play("supernova")
def collidecenter(self, pos):
return self.pos.distance_to(pos) <= self.size / (1.4 * 2)
def update(self):
self.check_finish()
self.image = self.original_image.copy()
color = SUPERNOVA_START.lerp(
SUPRNOVA_END,
pygame.math.clamp((data.ticks - self.born_time) / self.duration, 0, 1),
)
self.image.fill(color, special_flags=pygame.BLEND_RGB_MULT)
def on_finish(self):
data.assets.play("big_explosion")
particle.SupernovaExplosion(self.pos, SUPERNOVA_COLS[0])
class WormHole(Weapon):
def __init__(self, pos):
super().__init__(pos, "worm_hole", [data.game.objects])
data.assets.play("worm_hole")
data.game.wormhole = self
self.teleport_pos = pygame.Vector2(support.randpos(UNIVERSE_RECT))
self.static_image = self.image.copy()
self.speed = 0
self.angle = 0
def on_finish(self):
data.assets.play("teleport")
data.game.wormhole = None
data.player.rect.center = self.teleport_pos
for res in data.player.resources:
res.rect.center = self.teleport_pos
particle.GrowParticle(
self.teleport_pos,
1,
self.rect.w * 1.5,
700,
data.assets.get_weapon("worm_holeB"),
[data.game.objects],
)
def update(self):
self.check_finish()
self.speed += data.dt * WORMHOLE_ACC
self.angle += data.dt * self.speed
self.image = pygame.transform.rotate(self.static_image, self.angle)
self.rect = self.image.get_rect(center=self.rect.center)
def RedHole():
for enemy in data.game.pack.enemies:
pos = enemy.rect.center
particle.GrowParticle(
pos,
2,
WEAPONS["red_hole"][WEAPON_SIZEID],
random.randint(150, 250),
data.assets.get_weapon("red_hole"),
finish_func=functools.partial(RedHoleClone, pos),
)
class Shield(Weapon):
def __init__(self, *_):
super().__init__(data.player.rect.center, "shield", [data.game.objects])
self.static_image = self.image
self.angle = 0
data.game.shield = self
data.assets.play("shield")
def collidecenter(self, pos):
return self.pos.distance_to(pos) <= self.radius
def on_finish(self):
data.game.shield = None
data.assets.play("suck")
particle.GrowParticle(
self.rect.center, self.rect.w, 2, WEAPON_DISAPPEAR_SPEED, self.image
)
def update(self):
self.check_finish()
self.angle += data.dt * SHIELD_ROT_SPEED
self.image = pygame.transform.rotate(self.static_image, self.angle)
self.rect = self.image.get_rect()
self.rect.center = data.player.rect.center
self.pos = pygame.Vector2(self.rect.center)
WEAPON_CLASSES = {
"red_hole": RedHole,
"purple_hole": PurpleHole,
"white_hole": WhiteHole,
"supernova": Supernova,
"worm_hole": WormHole,
"shield": Shield,
}