Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added is_gameover to main.py file

  • Loading branch information...
commit e9abec60083f2c887cc66641379773a0f2a3e25e 1 parent 4f86c7a
@jlevey3 authored
Showing with 20 additions and 4 deletions.
  1. +1 −0  files/app.py
  2. +19 −4 files/main.py
View
1  files/app.py
@@ -13,6 +13,7 @@ def resume(self): pass
def handle_event(self, event): pass
def update(self): pass
def draw(self, screen): pass
+ def game_over(self): pass
class Application(object):
View
23 files/main.py
@@ -28,6 +28,7 @@ def setup(self):
font.set_bold(False)
font.set_italic(True)
font.set_underline(False)
+ font = pygame.font.Font(None,30)
self.inst = font.render("Press <SPACE> to Start", True, self.fg_color, self.bg_color)
def resume(self):
@@ -107,13 +108,13 @@ def setup (self):
def handle_event(self, event):
if event.type == KEYDOWN and event.key == K_ESCAPE:
self.app.set_state(PauseMenu)
- elif event.type == KEYDOWN and event.key == K_SPACE:
+ elif event.type == KEYDOWN and event.key == K_SPACE and not self.is_gameover():
if self.player.carrying:
self.player.drop()
else:
for robot in groupcollide(self.robot_grp, self.player_grp, False, False):
self.player.grab(robot)
- self.score += 5
+ self.score += 50
print "robot picked up"
@@ -122,6 +123,9 @@ def resume(self):
print "Loop Started"
def update(self):
+ if self.is_gameover():
+ self.player.kill()
+
self.spawnticker += 1
if self.spawnticker >= self.spawntime:
@@ -146,13 +150,20 @@ def update(self):
coll = groupcollide(self.robot_grp, ImpactGroup.impacts, False, False)
for robot in coll:
robot.damage(coll[robot][0])
+
+ #gameover
+ def is_gameover(self):
+ all_alive = self.player.alive()
+ for robot in self.robot_grp:
+ all_alive = all_alive and robot.alive()
+ return not all_alive
def draw(self, screen):
screen.fill(BG_COLOR)
- self.robot_grp.draw(screen)
-
+ self.robot_grp.draw(screen)
+
ImpactGroup.impacts.draw(screen)
self.meteors.draw(screen)
self.player_grp.draw(screen)
@@ -161,7 +172,11 @@ def draw(self, screen):
score_text = self.font.render("Score: %05d"%self.score, False, (255,255,255))
screen.blit(score_text, (5,5))
+ gameover_text = self.font.render("Game over! Your score is %05d. Hit ESC + q to return to main menu."%self.score, False, (255,255,255))
+ if self.is_gameover():
+ print "game over"
+ screen.blit(gameover_text, (10,350))
Please sign in to comment.
Something went wrong with that request. Please try again.