Mercurial > rinkhals
comparison gamelib/gameover.py @ 157:e3572b907028
Add splash images to game over screen.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Thu, 03 Sep 2009 21:45:57 +0000 |
parents | 082868bea873 |
children | 7bb8d9d6858a |
comparison
equal
deleted
inserted
replaced
156:210fc1ea0516 | 157:e3572b907028 |
---|---|
8 import imagecache | 8 import imagecache |
9 | 9 |
10 def create_game_over(gameboard): | 10 def create_game_over(gameboard): |
11 """Create a game over screen""" | 11 """Create a game over screen""" |
12 game_over = GameOver(gameboard) | 12 game_over = GameOver(gameboard) |
13 | 13 return GameOverContainer(game_over, align=0, valign=0) |
14 c = GameOverContainer(align=0, valign=0) | |
15 c.add(game_over, 0, 0) | |
16 | |
17 return c | |
18 | 14 |
19 class GameOverContainer(gui.Container): | 15 class GameOverContainer(gui.Container): |
16 def __init__(self, game_over, *args, **kwargs): | |
17 gui.Container.__init__(self, *args, **kwargs) | |
18 self.add(game_over, 0, 0) | |
19 if game_over.survived: | |
20 self.splash = imagecache.load_image("images/gameover_win.png") | |
21 else: | |
22 self.splash = imagecache.load_image("images/gameover_lose.png") | |
23 | |
20 def paint(self, s): | 24 def paint(self, s): |
21 pygame.display.set_caption('Game Over') | 25 pygame.display.set_caption('Game Over') |
22 #splash = imagecache.load_image("images/splash.png") | 26 pygame.display.get_surface().blit(self.splash, (0, 0)) |
23 #pygame.display.get_surface().blit(splash, (0, 0)) | |
24 gui.Container.paint(self, s) | 27 gui.Container.paint(self, s) |
25 | 28 |
26 class GameOver(gui.Table): | 29 class GameOver(gui.Table): |
27 def __init__(self, gameboard, **params): | 30 def __init__(self, gameboard, **params): |
28 gui.Table.__init__(self, **params) | 31 gui.Table.__init__(self, **params) |
32 self.tr() | |
29 | 33 |
30 def return_pressed(): | 34 def return_pressed(): |
31 pygame.event.post(engine.GO_MAIN_MENU) | 35 pygame.event.post(engine.GO_MAIN_MENU) |
32 | 36 |
33 def quit_pressed(): | 37 def quit_pressed(): |
34 pygame.event.post(engine.QUIT) | 38 pygame.event.post(engine.QUIT) |
35 | 39 |
36 if len(gameboard.chickens) > 0: | 40 if len(gameboard.chickens) > 0: |
41 self.survived = True | |
37 self.td(gui.Label("You Survived", color=constants.FG_COLOR), | 42 self.td(gui.Label("You Survived", color=constants.FG_COLOR), |
38 colspan=3) | 43 colspan=3) |
39 else: | 44 else: |
45 self.survived = False | |
40 self.td(gui.Label("You Lost", color=constants.FG_COLOR), | 46 self.td(gui.Label("You Lost", color=constants.FG_COLOR), |
41 colspan=3) | 47 colspan=3) |
42 | 48 |
43 self.tr() | 49 self.tr() |
44 self.td(gui.Label("Groats : %d" % gameboard.cash, | 50 self.td(gui.Label("Groats : %d" % gameboard.cash, |
50 self.tr() | 56 self.tr() |
51 self.td(gui.Label("Final score : %d" % (gameboard.cash + | 57 self.td(gui.Label("Final score : %d" % (gameboard.cash + |
52 constants.SELL_PRICE_CHICKEN * len(gameboard.chickens) + | 58 constants.SELL_PRICE_CHICKEN * len(gameboard.chickens) + |
53 constants.SELL_PRICE_EGG * gameboard.eggs), | 59 constants.SELL_PRICE_EGG * gameboard.eggs), |
54 color=constants.FG_COLOR), colspan=3) | 60 color=constants.FG_COLOR), colspan=3) |
61 | |
62 self.tr() | |
63 self.td(gui.Spacer(0, 50), colspan=3) | |
55 | 64 |
56 return_button = gui.Button("Return to Main Menu") | 65 return_button = gui.Button("Return to Main Menu") |
57 return_button.connect(gui.CLICK, return_pressed) | 66 return_button.connect(gui.CLICK, return_pressed) |
58 | 67 |
59 quit_button = gui.Button("Quit") | 68 quit_button = gui.Button("Quit") |