-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parallel2.py
287 lines (220 loc) · 8.1 KB
/
Parallel2.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
'''
Created on March 14, 2015
@author: Derek, Joey, Kevin, Niket
@version: v0.1.1
Removed faulty player code.
Added file importing and exporting. (Check details in save.py)
Spikes should work entirely properly.
Jumping follows a predictable arc. Game running at a consistent speed on all machines is uncertain.
@todo:
Kevin: Integrate your new menus, add a pause function.
Niket: Add the ability to detect and land on top of platforms in the Player.jump() method.
Joey: Update spike resources, design more trap combos, create file tracking system.
Derek: Finish level generator, create new background resources, animate backgrounds.
@attention:
WHO IS ADDING THE ABILITY TO DETECT WHEN TO ADD ANOTHER LEVEL?
Yes.
'''
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, STATE, OBS, FILECOMPLETE
pygame.init()
'''SETTINGS'''
VIEW.fill([255,255,255])
#Initializing the screen
back = pygame.image.load("background.png")
VIEW.blit(back, [0,270] )
'''soundtrack = pygame.mixer.music
soundtrack.load('Soundtrack2.wav')
soundtrack.play(-1, 0)'''
pygame.display.update()
array = []
for x in xrange(20): #shows how many traps
array.append(random.randint(1,4))
player = Player(2, 'GreenBall.png')
player2 = Player(2, 'GreenBall2.png')
player3 = Player(2, 'GreenBall3.png')
player4 = Player(2, 'GreenBall4.png')
player5 = Player(2, 'GreenBall5.png')
i = 0 # The index of the trap.
t = 0 # The time delay
# loop that controls when game will stop, along with the keyboard control
while STATE == True:
# Controls the framerate on Windows
pygame.time.delay(FPS/1000)
# Update the display
VIEW.fill([255,255,255])
VIEW.blit(back, [0,270])
VIEW.blit(player.image, player.rect.topleft)
"""VIEW.blit(player2.image, player2.rect.topleft)
VIEW.blit(player3.image, player3.rect.topleft)
VIEW.blit(player4.image, player4.rect.topleft)
VIEW.blit(player5.image, player5.rect.topleft)"""
# Cycle through all active sprites
if player.isJumping:
player.jump()
"""#if player2.isJumping:
player2.jump()
#if player3.isJumping:
player3.jump()
#if player4.isJumping:
player4.jump()
#if player5.isJumping:
player5.jump()"""
for trap in iter(OBS):
trap.move()
if trap.rect.colliderect(player.rect):
STATE = 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.
FILECOMPLETE = True
STATE = False
pygame.display.update()
"""pygame.transform.rotate(player.image,300)
pygame.display.update()
pygame.transform.rotate(player.image,80)
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
# Controls the framerate on Windows
pygame.time.delay(FPS/1000)
# Update the display
VIEW.fill([255,255,255])
VIEW.blit(back, [0,270])
VIEW.fill([255,255,255])
VIEW.blit(back, [0,270])
VIEW.blit(player2.image, player2.rect.topleft)
if player2.isJumping:
player2.jump()
for trap in iter(OBS):
trap.move()
if trap.rect.colliderect(player2.rect):
STATE = 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.
FILECOMPLETE = True
STATE = False
pygame.display.update()
if (t <= 0) and (i+1 <= len(array)):
t = combos(array[i])
t = t*40 + 400
i += 1
t -= SPEED
# Controls the framerate on Windows
pygame.time.delay(FPS/1000)
# Update the display
VIEW.fill([255,255,255])
VIEW.blit(back, [0,270])
VIEW.fill([255,255,255])
VIEW.blit(back, [0,270])
VIEW.blit(player3.image, player3.rect.topleft)
if player3.isJumping:
player3.jump()
for trap in iter(OBS):
trap.move()
if trap.rect.colliderect(player3.rect):
STATE = 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.
FILECOMPLETE = True
STATE = False
pygame.display.update()
if (t <= 0) and (i+1 <= len(array)):
t = combos(array[i])
t = t*40 + 400
i += 1
t -= SPEED
# Controls the framerate on Windows
pygame.time.delay(FPS/1000)
# Update the display
VIEW.fill([255,255,255])
VIEW.blit(back, [0,270])
VIEW.fill([255,255,255])
VIEW.blit(back, [0,270])
VIEW.blit(player4.image, player4.rect.topleft)
if player4.isJumping:
player4.jump()
for trap in iter(OBS):
trap.move()
if trap.rect.colliderect(player4.rect):
STATE = 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.
FILECOMPLETE = True
STATE = False
pygame.display.update()
if (t <= 0) and (i+1 <= len(array)):
t = combos(array[i])
t = t*40 + 400
i += 1
t -= SPEED
# Controls the framerate on Windows
pygame.time.delay(FPS/1000)
# Update the display
VIEW.fill([255,255,255])
VIEW.blit(back, [0,270])
VIEW.fill([255,255,255])
VIEW.blit(back, [0,270])
VIEW.blit(player5.image, player5.rect.topleft)
if player5.isJumping:
player5.jump()
for trap in iter(OBS):
trap.move()
if trap.rect.colliderect(player5.rect):
STATE = 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.
FILECOMPLETE = True
STATE = False
pygame.display.update()
if (t <= 0) and (i+1 <= len(array)):
t = combos(array[i])
t = t*40 + 400
i += 1
t -= SPEED
for event in pygame.event.get():
#if the user quits, the game exits
if event.type == QUIT:
STATE = False
# Jump command.
elif event.type == pygame.KEYDOWN:
if (event.key == pygame.K_SPACE) and (player.isJumping == False):
#sound = pygame.mixer.music
#sound.load('JumpSound.mp3')
#sound.play(1,0)
player.jumpCount += 1
player2.jumpCount += 1
player3.jumpCount += 1
player4.jumpCount += 1
player5.jumpCount += 1
player.isJumping = True
player2.isJumping = True
player3.isJumping = True
player4.isJumping = True
player5.isJumping = True
player.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]
player4.velocity = -2.0*SPEED*ARCHEIGHT[1]/ARCHEIGHT[0]
player5.velocity = -2.0*SPEED*ARCHEIGHT[1]/ARCHEIGHT[0]
player.rect.top -= 1
player2.rect.top -= 1
player3.rect.top -= 1
player4.rect.top -= 1
player5.rect.top -= 1
# Give the player a moment to realize they died.
pygame.time.delay(500)