-
Notifications
You must be signed in to change notification settings - Fork 0
/
aliengame.py
175 lines (116 loc) · 4.06 KB
/
aliengame.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
# Matthew Keitelman (mak2vr)
# Fernando Mata Cordero (fm5ew)
import pygame
import gamebox
import random
camera = gamebox.Camera(1000,800,True)
alien = gamebox.from_image(300, 15, "http://people.virginia.edu/~mak2vr/files/alien/alien.png")
alien.scale_by(1.3)
alien.yspeed = 0
platforms = [
gamebox.from_color(500,400,"black",1000,30),
gamebox.from_color(1500,600,"black",500,30),
]
radius = 250
platform_x = 1500
platform_length = 500
platform_end = 1750
prev_length = 0
prev_end = 0
prev_x = 0
prev_radius = 0
platform_end
time_on = 300
y=0
blue_hole_sheet = gamebox.load_sprite_sheet("http://people.virginia.edu/~mak2vr/files/alien/bluehole.png",1,5)
x = 1500
blueholes = []
score = 0
speed = 10
def tick(keys):
for bluehole in blueholes:
bluehole.scale_by(1.018)
global x, score, y, platform_x, time_on, speed, platform_length, platform_end, prev_length, prev_end, prev_x, radius, prev_radius
if y > 3:
y =0
y+=1
if camera.x % 1000 == 0:
speed += 4
score = int(camera.x)
scoreboard = gamebox.from_text(camera.x+300,50,(str(score)),"Verdana",26,"black")
camera.x += speed
alien.x += speed
if alien.x >= (platform_x - platform_length/2) and alien.x <= (platform_x - platform_length/2):
time_on += speed
elif alien.x >= platform_x - platform_length/2:
time_on = 0
if len(platforms) < 10:
prev_length = int(platform_length)
prev_x = int(platform_x)
prev_end = int(platform_end)
prev_radius = radius
platform_length = int(random.randint(300,600))
radius = int(platform_length/2)
platform_x = prev_end + radius + random.randint(25,200)
platform_end = platform_x + radius
height = random.randint(300,700)
platforms.append(gamebox.from_color(platform_x,height,"black",2*radius,30))
if len(blueholes) < 2:
bluehole_x = random.randint(camera.x,camera.x+500)
bluehole_y = random.randint(0,800)
blueholes.append(gamebox.from_image(bluehole_x,bluehole_y,blue_hole_sheet[y]))
# GRAVITY
alien.yspeed += 1.5
alien.y = alien.y + alien.yspeed
if pygame.K_s in keys:
alien.image = "http://people.virginia.edu/~mak2vr/files/alien/alien_top.png"
elif pygame.K_d in keys:
alien.image = "http://people.virginia.edu/~mak2vr/files/alien/alien_middle.png"
elif pygame.K_f in keys:
alien.image = "http://people.virginia.edu/~mak2vr/files/alien/alien_bottom.png"
else:
alien.image = "http://people.virginia.edu/~mak2vr/files/alien/alien.png"
for platform in platforms:
if alien.bottom_touches(platform):
alien.move_to_stop_overlapping(platform)
if platform.x < (camera.x-1000):
platforms.remove(platform)
if alien.touches(platform):
if pygame.K_SPACE in keys:
alien.yspeed -= 30
if pygame.K_RIGHT in keys:
alien.x += 5
if pygame.K_LEFT in keys:
alien.x -= 5
camera.clear("skyblue")
camera.draw(alien)
camera.draw(scoreboard)
for platform in platforms:
camera.draw(platform)
for bluehole in blueholes:
camera.draw(bluehole)
camera.display()
game_over = gamebox.from_text(camera.x,400,"Game Over","Arial",40,"black",True)
def end():
gamebox.pause()
camera.clear("skyblue")
camera.draw(game_over)
camera.display()
for bluehole in blueholes:
bluehole.image = blue_hole_sheet[y]
if bluehole.x < (camera.x-500):
blueholes.remove(bluehole)
if alien.touches(bluehole):
end()
if alien.y >= 800:
end()
ticks_per_second = 30
def start(keys):
camera.clear("skyblue")
camera.draw(gamebox.from_text(500,500,"Our Game", "Futura",20,"black"))
camera.draw(gamebox.from_text(500,600,"Press SPACE to start", "Futura",20,'black'))
camera.display()
if pygame.K_SPACE in keys:
gamebox.timer_loop(ticks_per_second, tick)
gamebox.timer_loop(ticks_per_second,start)
# keep this line the last one in your program