Mercurial > rinkhals
annotate gamelib/gameover.py @ 222:322e6d3a46e4
Turn 'd' into a fast forward / normal speed toggle at night
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Fri, 04 Sep 2009 22:38:48 +0000 |
parents | 7bb8d9d6858a |
children | 96d440bebdaa |
rev | line source |
---|---|
139 | 1 """The Game Over Screen""" |
2 | |
3 from pgu import gui | |
4 import pygame | |
5 | |
6 import engine | |
7 import constants | |
8 import imagecache | |
9 | |
151
082868bea873
Refactor UI so that only a single gui.App is used. Pass all UI events via main_app. Change Toolbar table to use .td() everywhere. Move toolbar to top.
Simon Cross <hodgestar@gmail.com>
parents:
139
diff
changeset
|
10 def create_game_over(gameboard): |
082868bea873
Refactor UI so that only a single gui.App is used. Pass all UI events via main_app. Change Toolbar table to use .td() everywhere. Move toolbar to top.
Simon Cross <hodgestar@gmail.com>
parents:
139
diff
changeset
|
11 """Create a game over screen""" |
139 | 12 game_over = GameOver(gameboard) |
157
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
13 return GameOverContainer(game_over, align=0, valign=0) |
139 | 14 |
15 class GameOverContainer(gui.Container): | |
157
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
16 def __init__(self, game_over, *args, **kwargs): |
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
17 gui.Container.__init__(self, *args, **kwargs) |
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
18 self.add(game_over, 0, 0) |
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
19 if game_over.survived: |
159
7bb8d9d6858a
Darken center of game over splash screen to make text legible.
Simon Cross <hodgestar@gmail.com>
parents:
157
diff
changeset
|
20 self.splash = imagecache.load_image("images/gameover_win.png", ["darken_center"]) |
157
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
21 else: |
159
7bb8d9d6858a
Darken center of game over splash screen to make text legible.
Simon Cross <hodgestar@gmail.com>
parents:
157
diff
changeset
|
22 self.splash = imagecache.load_image("images/gameover_lose.png", ["darken_center"]) |
157
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
23 |
139 | 24 def paint(self, s): |
25 pygame.display.set_caption('Game Over') | |
157
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
26 pygame.display.get_surface().blit(self.splash, (0, 0)) |
139 | 27 gui.Container.paint(self, s) |
28 | |
29 class GameOver(gui.Table): | |
30 def __init__(self, gameboard, **params): | |
31 gui.Table.__init__(self, **params) | |
157
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
32 self.tr() |
139 | 33 |
34 def return_pressed(): | |
35 pygame.event.post(engine.GO_MAIN_MENU) | |
36 | |
37 def quit_pressed(): | |
38 pygame.event.post(engine.QUIT) | |
39 | |
40 if len(gameboard.chickens) > 0: | |
157
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
41 self.survived = True |
139 | 42 self.td(gui.Label("You Survived", color=constants.FG_COLOR), |
43 colspan=3) | |
44 else: | |
157
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
45 self.survived = False |
139 | 46 self.td(gui.Label("You Lost", color=constants.FG_COLOR), |
47 colspan=3) | |
48 | |
49 self.tr() | |
50 self.td(gui.Label("Groats : %d" % gameboard.cash, | |
51 color=constants.FG_COLOR)) | |
52 self.td(gui.Label(" Chickens : %d " % len(gameboard.chickens), | |
53 color=constants.FG_COLOR)) | |
54 self.td(gui.Label(" Eggs : %d" % gameboard.eggs, | |
55 color=constants.FG_COLOR)) | |
56 self.tr() | |
57 self.td(gui.Label("Final score : %d" % (gameboard.cash + | |
58 constants.SELL_PRICE_CHICKEN * len(gameboard.chickens) + | |
59 constants.SELL_PRICE_EGG * gameboard.eggs), | |
60 color=constants.FG_COLOR), colspan=3) | |
61 | |
157
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
62 self.tr() |
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
63 self.td(gui.Spacer(0, 50), colspan=3) |
e3572b907028
Add splash images to game over screen.
Simon Cross <hodgestar@gmail.com>
parents:
151
diff
changeset
|
64 |
139 | 65 return_button = gui.Button("Return to Main Menu") |
66 return_button.connect(gui.CLICK, return_pressed) | |
67 | |
68 quit_button = gui.Button("Quit") | |
69 quit_button.connect(gui.CLICK, quit_pressed) | |
70 | |
71 style = { | |
72 "padding_bottom": 15, | |
73 } | |
74 td_kwargs = { | |
75 "align": 0, | |
76 "style": style, | |
77 "colspan": 3, | |
78 } | |
79 | |
80 self.tr() | |
81 self.td(return_button, **td_kwargs) | |
82 | |
83 self.tr() | |
84 self.td(quit_button, **td_kwargs) |