60
60
background = pygame .transform .scale (pygame .image .load ('desert_BG.png' ), (win_width , win_height ))
61
61
# Tower
62
62
tower = pygame .transform .scale (pygame .image .load ('Tower.png' ), (200 ,200 ))
63
+ # Music/Sounds
64
+ music = pygame .mixer .music .load ('music.ogg' )
65
+ pop_sound = pygame .mixer .Sound ('pop.ogg' )
66
+ pygame .mixer .music .play (- 1 )
63
67
64
68
class Hero :
65
69
def __init__ (self , x , y ):
@@ -125,7 +129,7 @@ def direction(self):
125
129
return - 1
126
130
127
131
def cooldown (self ):
128
- if self .cool_down_count >= 20 :
132
+ if self .cool_down_count >= 10 :
129
133
self .cool_down_count = 0
130
134
elif self .cool_down_count > 0 :
131
135
self .cool_down_count += 1
@@ -134,6 +138,7 @@ def shoot(self):
134
138
self .hit ()
135
139
self .cooldown ()
136
140
if (userInput [pygame .K_f ] and self .cool_down_count == 0 ):
141
+ pop_sound .play ()
137
142
bullet = Bullet (self .x , self .y , self .direction ())
138
143
self .bullets .append (bullet )
139
144
self .cool_down_count = 1
@@ -215,6 +220,7 @@ def off_screen(self):
215
220
216
221
# Draw Game
217
222
def draw_game ():
223
+ global tower_health , speed
218
224
win .fill ((0 , 0 , 0 ))
219
225
win .blit (background , (0 , 0 ))
220
226
# Draw Player
@@ -239,6 +245,8 @@ def draw_game():
239
245
player .alive = True
240
246
player .lives = 1
241
247
player .health = 30
248
+ tower_health = 2
249
+ speed = 2
242
250
font = pygame .font .Font ('freesansbold.ttf' , 32 )
243
251
text = font .render ('Lives: ' + str (player .lives ) + ' | Tower Health: ' + str (tower_health ) + ' |Kills: ' + str (kills ), True , (0 , 0 , 0 ))
244
252
win .blit (text , (150 , 20 ))
@@ -252,11 +260,11 @@ def draw_game():
252
260
253
261
# Instance of Enemy-Class
254
262
enemies = []
255
- speed = 3
263
+ speed = 2
256
264
kills = 0
257
265
258
266
# Tower
259
- tower_health = 5
267
+ tower_health = 2
260
268
261
269
# Mainloop
262
270
run = True
@@ -277,12 +285,16 @@ def draw_game():
277
285
player .move_hero (userInput )
278
286
player .jump_motion (userInput )
279
287
288
+ # Tower Health
289
+ if tower_health == 0 :
290
+ player .alive = False
291
+
280
292
# Enemy
281
293
if len (enemies ) == 0 :
282
294
enemy = Enemy (750 , 300 , speed )
283
295
enemies .append (enemy )
284
296
if speed <= 10 :
285
- speed += 1
297
+ speed += 0.25
286
298
for enemy in enemies :
287
299
enemy .move ()
288
300
if enemy .off_screen () or enemy .health == 0 :
@@ -294,4 +306,4 @@ def draw_game():
294
306
kills += 1
295
307
296
308
# Draw Game in Window
297
- draw_game ()
309
+ draw_game ()
0 commit comments