Mercurial > boomslang
comparison gamelib/gamescreen.py @ 29:6322d92dc8f0
Add state widget for rendering state.
author | Simon Cross <hodgestar+bzr@gmail.com> |
---|---|
date | Sun, 22 Aug 2010 19:20:58 +0200 |
parents | 0f25f7b9b37a |
children | e5c043aeed65 |
comparison
equal
deleted
inserted
replaced
28:0f25f7b9b37a | 29:6322d92dc8f0 |
---|---|
3 # Main menu for the game | 3 # Main menu for the game |
4 | 4 |
5 from state import initial_state | 5 from state import initial_state |
6 | 6 |
7 from pygame.color import Color | 7 from pygame.color import Color |
8 from pygame import Rect | |
8 from albow.screen import Screen | 9 from albow.screen import Screen |
9 from albow.controls import Button, Label | 10 from albow.controls import Button, Label, Widget |
10 from albow.layout import Column | 11 from albow.layout import Column |
11 from albow.palette_view import PaletteView | 12 from albow.palette_view import PaletteView |
12 | 13 |
13 | 14 |
14 class InventoryView(PaletteView): | 15 class InventoryView(PaletteView): |
39 | 40 |
40 def add_item(self, colstr): | 41 def add_item(self, colstr): |
41 self.info.append(colstr) | 42 self.info.append(colstr) |
42 | 43 |
43 | 44 |
45 class StateWidget(Widget): | |
46 | |
47 def __init__(self, state): | |
48 Widget.__init__(self, Rect(0, 0, 800, 600)) | |
49 self.state = state | |
50 | |
51 def draw(self, surface): | |
52 self.state.draw(surface) | |
53 | |
54 | |
44 class GameScreen(Screen): | 55 class GameScreen(Screen): |
45 def __init__(self, shell): | 56 def __init__(self, shell): |
46 Screen.__init__(self, shell) | 57 Screen.__init__(self, shell) |
47 self.shell = shell | 58 self.shell = shell |
59 | |
60 # TODO: Randomly plonk the state here for now | |
61 self.state = initial_state() | |
62 self.state_widget = StateWidget(self.state) | |
63 self.add(self.state_widget) | |
64 | |
48 StartButton = Button('Main Menu', action = self.main_menu) | 65 StartButton = Button('Main Menu', action = self.main_menu) |
49 QuitButton = Button('Quit', action = shell.quit) | 66 QuitButton = Button('Quit', action = shell.quit) |
50 AddItemButton = Button('Add item', action = self.add_item) | 67 AddItemButton = Button('Add item', action = self.add_item) |
51 Title = Label('Caught! ... In SPAACE') | 68 Title = Label('Caught! ... In SPAACE') |
52 menu = Column([ | 69 menu = Column([ |
54 StartButton, | 71 StartButton, |
55 QuitButton, | 72 QuitButton, |
56 AddItemButton, | 73 AddItemButton, |
57 ], align='l', spacing=20) | 74 ], align='l', spacing=20) |
58 self.add_centered(menu) | 75 self.add_centered(menu) |
76 | |
59 self.inventory = InventoryView() | 77 self.inventory = InventoryView() |
60 self.inventory.bottomleft = self.bottomleft | 78 self.inventory.bottomleft = self.bottomleft |
61 self.add(self.inventory) | 79 self.add(self.inventory) |
62 # TODO: Randomly plonk the state here for now | |
63 self.state = initial_state() | |
64 | 80 |
65 def main_menu(self): | 81 def main_menu(self): |
66 print 'Returning to menu' | 82 print 'Returning to menu' |
67 self.shell.show_screen(self.shell.menu_screen) | 83 self.shell.show_screen(self.shell.menu_screen) |
68 | 84 |