comparison gamelib/menu.py @ 446:a6de33fecb97

Hook up splash screen
author Stefano Rivera <stefano@rivera.za.net>
date Sun, 29 Aug 2010 00:30:17 +0200
parents 97322b78d1c1
children ece69836f00a
comparison
equal deleted inserted replaced
445:ef39ffe3fcc2 446:a6de33fecb97
1 # menu.py 1 # menu.py
2 # Copyright Boomslang team, 2010 (see COPYING File) 2 # Copyright Boomslang team, 2010 (see COPYING File)
3 # Main menu for the game 3 # Main menu for the game
4 4
5 from albow.screen import Screen 5 from albow.screen import Screen
6 from albow.controls import Button, Label 6 from albow.controls import Image, Button, Label
7 from albow.layout import Column 7 from albow.layout import Column
8 from albow.resource import get_image
9 from pygame import Rect
10
11 class SplashButton(Image):
12 """The fancy hand button for the widget"""
13
14 def __init__(self, filename, x, y, action, enable=None):
15 this_image = get_image('splash', filename)
16 Image.__init__(self, image=this_image)
17 self.action = action
18 self.set_rect(Rect((x, y), this_image.get_size()))
19 self.enable = enable
20
21 def draw(self, surface):
22 if self.is_enabled():
23 surface.blit(self.get_image(), self.get_rect())
24
25 def mouse_down(self, event):
26 if self.is_enabled():
27 self.action()
28
29 def is_enabled(self):
30 if self.enable:
31 return self.enable()
32 return True
8 33
9 34
10 class MenuScreen(Screen): 35 class MenuScreen(Screen):
11 def __init__(self, shell): 36 def __init__(self, shell):
12 Screen.__init__(self, shell) 37 Screen.__init__(self, shell)
13 StartButton = Button('Start New Game', action = self.start) 38 self._background = get_image('splash', 'splash.png')
14 ResumeButton = Button('Resume Game', action = self.resume, 39 self._start_button = SplashButton('play.png', 16, 523, self.start)
15 enable=self.check_running) 40 self._resume_button = SplashButton('resume.png', 256, 523, self.resume,
16 QuitButton = Button('Quit', action = shell.quit) 41 enable=self.check_running)
17 Title = Label('Suspended Sentence') 42 self._quit_button = SplashButton('quit.png', 580, 523, shell.quit)
18 menu = Column([ 43 self.add(self._start_button)
19 Title, 44 self.add(self._resume_button)
20 StartButton, 45 self.add(self._quit_button)
21 ResumeButton, 46
22 QuitButton, 47 def draw(self, surface):
23 ], align='l', spacing=20) 48 surface.blit(self._background, (0, 0))
24 self.add_centered(menu) 49 self._start_button.draw(surface)
50 self._resume_button.draw(surface)
51 self._quit_button.draw(surface)
25 52
26 def start(self): 53 def start(self):
27 self.shell.game_screen.start_game() 54 self.shell.game_screen.start_game()
28 self.shell.show_screen(self.shell.game_screen) 55 self.shell.show_screen(self.shell.game_screen)
29 56
32 59
33 def resume(self): 60 def resume(self):
34 if self.shell.game_screen.running: 61 if self.shell.game_screen.running:
35 self.shell.show_screen(self.shell.game_screen) 62 self.shell.show_screen(self.shell.game_screen)
36 63
37
38