-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgalgar.py
115 lines (91 loc) · 2.53 KB
/
galgar.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
import pgzrun
# Screen Setup
WIDTH = 1200
HEIGHT = 1000
TITLE = "GalaGar 2023"
# Render Sprite
ship = Actor ('galaga')
ship.x = WIDTH//2
ship.y = HEIGHT - 100
ship.dead = False
ship.countdown = 500
# List for Bullet
bullets = []
# List for Enemies
enemies = []
# Make array of enemies
for x in range(8):
for y in range (5):
enemies.append(Actor('bug'))
enemies [-1].x = 100 + 90 * x
enemies [-1].y = 150 + 80 * y
# Color pallete
RED = (255,0,0)
GREEN = (0,255,0)
BLUE = (0,0,255)
WHITE = (255,255,255)
BLACK = (0,0,0)
score = 0
direction = 1
music.play ("theme")
# Text
def draw_score ():
screen.draw.text (str(score), (50, 30), fontname="arcade", fontsize=20)
screen.draw.text ("Galagar 2023", (370, 20), fontname = "arcade", color="orange", align ="center", fontsize = 40)
def on_key_down(key):
if ship.dead == False:
if key == keys.SPACE:
sounds.lazer.play()
bullets.append (Actor('bullet'))
bullets[-1].x = ship.x
bullets[-1].y = ship.y - 55 # sets starting y of bullet
def update ():
global score
global direction
# keyboard maping
if ship.dead == False:
if keyboard.left:
ship.x -= 5
elif keyboard.right:
ship.x += 5
for bullet in bullets:
# remove un needed bullets
if bullet.y < -20:
bullets.remove (bullet)
else:
bullet.y -= 10
moveDown = False
if len (enemies) > 0 and (enemies [-1].x > WIDTH-80 or enemies[0].x <80):
moveDown = True
direction = direction*-1
for enemy in enemies:
enemy.x+= 5*direction
if moveDown == True:
enemy.y += 5 #80
# Test for bullet collision
for bullet in bullets:
if enemy.colliderect (bullet):
sounds.explosion.play ()
score += 150
bullets.remove (bullet)
enemies.remove (enemy)
if enemy.colliderect(ship):
# sounds.explosion.play()
ship.dead = True
# Player regeneration
if ship.dead:
ship.countdown -=1
if ship.countdown == 0:
ship.dead =False
ship.countdown = 500
def draw():
screen.clear()
screen.fill (BLACK)
for bullet in bullets:
bullet.draw()
for enemy in enemies:
enemy.draw()
if ship.dead == False:
ship.draw()
draw_score()
pgzrun.go ()