-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
488 lines (458 loc) · 24.7 KB
/
main.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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# July 8 - August 27, 2024
# 1978, Space Invaders released [???]
import decimal
from decimal import *
import pygame
from pygame import *
from pygame.locals import *
import pygame.freetype
import time
import math
import sys
import os
import random
import tkinter as tk
from svg import Parser, Rasterizer
import asyncio
import platform
if sys.platform == "emscripten":
platform.window.canvas.style.imageRendering = "pixelated"
if (web := sys.platform in ('emscripten','wasi')):
from platform import window
# ggenije
# This game is powered by PyGame. The Windows build was built with PyInstaller. The web build was built with PygBag (Python web assembly).
# https://youtu.be/FfWpgLFMI7w
# pro.sfxr.me
# https://github.com/Rabbid76/PyGameExamplesAndAnswers/blob/master/documentation/pygame/pygame_collision_and_intesection.md
# https://icons8.com/icons/set/space-invaders--animated
# https://www.freepik.com/free-vector/futuristic-spaceship-collection-with-flat-design_2898820.htm#query=space%20fighter&position=1&from_view=keyword&track=ais_user&uuid=5e43d284-9e98-4b88-a912-680fec6643a0
# https://www.freepik.com/free-vector/funny-game-monsters-collection_1529196.htm#fromView=search&page=2&position=7&uuid=20b22d67-42fc-4208-b742-6e63656f1697
# https://www.youtube.com/watch?v=F69-t33e8tk
# https://www.freepik.com/free-vector/hand-painted-watercolor-galaxy-background_14237502.htm#fromView=search&page=1&position=0&uuid=801401a5-0317-4fcc-a9aa-ff0df8e0039f
# https://nerdparadise.com/programming/pygame/part3
# https://www.geeksforgeeks.org/how-to-add-music-playlist-in-pygame/
# https://stackoverflow.com/questions/120584/svg-rendering-in-a-pygame-application-prior-to-pygame-2-0-pygame-did-not-suppo
# https://stackoverflow.com/questions/20088670/pygame-smooth-fonts
# Initialize pygame
#pygame.mixer.pre_init(11025, 8, 2, 1024)
pygame.mixer.pre_init(44100, 16, 2, 4096)
pygame.init()
pygame.mixer.init()
screen_width = 1280
screen_height = 720
flags = DOUBLEBUF | pygame.RESIZABLE
screen = pygame.display.set_mode((screen_width, screen_height), flags, 16)
clock = pygame.time.Clock()
font = pygame.freetype.Font("./Fonts/Dosis/static/Dosis-Bold.ttf", 36)
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
camShake = [0, 0]
camShake2 = [0, 0]
def distanceto(x1, y1, x2, y2):
return math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
def MUSIC_SETUP():
global playlist, Music_end
playlist = list()
if sys.platform == "emscripten":
playlist.append ( "./audio/Kevin MacLeod - Space Fighter Loop.ogg" )
playlist.append ( "./audio/Kevin MacLeod - Galactic Rap.ogg" )
playlist.append ( "./audio/Kevin MacLeod - Brain Dance.ogg" )
playlist.append ( "./audio/Kevin MacLeod - Cloud Dancer.ogg" )
playlist.append ( "./audio/Kevin MacLeod - Mesmerizing Galaxy Loop.ogg" )
else:
playlist.append ( "./audio/Kevin MacLeod - Space Fighter Loop.mp3" )
playlist.append ( "./audio/Kevin MacLeod - Galactic Rap.mp3" )
playlist.append ( "./audio/Kevin MacLeod - Brain Dance.mp3" )
playlist.append ( "./audio/Kevin MacLeod - Cloud Dancer.mp3" )
playlist.append ( "./audio/Kevin MacLeod - Mesmerizing Galaxy Loop.mp3" )
Music_end = pygame.USEREVENT
pygame.mixer.music.load ( playlist[0] )
playlist.pop(0)
pygame.mixer.music.play()
pygame.mixer.music.queue ( playlist[0] )
playlist.pop(0)
pygame.mixer.music.set_endevent ( Music_end )
# SVG! YAY!
def load_svg(filename, scale=None, size=None, clip_from=None, fit_to=None, foramt='RGBA'):
svg = Parser.parse_file(filename)
scale = min((fit_to[0] / svg.width, fit_to[1] / svg.height)
if fit_to else ([scale if scale else 1] * 2))
width, height = size if size else (svg.width, svg.height)
surf_size = round(width * scale), round(height * scale)
buffer = Rasterizer().rasterize(svg, *surf_size, scale, *(clip_from if clip_from else 0, 0))
return pygame.image.frombuffer(buffer, surf_size, foramt)
# Player
# playerImg = pygame.image.load('./img/player.png').convert_alpha()
playerImg = load_svg('./img/player.svg')
playerPos = [(1280 - playerImg.get_width()/2.5)/2, (720 - playerImg.get_height()/2.5)/2 + 240]
playerPosChange = [0, 0]
playerRect = pygame.Rect(playerImg.get_rect(center = playerPos))
WindowScale = 1
WindowXscale = 1
WindowYscale = 1
def player():
# playerImg = pygame.image.load('./img/player.png').convert_alpha()
playerImg = load_svg('./img/player.svg')
playerImg = pygame.transform.scale(playerImg, (playerImg.get_width()/2.5 * WindowScale, playerImg.get_height()/2.5 * WindowScale))
playerRect = pygame.Rect(playerImg.get_rect(center = playerPos))
screen.blit(playerImg, ((playerPos[0]+camShake[0])*WindowXscale, (playerPos[1]+camShake[1])*WindowYscale))
# Enemy
enemyImageNumber = []
enemyImg = []
enemyPos = []
enemyPosChange = []
enemyRect = []
for i in range(24):
enemyImageNumber.append(random.randint(1,9))
# enemyImg = pygame.image.load(f"./img/alien{enemyImageNumber}.png").convert_alpha()
enemyImg.append(load_svg(f"./img/alien{enemyImageNumber[i]}.svg"))
enemyPos.append([random.randint(100, screen_width - 20 - int(enemyImg[i].get_width()//1.7)), random.randint(50, 200)])
enemyPosChange.append([(random.randint(0, 1) * 280) - 140, 0])
enemyRect.append(pygame.Rect(enemyPos[i][0], enemyPos[i][1], enemyImg[i].get_width(), enemyImg[i].get_height()))
# PlayerLaser
# Ready - You can't see the laser on the screen.
# Fire - The laser is currently moving.
PlayerLaserNum = 0
# playerLaserImg = pygame.image.load(f"./img/PlayerLaser.png").convert_alpha()
playerLaserImg = load_svg(f"./img/PlayerLaser.svg")
playerLaserImg = pygame.transform.scale(playerLaserImg, (playerLaserImg.get_width()*5, playerLaserImg.get_height()*3))
playerLaserPos = []
playerLaserState = []
playerLaserPosChange = [0, -1200]
playerLaserRect = []
for i in range(24):
playerLaserPos.append([0, 0])
playerLaserState.append("ready")
playerLaserRect.append(pygame.Rect(playerLaserPos[i][0] + playerLaserImg.get_width()*2, playerLaserPos[i][1] - playerLaserImg.get_height()*0.36, playerLaserImg.get_width(), playerLaserImg.get_height()))
def constrain(val, min_val, max_val):
if val < min_val: return min_val
if val > max_val: return max_val
return val
particles = []
MUSIC_SETUP()
def respawnEnemy(i):
global enemyImg
global enemyPos
global enemyPosChange
global enemyImageNumber
enemyImageNumber[i] = random.randint(1,9)
enemyImg[i] = load_svg(f"./img/alien{enemyImageNumber[i]}.svg")
enemyPos[i] = [random.randint(100, screen_width - 20 - int(enemyImg[i].get_width()//1.7)), random.randint(50, 200)]
enemyPosChange[i] = [(random.randint(0, 1) * 280) - 140, 0]
for i in range(24):
enemyImageNumber[i] = random.randint(1,9)
enemyImg[i] = load_svg(f"./img/alien{enemyImageNumber[i]}.svg")
enemyPos[i] = [random.randint(100, screen_width - 20 - int(enemyImg[i].get_width()//1.7)), random.randint(50, 200)]
enemyPosChange[i] = [(random.randint(0, 1) * 280) - 140, 0]
def enemy(i):
#enemyImg = pygame.image.load(f"./img/alien{enemyImageNumber}.png").convert_alpha()
enemyImg[i] = load_svg(f"./img/alien{enemyImageNumber[i]}.svg")
enemyImg[i] = pygame.transform.scale(enemyImg[i], (enemyImg[i].get_width()*WindowScale/2, enemyImg[i].get_height()*WindowScale/2))
enemyRect[i] = pygame.Rect(enemyPos[i][0], enemyPos[i][1], enemyImg[i].get_width(), enemyImg[i].get_height())
screen.blit(enemyImg[i], ((enemyPos[i][0]+camShake[0])*WindowXscale, (enemyPos[i][1]+camShake[1])*WindowYscale))
PlayerLaserNum = 0
def playerLaser(num):
#playerLaserImg = pygame.image.load(f"./img/PlayerLaser.png").convert_alpha()
playerLaserImg = load_svg(f"./img/PlayerLaser.svg")
playerLaserImg = pygame.transform.scale(playerLaserImg, (playerLaserImg.get_width()*WindowScale * 5, playerLaserImg.get_height()*WindowScale * 3))
playerLaserRect[num] = pygame.Rect(playerLaserPos[i][0] + playerLaserImg.get_width()*2, playerLaserPos[i][1] - playerLaserImg.get_height()*0.36, playerLaserImg.get_width(), playerLaserImg.get_height())
if playerLaserState[num] == "fire":
screen.blit(playerLaserImg, ((playerLaserPos[num][0]+camShake[0])*WindowXscale + playerLaserImg.get_width() + 26.666667*WindowScale, (playerLaserPos[num][1]+camShake[1])*WindowYscale))
''' def draw_text(text, font, color, x, y, align):
text_surface = font.render(text, True, color)
text_rect = text_surface.get_rect()
if align == "left":
screen.blit(text_surface, (x, y))
elif align == "center":
text_rect.center = (x, y)
screen.blit(text_surface, text_rect) '''
def draw_text(text, font, color, x, y, align):
text_rect = font.get_rect(text)
text_rect.center = screen.get_rect().center
if align == 'centerh':
font.render_to(screen, (text_rect.center[0] - text_rect.width/2 + x, y), text, color)
elif align == 'centerv':
font.render_to(screen, (x, text_rect.center[1] - text_rect.height/2 + y), text, color)
elif align == 'center':
font.render_to(screen, (text_rect.center[0] - text_rect.width/2 + x, text_rect.center[1] - text_rect.height/2 + y), text, color)
elif align == 'left':
font.render_to(screen, (x, y), text, color)
elif align == 'right':
font.render_to(screen, (text_rect.center[0]*2 - text_rect.width + x, y), text, color)
# Title and Icon and background
pygame.display.set_caption("1978")
icon = pygame.image.load('./img/SPACE FIGHTERS SVG icons8.png')
pygame.display.set_icon(icon)
background = pygame.image.load('./img/5438849.jpg').convert_alpha()
background = pygame.transform.scale(background, (screen_width, screen_height))
backgroundRect = pygame.Rect(background.get_rect())
background2 = load_svg('./img/vignette.svg')
background2 = pygame.transform.scale(background2, (screen_width, screen_height))
backgroundRect2 = pygame.Rect(background2.get_rect())
# Game Loop
global running
running = 1
score = Decimal(0)
scoreDisplay = Decimal(0)
frames = 0
start_time = time.time()
delta_time = 0.000001
game_time = -0.000001
timeScale = 1
GameFPS = 1/delta_time #60
GameOver = 0
camShake = [0, 0]
camShake2 = [0, 0]
while running:
mos_x, mos_y = pygame.mouse.get_pos()
frames += 1
(WindowWidth, WindowHeight) = pygame.display.get_surface().get_size()
WindowXscale = WindowWidth / screen_width
WindowYscale = WindowHeight / screen_height
if WindowXscale < 0.01 and WindowYscale < 0.01:
WindowScale = min(WindowXscale, WindowYscale)
elif WindowXscale > 0.01 and WindowYscale > 0.01:
WindowScale = min(WindowXscale, WindowYscale)
else:
WindowScale = 0.01
delta_time = (time.time() - start_time) - game_time
start_time += (1-timeScale) * delta_time
delta_time *= timeScale
game_time = time.time() - start_time
if Decimal(delta_time) > 0:
GameFPS = 1/delta_time
else:
GameFPS = math.inf
font = pygame.freetype.Font("./Fonts/Dosis/static/Dosis-Bold.ttf", round(36*WindowScale))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = 0
if event.type == Music_end: # A track has ended
if len ( playlist ) > 0: # If there are more tracks in the queue...
pygame.mixer.music.queue ( playlist.pop() ) # Queue the next one in the list
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and not PlayerLaserNum >= 24:
for i in range(24):
if playerLaserState[i] == "ready":
playerLaserPos[i] = [playerPos[0] + random.randrange(-7, 7)*WindowScale, playerPos[1]+50]
playerLaserState[i] = "fire"
PlayerLaserNum += 1
playerLaserPos[i][1] = playerPos[1]+50
if sys.platform == "emscripten":
pygame.mixer.Sound("./audio/PlayerLaserShoot.ogg").play()
else:
pygame.mixer.Sound("./audio/PlayerLaserShoot.wav").play()
break
if not pygame.mixer.music.get_busy():
MUSIC_SETUP()
# If keystroke is pressed check whether its right or left
keys = pygame.key.get_pressed() # Checking pressed keys
#if keyboard.is_pressed('up') or keys[pygame.K_UP]:
if keys[pygame.K_UP]:
playerPosChange[1] -= 12 * delta_time
#if keyboard.is_pressed('down') or keys[pygame.K_DOWN]:
if keys[pygame.K_DOWN]:
playerPosChange[1] += 12 * delta_time
#if keyboard.is_pressed('left') or keys[pygame.K_LEFT]:
if keys[pygame.K_LEFT]:
playerPosChange[0] -= 12 * delta_time
#if keyboard.is_pressed('right') or keys[pygame.K_RIGHT]:
if keys[pygame.K_RIGHT]:
playerPosChange[0] += 12 * delta_time
# RGB - Red, Green, Blue
screen.fill((0, 0, 32))
# Background Image
if (WindowWidth, WindowHeight) != (background.get_width(), background.get_height()):
background = pygame.transform.scale(pygame.image.load('./img/5438849.jpg'), (WindowWidth, WindowHeight))
background2 = pygame.transform.scale(load_svg('./img/vignette.svg'), (WindowWidth, WindowHeight))
screen.blit(background, (camShake[0]*WindowScale, camShake[1]*WindowScale))
particles.append([[random.randint(screen_width*-1, screen_width), -100], [random.randint(0, 0) / 10 - 1, 300], random.randint(4, 6), -2, WHITE])
for particle in particles:
particle[0][0] += particle[1][0] * delta_time
particle[0][1] += particle[1][1] * delta_time
particle[2] += particle[3] * delta_time
pygame.draw.circle(screen, particle[4], (round((particle[0][0]+round(camShake[0]))*WindowXscale), round((particle[0][1]+round(camShake[1]))*WindowYscale)), round(particle[2]*WindowScale))
if particle[2] <= 0:
particles.remove(particle)
playerPos[0] += playerPosChange[0] * 100 * delta_time
playerPos[1] += playerPosChange[1] * 100 * delta_time
playerPosChange[0] *= 0.04**delta_time
playerPosChange[1] *= 0.04**delta_time
#playerPos[0] = constrain(playerPos[0], 0, screen_width - 135*WindowScale)
#playerPos[1] = constrain(playerPos[1], 0, screen_height - 165*WindowScale)
if WindowYscale >= WindowXscale:
playerPos[1] = constrain(playerPos[1], 0, screen_height - playerImg.get_height()*WindowScale/2.5)
else:
playerPos[1] = constrain(playerPos[1], 0, screen_height - playerImg.get_height()/2.5)
# Player Laser Movement
enpoY = 0
for i in range(24):
enemyPos[i][0] += enemyPosChange[i][0] * delta_time
enemyPos[i][1] += enemyPosChange[i][1] * delta_time
if WindowXscale >= WindowYscale:
playerPos[0] = constrain(playerPos[0], 0, screen_width - playerImg.get_width()*WindowScale/2.5)
if enemyPos[i][0] >= screen_width - enemyImg[i].get_width()*WindowScale or enemyPos[i][0] <= 0:
enemyPos[i][0] -= enemyPosChange[i][0] * .1
enemyPosChange[i][0] *= -1.2
enemyPos[i][1] += 40
else:
playerPos[0] = constrain(playerPos[0], 0, screen_width - playerImg.get_width()/2.5)
if enemyPos[i][0] >= screen_width - enemyImg[i].get_width() or enemyPos[i][0] <= 0:
enemyPos[i][0] -= enemyPosChange[i][0] * .1
enemyPosChange[i][0] *= -1.2
enemyPos[i][1] += 40
enemyRect[i] = pygame.Rect(enemyPos[i][0], enemyPos[i][1], enemyImg[i].get_width(), enemyImg[i].get_height())
playerLaserRect[i] = pygame.Rect(playerLaserPos[i][0] + playerLaserImg.get_width()*2, playerLaserPos[i][1] - playerLaserImg.get_height()*0.36, playerLaserImg.get_width(), playerLaserImg.get_height())
if playerLaserPos[i][1] <= -60:
PlayerLaserNum -= 1
playerLaserPos[i][1] = 2000
playerLaserState[i] = "ready"
if enemyPos[i][1] >= enpoY:
enpoY = enemyPos[i][1]
if enpoY >= 400:
timeScale = 1 - ((enpoY/600 - .66667)**.5)
else:
timeScale = 1
background2.set_alpha(enpoY - 430)
if enpoY >= 900:
running = False
GameOver = 1
for j in range(24):
if playerLaserRect[i].colliderect(enemyRect[j]):
score += Decimal(100)
camShake2[0] += 12
camShake2[1] += 12
if sys.platform == "emscripten":
pygame.mixer.Sound("./audio/EnemyExplosion.ogg").play()
else:
pygame.mixer.Sound("./audio/EnemyExplosion.wav").play()
for k in range(10):
particles.append([[playerLaserPos[i][0] + playerLaserImg.get_width()*2, playerLaserPos[i][1]], [math.sin(random.randrange(-180, 180))*240, math.cos(random.randrange(-180, 180))*240], random.randint(6, 9), -5, RED])
enemyImageNumber[j] = random.randint(1,9)
enemyImg[j] = load_svg(f"./img/alien{enemyImageNumber[j]}.svg")
enemyPos[j] = [random.randint(100, screen_width - 20 - int(enemyImg[j].get_width()//1.7)), random.randint(50, 200)]
enemyPosChange[j] = [(random.randint(0, 1) * 280) - 140, 0]
PlayerLaserNum -= 1
playerLaserPos[i][1] = 2000
playerLaserState[i] = "ready"
playerLaserPos[i][1] += playerLaserPosChange[1] * delta_time * (playerLaserState[i] == "fire")
# pygame.draw.rect(screen, RED, playerLaserRect[i])
# pygame.draw.rect(screen, RED, enemyRect[i])
playerLaser(i)
enemy(i)
player()
screen.blit(background2, (camShake[0]*WindowScale, camShake[1]*WindowScale))
PlayerLaserNum = constrain(PlayerLaserNum, 0, 24)
scoreDisplay += (Decimal(score)-Decimal(scoreDisplay)) * Decimal(delta_time) * Decimal(5)
scoreDisplay2 = round(Decimal(scoreDisplay))
camShake = (random.randrange(-1, 1)*camShake2[0], random.randrange(-1, 1)*camShake2[1])
camShake2[0] *= 0.01**delta_time
camShake2[1] *= 0.01**delta_time
draw_text(f"1978", pygame.freetype.Font("./Fonts/Dosis/static/Dosis-Bold.ttf", round(108*WindowScale)), (100, 100, 100, 180), camShake[0]*WindowScale, camShake[1]*WindowScale, "center")
draw_text(f"Score: {Decimal(scoreDisplay2)}", font, (abs(math.cos(game_time * 1.5) * 255), abs(math.sin(game_time * 2) * 255), abs(math.cos(game_time * 2.5) * 255)), camShake[0]*WindowScale, (30+camShake[1])*WindowScale, "centerh")
draw_text(f"Score: {Decimal(scoreDisplay2)}", font, (128, 64, 192), (1+camShake[0])*WindowScale, (31+camShake[1])*WindowScale, "centerh")
pygame.display.flip()
pygame.display.update()
# clock.tick(24)
while GameOver == True:
mos_x, mos_y = pygame.mouse.get_pos()
frames += 1
(WindowWidth, WindowHeight) = pygame.display.get_surface().get_size()
WindowXscale = WindowWidth / screen_width
WindowYscale = WindowHeight / screen_height
if WindowXscale < 0.01 and WindowYscale < 0.01:
WindowScale = min(WindowXscale, WindowYscale)
elif WindowXscale > 0.01 and WindowYscale > 0.01:
WindowScale = min(WindowXscale, WindowYscale)
else:
WindowScale = 0.01
delta_time = (time.time() - start_time) - game_time
start_time += (1-timeScale) * delta_time
delta_time *= timeScale
game_time = time.time() - start_time
if delta_time > 0:
GameFPS = 1/delta_time
else:
GameFPS = math.inf
font = pygame.freetype.Font("./Fonts/Dosis/static/Dosis-Bold.ttf", round(100*WindowScale))
for event in pygame.event.get():
if event.type == pygame.QUIT:
GameOver = 0
pygame.mixer.music.stop()
camShake = (random.randrange(-1, 1)*camShake2[0], random.randrange(-1, 1)*camShake2[1])
camShake2[0] *= 0.01**delta_time
camShake2[1] *= 0.01**delta_time
if (WindowWidth, WindowHeight) != (background.get_width(), background.get_height()):
background = pygame.transform.scale(pygame.image.load('./img/5438849.jpg'), (WindowWidth, WindowHeight))
background2 = pygame.transform.scale(load_svg('./img/vignette.svg'), (WindowWidth, WindowHeight))
screen.blit(background, camShake)
screen.blit(background2, camShake)
timeScale = 1
draw_text(f"Score: {Decimal(scoreDisplay2)}", font, (abs(math.cos(game_time * 1.5) * 255), abs(math.sin(game_time * 2) * 255), abs(math.cos(game_time * 2.5) * 255)), (0+camShake[0])*WindowScale, (30+camShake[1])*WindowScale, "centerh")
draw_text(f"Score: {Decimal(scoreDisplay2)}", font, (128, 64, 192), (1+camShake[0])*WindowScale, (31+camShake[1])*WindowScale, "centerh")
draw_text("GAME OVER", font, (128, 64, 192), (-1+camShake[0])*WindowScale, (0+camShake[1])*WindowScale, "center")
draw_text("GAME OVER", font, (128, 64, 192), (1+camShake[0])*WindowScale, (0+camShake[1])*WindowScale, "center")
draw_text("GAME OVER", font, (128, 64, 192), (0+camShake[0])*WindowScale, (1+camShake[1])*WindowScale, "center")
draw_text("GAME OVER", font, (128, 64, 192), (-1+camShake[0])*WindowScale, (1+camShake[1])*WindowScale, "center")
draw_text("GAME OVER", font, (128, 64, 192), (1+camShake[0])*WindowScale, (1+camShake[1])*WindowScale, "center")
draw_text("GAME OVER", font, (128, 64, 192), (0+camShake[0])*WindowScale, (-1+camShake[1])*WindowScale, "center")
draw_text("GAME OVER", font, (128, 64, 192), (-1+camShake[0])*WindowScale, (-1+camShake[1])*WindowScale, "center")
draw_text("GAME OVER", font, (128, 64, 192), (1+camShake[0])*WindowScale, (-1+camShake[1])*WindowScale, "center")
draw_text("GAME OVER", font, (abs(math.cos(game_time * 1.5) * 255), abs(math.sin(game_time * 2) * 255), abs(math.cos(game_time * 2.5) * 255)), (0+camShake[0])*WindowScale, (0+camShake[1])*WindowScale, "center")
if keys[pygame.K_r]:
GameOver = 0
playerImg = load_svg('./img/player.svg')
playerPos = [(1280 - playerImg.get_width()/2.5)/2, (720 - playerImg.get_height()/2.5)/2 + 240]
playerPosChange = [0, 0]
playerRect = pygame.Rect(playerImg.get_rect(center = playerPos))
enemyImageNumber = []
enemyImg = []
enemyPos = []
enemyPosChange = []
enemyRect = []
for i in range(24):
enemyImageNumber.append(random.randint(1,9))
# enemyImg = pygame.image.load(f"./img/alien{enemyImageNumber}.png").convert_alpha()
enemyImg.append(load_svg(f"./img/alien{enemyImageNumber[i]}.svg"))
enemyPos.append([random.randint(100, screen_width - 20 - int(enemyImg[i].get_width()//1.7)), random.randint(50, 200)])
enemyPosChange.append([(random.randint(0, 1) * 280) - 140, 0])
enemyRect.append(pygame.Rect(enemyPos[i][0], enemyPos[i][1], enemyImg[i].get_width(), enemyImg[i].get_height()))
PlayerLaserNum = 0
# playerLaserImg = pygame.image.load(f"./img/PlayerLaser.png").convert_alpha()
playerLaserImg = load_svg(f"./img/PlayerLaser.svg")
playerLaserImg = pygame.transform.scale(playerLaserImg, (playerLaserImg.get_width()*5, playerLaserImg.get_height()*3))
playerLaserPos = []
playerLaserState = []
playerLaserPosChange = [0, -1200]
playerLaserRect = []
for i in range(24):
playerLaserPos.append([0, 0])
playerLaserState.append("ready")
playerLaserRect.append(pygame.Rect(playerLaserPos[i][0] + playerLaserImg.get_width()*2, playerLaserPos[i][1] - playerLaserImg.get_height()*0.36, playerLaserImg.get_width(), playerLaserImg.get_height()))
enemyImageNumber[i] = random.randint(1,9)
enemyImg[i] = load_svg(f"./img/alien{enemyImageNumber[i]}.svg")
enemyPos[i] = [random.randint(100, screen_width - 20 - int(enemyImg[i].get_width()//1.7)), random.randint(50, 200)]
enemyPosChange[i] = [(random.randint(0, 1) * 280) - 140, 0]
particles = []
MUSIC_SETUP()
enemyImageNumber[i] = random.randint(1,9)
enemyImg[i] = load_svg(f"./img/alien{enemyImageNumber[i]}.svg")
enemyPos[i] = [random.randint(100, screen_width - 20 - int(enemyImg[i].get_width()//1.7)), random.randint(50, 200)]
enemyPosChange[i] = [(random.randint(0, 1) * 280) - 140, 0]
running = 1
score = Decimal(0)
scoreDisplay = Decimal(0)
frames = 0
start_time = time.time()
delta_time = 0.000001
game_time = -0.000001
timeScale = 1
GameFPS = 1/delta_time #60
GameOver = 0
camShake = [0, 0]
camShake2 = [0, 0]
pygame.display.flip()
pygame.display.update()