-
Notifications
You must be signed in to change notification settings - Fork 0
/
visuals.py
420 lines (335 loc) · 12 KB
/
visuals.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# -*- coding: utf-8 -*-
import pygame
from pygame.locals import *
from random import randint, choice
from math import ceil, radians, fabs
from copy import copy
import game_values as GAMEVALUES
from fct import *
import res
class tempEffect(pygame.sprite.Sprite):
def __init__(self, particle, frames, pos):
pygame.sprite.Sprite.__init__(self)
self.phases = {}
self.image = res.images[particle][0]
self.rect = self.image.get_rect(center=pos)
self.frame = 0
self.end = frames
sequences = frames/len(res.images[particle])
imageFrame = 0
for phase in range(0, len(res.images[particle])):
self.phases[imageFrame] = res.images[particle][phase]
imageFrame += sequences
def update(self):
for phase in self.phases.items():
if self.frame >= phase[0]:
self.image = phase[1]
self.frame += 1
if self.frame >= self.end:
self.kill()
class whiteSquare(pygame.sprite.Sprite):
def __init__(self, rect):
pygame.sprite.Sprite.__init__(self)
self.rect = rect
self.fixedPos = self.rect.center
self.image = pygame.Surface((self.rect.width, self.rect.height))
def update(self):
self.rect = self.rect.inflate(-6, -6)
self.rect.center = self.fixedPos
self.image = pygame.Surface((self.rect.width, self.rect.height))
self.image.fill((255, 255, 255))
if self.rect.width <= 6 or self.rect.height <= 6:
self.kill()
class whiteCircle(pygame.sprite.Sprite):
def __init__(self, rect):
pygame.sprite.Sprite.__init__(self)
self.rect = rect
self.radius = int(self.rect.w/2)
self.image = pygame.Surface((self.rect.width, self.rect.height))
self.image.set_colorkey((0, 0, 0))
pygame.draw.circle(self.image, (255, 255, 255), (int(self.rect.w/2), int(self.rect.h/2)), self.radius)
def update(self):
self.radius -= 3
self.image = pygame.Surface((self.rect.width, self.rect.height))
self.image.set_colorkey((0, 0, 0))
pygame.draw.circle(self.image, (255, 255, 255), (int(self.rect.w/2), int(self.rect.h/2)), self.radius)
if self.radius <= 3:
self.kill()
class growingCircle(pygame.sprite.Sprite):
def __init__(self, pos, size, speed, color=(255, 255, 255)):
pygame.sprite.Sprite.__init__(self)
self.circle = 5
self.size = size
self.grow = (speed/100)*(size/2-5)
self.image = pygame.Surface((self.size+10, self.size+10), SRCALPHA)
self.rect = self.image.get_rect(center=pos)
self.color = color
def update(self):
self.circle += self.grow
if self.circle < self.size/2:
width = 6
if self.circle > self.size/2-5:
width = 1
elif self.circle > self.size/2-15:
width = 3
elif self.circle > self.size/2-25:
width = 4
elif self.circle > self.size/2-40:
width = 5
if width > self.circle:
width = 0
self.image = pygame.Surface((self.size+10, self.size+10), SRCALPHA)
pygame.draw.circle(self.image, self.color, (int(self.size/2), int(self.size/2)), int(self.circle), width)
else:
self.kill()
class particleLayer:
def __init__(self, max, pFU):
self.max = max
self.particles = []
self.speed = pFU
def update(self):
self.anim = self.speed
for particle in self.particles:
particle.update()
if particle.alpha <= 25:
self.particles.remove(particle)
def draw(self, window):
img = pygame.Surface((res.settings["PART_SIZE"], res.settings["PART_SIZE"]))
for particle in self.particles:
img.set_alpha(particle.alpha)
img.fill(particle.color)
window.blit(img, particle.rect)
def add(self, *partArgs):
partSize = len(self.particles)
for i in range(0, ceil(partArgs[0]/self.speed*res.settings["PART_NB_MULT"])):
if partSize < self.max:
particle = framePixel(*partArgs[1:], self.speed)
self.particles.append(particle)
def reset(self, max, pFU):
self.max = max
self.pFU = pFU
if len(self.particles) > self.max:
self.particles = []
class framePixel:
def __init__(self, frame, pos, color, opacity, disp, dep, speed):
self.speed = speed
self.pos = pos[0]+randint(-disp, disp), pos[1]+randint(-disp, disp)
self.rect = pygame.Rect(self.pos[0]-res.settings["PART_SIZE"]/2, self.pos[1]-res.settings["PART_SIZE"]/2, res.settings["PART_SIZE"], res.settings["PART_SIZE"])
self.motion = randFloat(-dep, dep)*self.speed, randFloat(-dep, dep)*self.speed
frame = frame/self.speed
self.alpha = opacity
self.color = color
self.alphaReduction = self.alpha/frame
self.updateWait = 0
def update(self):
if self.updateWait <= 0:
self.updateWait = self.speed
self.pos = self.pos[0]+self.motion[0], self.pos[1]+self.motion[1]
self.rect.center = self.pos
self.alpha -= self.alphaReduction
self.updateWait -= 1
def set_speed(self, speed):
self.motion = self.motion[0]*speed, self.motion[1]*speed
self.frame *= speed
self.alphaReduction *= speed
class flash(pygame.sprite.Sprite):
def __init__(self, color=(255, 255, 255), opacity=255, frame=15):
pygame.sprite.Sprite.__init__(self)
self.frame = frame
self.rect = pygame.Rect(0, 0, 1366, 768)
self.image = pygame.Surface((1366, 768))
self.image.fill(color)
self.image.set_alpha(opacity)
self.alpha = opacity
self.alphaReduction = self.alpha/frame
def update(self):
if self.frame <= 0:
self.kill()
self.frame -= 1
self.alpha -= self.alphaReduction
self.image.set_alpha(self.alpha)
class fade(pygame.sprite.Sprite):
def __init__(self, color=(255, 255, 255), opacity=255, frame=15):
pygame.sprite.Sprite.__init__(self)
self.frame = frame
self.rect = pygame.Rect(0, 0, 1366, 768)
self.image = pygame.Surface((1366, 768))
self.image.fill(color)
self.image.set_alpha(0)
self.alpha = 0
self.alphaAddition = opacity/frame
def update(self):
if self.frame <= 0:
self.kill()
self.frame -= 1
self.alpha += self.alphaAddition
self.image.set_alpha(self.alpha)
class rotativeDeco:
def __init__(self, image):
self.image = image
self.rot = randint(3, 7)
self.angle = 0
if randint(0, 1) == 0:
self.rot *= -1
def draw(self, window, pos):
window.blit(rot_center(self.image, self.angle), self.image.get_rect(center=pos))
self.angle += self.rot
class falling_beam:
def __init__(self):
r = randint(0, 255)
if r < 255:
v = randint(0, 255-r)
else:
v = 0
self.color = (r, v, 255-r-v)
self.speed = randint(5, 15)
self.pos = [randint(0, 1366), 0]
def update(self):
self.pos[1] += self.speed
if self.pos[1] >= 768+self.speed*22:
self.speed = 0
def draw(self, window):
pygame.draw.line(window, [int(c*0.3) for c in self.color], (self.pos[0], self.pos[1]-self.speed*22), self.pos, 1)
pygame.draw.line(window, [int(c*0.65) for c in self.color], (self.pos[0], self.pos[1]-self.speed*15), self.pos, 1)
pygame.draw.line(window, self.color, (self.pos[0], self.pos[1]-self.speed*5), self.pos, 3)
pygame.draw.line(window, self.color, (self.pos[0], self.pos[1]-self.speed*10), self.pos, 1)
class animated_bg:
def __init__(self):
self.bg1 = 0
self.bg2 = -768
self.objects = []
self.speed = 20
self.count = 1
self.objList = ["exit", "spikes", "largeWall", "glassBlock", "smallSquare", "wood_block", "pylone", "wood_cone", "glass_cone", "turret", "laz_turret", "laz_square", "circularSaw", "spike_square", "smallWall", "spike_wall", "a-ring", "teleporter", "spiky_wood", "spiky_wheel"]
self.objList *= 2
self.objList += ["start", "exit_close", "tesla", "square_button", "turret"]
def update(self):
if res.settings["MOVING_BG"]:
self.bg1 += 2
self.bg2 += 2
if self.bg1 >= 768:
self.bg1 = -768
elif self.bg2 >= 768:
self.bg2 = -768
self.count -= 1
if self.count == 0:
self.count = 25
name = choice(self.objList)
if name in ("largeWall", "smallWall"):
tex = 3
elif name == "spike_wall":
tex = 2
else:
tex = randint(0, len(res.images[name])-1)
x = randint(50, 1266)
if len(self.objects) > 0:
while fabs(self.objects[-1][0][0]-x) < 100:
x = randint(50, 1266)
self.objects.append([[x, -50], name, tex, choice([0, 90, 180, 270])])
if name == "turret":
attName = "cannon"
if randint(0, 5) == 1 and tex < 5:
attName = "cannon_double"
self.objects.append([[x, -50], attName, tex, randint(0, 360)])
elif name == "laz_turret":
self.objects.append([[x, -50], "lazer", tex, randint(0, 360)])
for obj in self.objects:
obj[0][1] += 2
if obj[0][1] > 868:
self.objects.remove(obj)
def draw(self, window):
if not res.settings["MOVING_BG"]:
window.blit(res.images["bg"][0], (0, 0))
else:
window.blit(res.images["bg"][1], (0, self.bg1))
window.blit(res.images["bg"][1], (0, self.bg2))
for obj in self.objects:
if obj[1] == "exit":
obj[2] += 0.2
if obj[2] >= 4:
obj[2] = 0
elif obj[1] == "a-ring":
obj[2] += 0.1
if obj[2] >= 3:
obj[2] = 0
elif obj[1] == "circularSaw":
obj[3] += 10
obj[3] = limitangle(obj[3])
elif obj[1] in ("teleporter", "cannon_double", "spiky_wheel"):
obj[3] -= 7
obj[3] = limitangle(obj[3])
img = pygame.transform.rotate(res.images[obj[1]][int(obj[2])], obj[3])
window.blit(img, img.get_rect(center=obj[0]))
def draw_cornerBar(rect, h, d):
image = pygame.Surface(rect.size, pygame.SRCALPHA)
barx = d/h*(rect.width/2)+1
bary = d/h*(rect.height/2)+1
tl_w = pygame.Rect(0, 0, barx, 5)
tl_h = pygame.Rect(0, 0, 5, bary)
tr_w = pygame.Rect(rect.width-barx, 0, barx, 5)
tr_h = pygame.Rect(rect.width-5, 0, 5, bary)
bl_w = pygame.Rect(0, rect.height-5, barx, 5)
bl_h = pygame.Rect(0, rect.height-bary, 5, bary)
br_w = pygame.Rect(rect.width-barx, rect.height-5, barx, 5)
br_h = pygame.Rect(rect.width-5, rect.height-bary, 5, bary)
rects = tl_w, tl_h, tr_w, tr_h, bl_w, bl_h, br_w, br_h
for r in rects:
pygame.draw.rect(image, (255, 255, 255), r)
return image
def draw_circleBar(rect, h, d, angle):
image = pygame.Surface(rect.size, pygame.SRCALPHA)
end_angle = radians(d/h*360)
angle = radians(angle)
pygame.draw.arc(image, (255, 255, 255), image.get_rect(), angle, end_angle+angle, 5)
return image
def draw_range_rect(rect, angle, range):
image = pygame.Surface(rect.size, SRCALPHA)
vect = get_vect(angle+range, rect.height)
endpos = rect.width/2+vect[0], rect.height/2+vect[1]
pygame.draw.line(image, (0, 0, 0), (rect.width/2, rect.height/2), endpos, 12)
pygame.draw.line(image, (150, 150, 150), (rect.width/2, rect.height/2), endpos, 6)
vect = get_vect(angle-range, rect.height)
endpos = rect.width/2+vect[0], rect.height/2+vect[1]
pygame.draw.line(image, (0, 0, 0), (rect.width/2, rect.height/2), endpos, 12)
pygame.draw.line(image, (150, 150, 150), (rect.width/2, rect.height/2), endpos, 6)
pygame.draw.rect(image, (0, 0, 0), (0, 0, rect.width, rect.height), 4)
return image
def draw_range_circle(rect, angle, range):
image = pygame.Surface(rect.size, SRCALPHA)
center = rect.height/2
vect = get_vect(angle+range, center-5)
endpos = center+vect[0], center+vect[1]
pygame.draw.line(image, (0, 0, 0), (center, center), endpos, 10)
pygame.draw.line(image, (150, 150, 150), (center, center), endpos, 4)
vect = get_vect(angle-range, center-5)
endpos = center+vect[0], center+vect[1]
pygame.draw.line(image, (0, 0, 0), (center, center), endpos, 10)
pygame.draw.line(image, (150, 150, 150), (center, center), endpos, 4)
return image
def draw_electricStrike(window, pos1, pos2, var=8):
origin = list(pos1)
oldPoint = origin
for vect in vectCutting(pos1[0]-pos2[0], pos1[1]-pos2[1], var):
origin[0] -= vect[0]
origin[1] -= vect[1]
newPoint = origin[0]+randint(0, var*2)-var, origin[1]+randint(0, var*2)-var
pygame.draw.line(window, (200, 220, 255), oldPoint, newPoint, 2)
oldPoint = newPoint
pygame.draw.line(window, (200, 220, 255), oldPoint, pos2, 2)
def draw_select_area(window, rect, time, shape, color=(255, 255, 255), tick=1):
infl = time-30
if infl <= 0:
infl += 30
if shape == 0:
pygame.draw.rect(window, color, rect.inflate(infl, infl), tick)
else:
pygame.draw.circle(window, color, rect.center, int((rect.width+infl)/2), tick)
def draw_dotted_line(window, pos1, pos2, time):
newPoint = list(pos1)
i = 0
for vect in vectCutting(pos1[0]-pos2[0], pos1[1]-pos2[1], 1):
newPoint[0] -= vect[0]
newPoint[1] -= vect[1]
if i%20 == time:
pygame.draw.line(window, (180, 210, 255), newPoint, (newPoint[0]+vect[0]*2, newPoint[1]+vect[1]*2), 2)
i += 1