-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parallel_beta.py
287 lines (219 loc) · 9.67 KB
/
Parallel_beta.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
import pygame, random
from pygame.locals import *
from globals import *
from combos import *
from Obstacle import *
from Player import *
#from save import*
global SPEED, VIEW, FPS, STATE, OBS, LVLCOMPLETE
pygame.init()
'''INITIALIZE'''
# The screen
back = pygame.image.load("level1.png")
VIEW.blit(back, [0,270] )
# The soundtrack
soundtrack = pygame.mixer.music
soundtrack.load('Soundtrack2.mp3')
soundtrack.play(-1, 0)
# The traps.
#array = []
#for x in xrange(20): #shows how many traps
# array.append(random.randint(1,4))
array = [ [1,1],[2,2],[2,1],[2,3],[1,3],[2,2] ]
# Initializes the clock to create a stable frame rate and consistent new frame delay across machines..
clock = pygame.time.Clock()
global attempts
attempts = 0
def game(lvl, array):
'''
Creates a playable instance of a level.
@param lvl: Which level the player will start on.
@param array: The 2 dimensional array that acts as the game's "seed." array[0] = trapCombo #, array[1] = Which level the trap spawns on.
@return: Returns lvl+1 if the player beat the level, or simply lvl if the player lost and must replay the level.
'''
# Initialize variables.
global STATE # State of the entire game.
lvlState = True # Win/lose state of the current level.
global attempts
# Iterators.
i = 0 # The index of the trap.
t = 5 # The initial trap spawn delay
# Play the game with different conditions for each level.
if lvl == 1:
back = pygame.image.load("level1.png")
VIEW.blit(back, [0,0] )
player1 = Player(1, "RealBall.png")
while lvlState:
pygame.display.set_caption('Attempts: %d' %attempts)
# Standardizes FPS across platforms.
clock.tick_busy_loop(FPS)
if player1.isJumping:
player1.jump()
# Update the display
player1.updateSprite()
VIEW.fill([255,255,255])
VIEW.blit(back, [0,0])
VIEW.blit(player1.image, player1.rect.topleft)
for trap in iter(OBS):
trap.move()
# If a trap moves into a player, they lose the level.
if trap.rect.colliderect(player1.rect):
attempts += 1
lvlState = False
if trap.rect.right+10 < 0:
trap.delete() # Delete traps that move off of the left side.
if len(OBS) <= 0: # End the file when all traps have moved off the left side and advance to next level.
lvlState = False
lvl = lvl+1
pygame.display.update()
# Spawn traps when appropriate.
if (t <= 0) and (i+1 <= len(array)):
if (array[i][1] < 2):
t = combos(array[i])
t = t*40 + 400
i += 1
t -= SPEED
# Command list
for event in pygame.event.get():
# If the user quits, the game exits
if event.type == QUIT:
STATE = False
lvlState = False
# Input list
elif event.type == pygame.KEYDOWN:
if (event.key == pygame.K_SPACE) and (player1.isJumping == False):
#sound = pygame.mixer.music
#sound.load('JumpSound.mp3')
#sound.play(1,0)
player1.jumpCount += 1
player1.isJumping = True
player1.velocity = -2.0*SPEED*ARCHEIGHT[1]/ARCHEIGHT[0] #-2SPEED*MAX[y]/MAX[x]
player1.rect.top -= 1
return lvl #End of "if lvl == 1"
elif lvl == 2:
back = pygame.image.load("level2.png")
VIEW.blit(back, [0,0] )
player1 = Player(1, "RealBall.png")
player2 = Player(2, "RealBall.png")
while lvlState:
pygame.display.set_caption('Attempts: %d' %attempts)
# Standardizes FPS across platforms.
clock.tick_busy_loop(FPS)
if player1.isJumping:
player1.jump()
player2.jump()
# Update the display
player1.updateSprite()
player2.updateSprite()
VIEW.fill([255,255,255])
VIEW.blit(back, [0,0])
VIEW.blit(player1.image, player1.rect.topleft)
VIEW.blit(player2.image, player2.rect.topleft)
for trap in iter(OBS):
trap.move()
if trap.rect.colliderect(player1.rect) or trap.rect.colliderect(player2.rect):
attempts += 1
lvlState = False
if trap.rect.right+10 < 0: # Delete traps that move off of the left side.
trap.delete()
if len(OBS) <= 0: # End the file when all traps have moved off the left side.
lvlState = False
lvl = lvl+1
pygame.display.update()
# Spawn traps when appropriate.
if (t <= 0) and (i+1 <= len(array)):
if (array[i][1] < 3):
t = combos(array[i])
t = t*40 + 400
i += 1
t -= SPEED
# Command list
for event in pygame.event.get():
# If the user quits, the game exits
if event.type == QUIT:
STATE = False
lvlState = False
# Input list
elif event.type == pygame.KEYDOWN:
if (event.key == pygame.K_SPACE) and (player1.isJumping == False):
#sound = pygame.mixer.music
#sound.load('JumpSound.mp3')
#sound.play(1,0)
player1.jumpCount += 1
player2.jumpCount += 1
player1.isJumping = True
player2.isJumping = True
player1.velocity = -2.0*SPEED*ARCHEIGHT[1]/ARCHEIGHT[0] #-2SPEED*MAX[y]/MAX[x]
player2.velocity = -2.0*SPEED*ARCHEIGHT[1]/ARCHEIGHT[0]
player1.rect.top -= 1
player2.rect.top -= 1
return lvl
elif lvl == 3:
back = pygame.image.load("level3.png")
VIEW.blit(back, [0,0] )
player1 = Player(1, "RealBall.png")
player2 = Player(2, "RealBall.png")
player3 = Player(3, "RealBall.png")
while lvlState:
pygame.display.set_caption('Attempts: %d' %attempts)
# Standardizes FPS across platforms.
clock.tick_busy_loop(FPS)
if player1.isJumping:
player1.jump()
player2.jump()
player3.jump()
# Update the display
player1.updateSprite()
player2.updateSprite()
player3.updateSprite()
VIEW.fill([255,255,255])
VIEW.blit(back, [0,0])
VIEW.blit(player1.image, player1.rect.topleft)
VIEW.blit(player2.image, player2.rect.topleft)
VIEW.blit(player3.image, player3.rect.topleft)
for trap in iter(OBS):
trap.move()
if trap.rect.colliderect(player1.rect) or trap.rect.colliderect(player2.rect) or trap.rect.colliderect(player3.rect):
attempts += 1
lvlState = False
if trap.rect.right+10 < 0: # Delete traps that move off of the left side.
trap.delete()
if len(OBS) <= 0: # End the file when all traps have moved off the left side.
lvlState = False
lvl = lvl+1
pygame.display.update()
# Spawn traps when appropriate.
if (t <= 0) and (i+1 <= len(array)):
t = combos(array[i])
t = t*40 + 400
i += 1
t -= SPEED
# Command list
for event in pygame.event.get():
# If the user quits, the game exits
if event.type == QUIT:
STATE = False
lvlState = False
# Input list
elif event.type == pygame.KEYDOWN:
if (event.key == pygame.K_SPACE) and (player1.isJumping == False):
#sound = pygame.mixer.music
#sound.load('JumpSound.mp3')
#sound.play(1,0)
player1.jumpCount += 1
player1.isJumping = True
player1.velocity = -2.0*SPEED*ARCHEIGHT[1]/ARCHEIGHT[0] #-2SPEED*MAX[y]/MAX[x]
player2.velocity = -2.0*SPEED*ARCHEIGHT[1]/ARCHEIGHT[0]
player3.velocity = -2.0*SPEED*ARCHEIGHT[1]/ARCHEIGHT[0]
player1.rect.top -= 1
player2.rect.top -= 1
player3.rect.top -= 1
return lvl
'''BODY'''
LEVEL = game(1, array)
OBS.empty()
while STATE and LEVEL < 4:
LEVEL = game(LEVEL, array)
OBS.empty()
if LEVEL > 3:
print("You win!")