Mercurial > rinkhals
changeset 179:e2b5262c2b11
Add basic help screen
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Fri, 04 Sep 2009 15:00:54 +0000 |
parents | 92387848caec |
children | c0cad267222b |
files | gamelib/engine.py gamelib/helpscreen.py gamelib/mainmenu.py |
diffstat | 3 files changed, 105 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/gamelib/engine.py Fri Sep 04 07:19:58 2009 +0000 +++ b/gamelib/engine.py Fri Sep 04 15:00:54 2009 +0000 @@ -9,6 +9,7 @@ import sound import constants import mainmenu +import helpscreen class Engine(Game): def __init__(self, main_app): @@ -37,6 +38,11 @@ """Open the main menu""" self.open_window(self.main_menu) + def set_help_screen(self): + """Open the main menu""" + help_screen = helpscreen.make_help_screen() + self.open_window(help_screen) + def create_game_over(self): """Create and open the Game Over window""" game_over = gameover.create_game_over(self.gameboard) @@ -51,6 +57,8 @@ if events_equal(e, START_DAY): self.game.create_game_board() return DayState(self.game) + elif events_equal(e, GO_HELP_SCREEN): + return HelpScreenState(self.game) elif e.type is KEYDOWN: if e.key == K_ESCAPE: return Quit(self.game) @@ -69,6 +77,28 @@ update = self.game.main_app.update(screen) pygame.display.update(update) +class HelpScreenState(State): + def init(self): + sound.stop_background_music() + self.game.set_help_screen() + + def event(self, e): + if e.type is KEYDOWN and e.key == K_ESCAPE: + return MainMenu(self.game) + elif events_equal(e, GO_MAIN_MENU): + return MainMenuState(self.game) + elif e.type is not QUIT: + self.game.main_app.event(e) + + def paint(self, screen): + screen.fill((0,0,0)) + self.game.main_app.paint(screen) + pygame.display.flip() + + def update(self, screen): + update = self.game.main_app.update(screen) + pygame.display.update(update) + class DayState(State): def init(self): """Add some chickens to the farm""" @@ -189,6 +219,7 @@ START_DAY = pygame.event.Event(USEREVENT, name="START_DAY") START_NIGHT = pygame.event.Event(USEREVENT, name="START_NIGHT") GO_MAIN_MENU = pygame.event.Event(USEREVENT, name="GO_MAIN_MENU") +GO_HELP_SCREEN = pygame.event.Event(USEREVENT, name="GO_HELP_SCREEN") MOVE_FOX_ID = USEREVENT + 1 MOVE_FOXES = pygame.event.Event(MOVE_FOX_ID, name="MOVE_FOXES") QUIT = pygame.event.Event(QUIT)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gamelib/helpscreen.py Fri Sep 04 15:00:54 2009 +0000 @@ -0,0 +1,65 @@ +"""Help screen.""" + +from pgu import gui +import pygame +import constants +import engine +import imagecache + +HELP="""Welcome to %s + +Introduction: + +The aim of the game is to make as much money as possible from your chicken +farm. The problem is the foxes, which want to eat your chickens. Since hiring +guards is both too expensive and unreliable, the obvious solution is to help +the chickens defend themselves. + +Game mechanics: + +You lose if you end a night with no chickens left. + +You win if you survive 14 nights. + +Chickens only lay eggs in henhouses, and must stay on the egg for 2 days to +hatch a new chicken. Chickens that hatch in already full henhouses die +immediately from overcrowding. +""" % constants.NAME + +def make_help_screen(): + """Create a main menu""" + help_screen = HelpScreen(width=600) + + c = HelpContainer(align=0, valign=0) + c.add(help_screen, 0, 0) + + return c + +class HelpContainer(gui.Container): + def paint(self, s): + pygame.display.set_caption('Instructions') + splash = imagecache.load_image("images/splash.png") + pygame.display.get_surface().blit(splash, (0, 0)) + gui.Container.paint(self, s) + +class HelpScreen(gui.Document): + def __init__(self, **params): + gui.Document.__init__(self, **params) + + def done_pressed(): + pygame.event.post(engine.GO_MAIN_MENU) + + done_button = gui.Button("Return to Main Menu") + done_button.connect(gui.CLICK, done_pressed) + + space = self.style.font.size(" ") + + for paragraph in HELP.split('\n\n'): + self.block(align=-1) + for word in paragraph.split(): + self.add(gui.Label(word)) + self.space(space) + self.br(space[1]) + self.br(space[1]) + self.block(align=0) + self.add(done_button, align=0)
--- a/gamelib/mainmenu.py Fri Sep 04 07:19:58 2009 +0000 +++ b/gamelib/mainmenu.py Fri Sep 04 15:00:54 2009 +0000 @@ -35,12 +35,18 @@ def start_pressed(): pygame.event.post(engine.START_DAY) + def help_pressed(): + pygame.event.post(engine.GO_HELP_SCREEN) + start_button = gui.Button("Start") start_button.connect(gui.CLICK, start_pressed) quit_button = gui.Button("Quit") quit_button.connect(gui.CLICK, quit_pressed) + help_button = gui.Button("Instructions") + help_button.connect(gui.CLICK, help_pressed) + fullscreen_toggle = gui.Button("Toggle Fullscreen") fullscreen_toggle.connect(gui.CLICK, fullscreen_toggled) @@ -56,6 +62,9 @@ self.td(start_button, **td_kwargs) self.tr() + self.td(help_button, **td_kwargs) + + self.tr() self.td(fullscreen_toggle, **td_kwargs) self.tr()