Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9ccf678

Browse files
Add files via upload
1 parent 7ed5ee4 commit 9ccf678

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

‎Game.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
background = pygame.transform.scale(pygame.image.load('desert_BG.png'), (win_width, win_height))
6161
# Tower
6262
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)
6367

6468
class Hero:
6569
def __init__(self, x, y):
@@ -125,7 +129,7 @@ def direction(self):
125129
return -1
126130

127131
def cooldown(self):
128-
if self.cool_down_count >= 20:
132+
if self.cool_down_count >= 10:
129133
self.cool_down_count = 0
130134
elif self.cool_down_count > 0:
131135
self.cool_down_count += 1
@@ -134,6 +138,7 @@ def shoot(self):
134138
self.hit()
135139
self.cooldown()
136140
if (userInput[pygame.K_f] and self.cool_down_count == 0):
141+
pop_sound.play()
137142
bullet = Bullet(self.x, self.y, self.direction())
138143
self.bullets.append(bullet)
139144
self.cool_down_count = 1
@@ -215,6 +220,7 @@ def off_screen(self):
215220

216221
# Draw Game
217222
def draw_game():
223+
global tower_health, speed
218224
win.fill((0, 0, 0))
219225
win.blit(background, (0, 0))
220226
# Draw Player
@@ -239,6 +245,8 @@ def draw_game():
239245
player.alive = True
240246
player.lives = 1
241247
player.health = 30
248+
tower_health = 2
249+
speed = 2
242250
font = pygame.font.Font('freesansbold.ttf', 32)
243251
text = font.render('Lives: ' + str(player.lives) + ' | Tower Health: '+ str(tower_health) + ' |Kills: '+ str(kills), True, (0, 0, 0))
244252
win.blit(text, (150, 20))
@@ -252,11 +260,11 @@ def draw_game():
252260

253261
# Instance of Enemy-Class
254262
enemies = []
255-
speed = 3
263+
speed = 2
256264
kills = 0
257265

258266
# Tower
259-
tower_health = 5
267+
tower_health = 2
260268

261269
# Mainloop
262270
run = True
@@ -277,12 +285,16 @@ def draw_game():
277285
player.move_hero(userInput)
278286
player.jump_motion(userInput)
279287

288+
# Tower Health
289+
if tower_health == 0:
290+
player.alive = False
291+
280292
# Enemy
281293
if len(enemies) == 0:
282294
enemy = Enemy(750, 300, speed)
283295
enemies.append(enemy)
284296
if speed <= 10:
285-
speed += 1
297+
speed += 0.25
286298
for enemy in enemies:
287299
enemy.move()
288300
if enemy.off_screen() or enemy.health == 0:
@@ -294,4 +306,4 @@ def draw_game():
294306
kills +=1
295307

296308
# Draw Game in Window
297-
draw_game()
309+
draw_game()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /