-
Notifications
You must be signed in to change notification settings - Fork 0
/
l1.py
307 lines (281 loc) · 14.6 KB
/
l1.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
#Creating the level 1 class
#By Tyler Spadgenske
import pygame, sys, random
from pygame.locals import *
#import custom classes
import background, button, toolbar, selectGun, selectTool, person, powerups, baddieAI
from background import Level_1
from button import Button
from toolbar import Toolbar
from selectGun import selectGunMenu
from selectTool import selectToolMenu
from person import Person
from powerups import Powerups
from baddieAI import AI
from popups import Popups
from file import File
class L1(object):
def __init__(self, windowSurface, mainClock, SKY_BLUE, gameData, showFPS):
self.getFiles = File
#Create game data
self.lockedGuns = gameData['lockedGuns']
self.lockedTools = gameData['lockedTools']
self.sound = gameData['sound']
self.runGame = True
self.showFPS = showFPS
#Setup theme music
pygame.mixer.music.load('files//sound//gameTheme.mp3')
#Constants
self.BPS = 8 #(Bullets Per Second)
self.TOTAL_SUPPLIES = 12 #Total Supplies for each powerup
self.SKY_BLUE = SKY_BLUE #Sky color
self.TOTAL_COPS = 32 #Total number of all cops in level
#Variables
self.windowSurface = windowSurface
self.clock = mainClock
#Setup Dr. Taco's Direction
self.moveRight = False
self.moveLeft = False
#Set Start Weapon and tool, and make sure menus are closed.
self.currentWeapon = '9mm'
self.currentTool = 'crowbar'
self.dropDownGun = False
self.dropDownTool = False
#Set Basic Values
self.score = 0
self.ammo = 30
self.hit = False
self.gunButtonCoords = [695, 30, 735, 30, 715, 50]
self.toolButtonCoords = [395, 30, 435, 30, 415, 50]
self.officerX = 1500
self.officerGunX = {'right':abs(self.officerX) + 55, 'left':self.officerX + -3}
self.gunXlist = []
self.takeStep = 0
self.direction = 1
self.goUp = None
self.shootBullet = False
self.message = 'This is the Message Box.'
self.skill_level = 800
self.centered = False
self.drop = False
self.paused = False
self.reload = False
self.endReload = False
self.endBack = False
self.die = False
self.val = None
self.rapidFire = [0, False]
self.lifeLeft = 0
self.endPoint = 0
self.back = False
self.tacosCollected = 0
self.first = True
self.flame = False
#Initialize Objects
self.level_1 = Level_1(self.windowSurface)
self.tools = Toolbar(self.lockedGuns, self.windowSurface)
self.gunMenu = selectGunMenu(self.lockedGuns)
self.toolMenu = selectToolMenu(self.lockedTools)
self.gunArrowButton = Button(self.windowSurface)
self.toolArrowButton = Button(self.windowSurface)
self.DrTaco = Person('Doctor Taco', self.windowSurface, self.officerX, self.officerGunX)
self.wingame = Popups(self.windowSurface)
#Default lists
self.copList = []
self.Xlist = []
self.num = 700
#Add a cop every 250 pixels for the range in TOTAL_COPS
for i in range(0, self.TOTAL_COPS):
self.Xlist.append(self.num)
self.num += 250
self.num = 0
#Add the cop object
self.index = 0
for cop in range(0, self.TOTAL_COPS):
self.copList.append(AI(self.windowSurface, self.skill_level, self.Xlist[self.index]))
self.index += 1
#Add the cops gun
self.index = 0
for i in range(0, self.TOTAL_COPS):
self.gunXlist.append({'right':abs(self.Xlist[self.index]) + 80, 'left':self.Xlist[self.index] + -10})
self.index += 1
#Add Supplies to random locations
self.healthX = []
self.tacosX = []
self.tacosY = []
self.ammoX = []
self.ammoBoxes = []
self.healthBoxes = []
self.tacos = []
for i in range(0, self.TOTAL_SUPPLIES):
self.ammoBoxes.append(Powerups(self.windowSurface, self.score))
self.healthBoxes.append(Powerups(self.windowSurface, self.score))
for i in range(0, 2):
self.tacos.append(Powerups(self.windowSurface, self.score))
self.tacosX.append(random.randint(300, 9000))
self.tacosY.append(random.randint(300, 490))
self.healthX.append(random.randint(300, 9000))
self.ammoX.append(random.randint(300, 9000))
def play(self, highscore, totalscore):
#If there is no quit event, (i.e reload or back)
while self.runGame == True:
self.stopAll = False
#Setup rect list and blit background
self.reload = False
self.ammoX, self.healthX, self.tacosX, self.endPoint = self.level_1.blitBackground(self.moveRight, self.moveLeft, self.ammoX,
self.healthX, self.tacosX, self.copList, self.centered)
#Setup all the cops gun position.
self.index = 0
for cop in self.copList:
self.gunXlist[self.index] = {'right':self.copList[self.index].get_rect()[0] + 80, 'left':self.copList[self.index].get_rect()[0] + -10}
self.index += 1
for event in pygame.event.get():
self.sound, self.paused, self.reload, self.back = self.tools.addButtons(self.sound, event)
if event.type == QUIT:
self.runGame = False
self.stopAll = True
if event.type == KEYDOWN:
if event.key == K_RIGHT:
self.direction = 1
self.moveRight = True
self.moveLeft = False
if event.key == K_LEFT:
self.direction = 0
self.moveLeft = True
self.moveRight = False
if event.key == K_UP:
if self.goUp == None:
self.goUp = True
if event.key == K_SPACE:
self.shootBullet = True
self.rapidFire[1] = True
if event.type == KEYUP:
self.moveRight = False
self.moveLeft = False
self.shootBullet = False
self.rapidFire[1] = False
if self.currentWeapon == 'flamethrower':
self.shootBullet = False
self.dropDownGun = self.gunArrowButton.arrow(self.dropDownGun, event, self.gunButtonCoords)
self.dropDownTool = self.toolArrowButton.arrow(self.dropDownTool, event, self.toolButtonCoords)
if self.dropDownGun:
self.currentWeapon = self.gunMenu.selectGunButton(self.currentWeapon, event)
if self.dropDownTool:
self.currentTool = self.toolMenu.selectToolButton(self.currentTool, event)
self.rapidFire[0] += 1
if self.rapidFire[0] == self.BPS:
self.rapidFire[0] = 0
if self.rapidFire[1]:
if self.currentWeapon == 'AK-47':
self.shootBullet = True
#Add Health bar, score, message box, buttons, and ammo text to screen
self.tools.display()
self.tools.messageBox(self.message)
self.tools.countScore(self.score)
self.tools.countAmmo(self.ammo, self.currentWeapon)
self.sound, self.paused, self.reaload, self.backk = self.tools.addButtons(self.sound, None)
self.tools.health(self.lifeLeft)
#Blit select gun menu, select tool menu, and drop down arrows to screen and allow user to select weapon (or gun)
self.dropDownGun, self.currentWeapon = self.gunMenu.chooseGun(self.windowSurface, self.dropDownGun, self.currentWeapon)
self.dropDownTool, self.currentTool = self.toolMenu.chooseTool(self.windowSurface, self.dropDownTool, self.currentTool)
self.gunArrowButton.blitArrow(self.windowSurface, self.dropDownGun, self.gunButtonCoords)
self.toolArrowButton.blitArrow(self.windowSurface, self.dropDownTool, self.toolButtonCoords)
#Get Frames per second and and it to screen
self.fps = int(self.clock.get_fps())
self.tools.FPS(self.fps, self.showFPS)
#If game is not paused, let Dr. Taco walk, jump, and shoot selected weapon
if self.paused != True:
#Make it so Dr. Taco can jump and move
self.takeStep, self.centered = self.DrTaco.walk(self.takeStep, self.direction, self.moveLeft, self.moveRight, self.currentWeapon)
self.goUp = self.DrTaco.jump(self.goUp)
#If weapon is the Pistol, put it in Dr. Taco's hand and enable it for use.
if self.currentWeapon == '9mm':
self.shootBullet, self.hit, self.ammo, self.message, self.score, self.officerX, self.drop, self.val, self.val, self.lifeLeft = self.DrTaco.shootPistol(
self.shootBullet, self.hit, self.direction, self.officerGunX, self.sound, self.copList, self.ammo, self.message, self.score,
lifeLeft = self.lifeLeft)
#If weapon is the Shotgun, put it in Dr. Taco's hand and enable it for use.
if self.currentWeapon == 'shotgun':
self.shootBullet, self.hit, self.ammo, self.message, self.score, self.officerX, self.drop, self.val, self.lifeLeft = self.DrTaco.shootShotgun(
self.shootBullet, self.hit, self.direction, self.officerGunX, self.sound, self.copList, self.ammo, self.message, self.score,
lifeLeft = self.lifeLeft)
#If weapon is the AK-47, put it in Dr. Taco's hand and enable it for use.
if self.currentWeapon == 'AK-47':
self.shootBullet, self.hit, self.ammo, self.message, self.score, self.officerX, self.drop, self.val, self.lifeLeft = self.DrTaco.shootAK(
self.shootBullet, self.hit, self.direction, self.officerGunX, self.sound, self.copList, self.ammo, self.message, self.score,
lifeLeft = self.lifeLeft)
self.shootBullet = False
#If weapon is the bazooka, put it in Dr. Taco's hand and enable it for use.
if self.currentWeapon == 'bazooka':
self.shootBullet, self.hit, self.ammo, self.message, self.score, self.officerX, self.drop, self.val, self.lifeLeft = self.DrTaco.shootBazooka(
self.shootBullet, self.hit, self.direction, self.officerGunX, self.sound, self.copList, self.ammo, self.message, self.score,
self.currentWeapon, lifeLeft = self.lifeLeft)
#If weapon is the flamethrower, put it in Dr. Taco's hand and enable it for use.
if self.currentWeapon == 'flamethrower':
self.shootBullet, self.hit, self.ammo, self.message, self.score, self.officerX, self.drop, self.val, self.lifeLeft, self.flame = self.DrTaco.shootFlame(
self.shootBullet, self.hit, self.direction, self.officerGunX, self.sound, self.copList, self.ammo, self.message, self.score,
self.currentWeapon, self.lifeLeft)
#Make all the cops think
self.index = 0
for cop in self.copList:
self.hit, self.endReload, self.endBack, self.lifeLeft = cop.think(self.DrTaco.get_rect(), self.copList[self.index].get_rect()[0], self.gunXlist[self.index],
self.drop, self.hit, self.sound, self.lifeLeft, self.flame)
#If Dr. Taco is dead break out of loop
if self.endReload:
break
if self.endBack:
break
self.index += 1
#Blit all the supplies to the screen by running their functions
self.index = 0
for box in self.ammoBoxes:
self.score, self.ammo = box.ammoBox(self.ammoX[self.index], 490, self.DrTaco.get_rect(), self.ammo, self.score, self.sound)
self.index += 1
self.index = 0
for box in self.healthBoxes:
self.score, self.lifeLeft = box.healthBox(self.healthX[self.index], 490, self.DrTaco.get_rect(), self.lifeLeft, self.sound, self.score)
self.index += 1
self.index = 0
for box in self.tacos:
self.score, self.tacosCollected = box.taco(self.tacosX[self.index], self.tacosY[self.index],
self.DrTaco.get_rect(), self.sound, self.score, self.tacosCollected)
self.index += 1
#If Dr. Taco has reached the end of the level, display level completed popup and exit loop
if self.endPoint < 298:
self.endReload, self.back = self.wingame.wingame(self.score, self.tacosCollected)
#If the health bar length is too much set it to right size
if self.lifeLeft >= 20:
self.lifeLeft = 20
#Update screen and fill background
pygame.display.update()
self.clock.tick()
self.windowSurface.fill(self.SKY_BLUE)
#If reload button is clicked exit loop and enter another object
if self.endReload:
pygame.mixer.music.stop()
self.runGame = False
self.reload = True
if self.reload:
pygame.mixer.music.stop()
self.runGame = False
if self.back:
pygame.mixer.music.stop()
self.runGame = False
if self.endBack:
pygame.mixer.music.stop()
self.runGame = False
self.back = True
#Add score to total score
if self.runGame != True:
totalscore += self.score
#Check for high score
if highscore < self.score:
highscore = self.score
#Play music
if self.sound == True:
if self.first:
pygame.mixer.music.play(-1, 0.0)
self.first = False
else:
pygame.mixer.music.stop()
self.first = True
return self.reload, self.back, highscore, totalscore, self.stopAll