annotate gamelib/gamescreen.py @ 28:0f25f7b9b37a

Add loading of initial state.
author Simon Cross <hodgestar+bzr@gmail.com>
date Sun, 22 Aug 2010 18:48:32 +0200
parents 5c7bbbdf9296
children 6322d92dc8f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
1 # menu.py
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
2 # Copyright Boomslang team, 2010 (see COPYING File)
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
3 # Main menu for the game
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
4
28
0f25f7b9b37a Add loading of initial state.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 27
diff changeset
5 from state import initial_state
0f25f7b9b37a Add loading of initial state.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 27
diff changeset
6
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
7 from pygame.color import Color
24
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
8 from albow.screen import Screen
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
9 from albow.controls import Button, Label
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
10 from albow.layout import Column
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
11 from albow.palette_view import PaletteView
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
12
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
13
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
14 class InventoryView(PaletteView):
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
15
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
16 info = ["red", "green", "blue", "cyan", "magenta", "yellow"]
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
17
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
18 sel_color = Color("white")
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
19 sel_width = 2
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
20
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
21 def __init__(self):
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
22 PaletteView.__init__(self, (50, 50), 1, 6, scrolling=True)
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
23 self.selection = None
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
24
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
25 def num_items(self):
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
26 return len(self.info)
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
27
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
28 def draw_item(self, surface, item_no, rect):
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
29 d = -2 * self.sel_width
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
30 r = rect.inflate(d, d)
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
31 color = Color(self.info[item_no])
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
32 surface.fill(color, r)
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
33
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
34 def click_item(self, item_no, event):
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
35 self.selection = item_no
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
36
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
37 def item_is_selected(self, item_no):
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
38 return self.selection == item_no
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
39
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
40 def add_item(self, colstr):
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
41 self.info.append(colstr)
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
42
24
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
43
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
44 class GameScreen(Screen):
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
45 def __init__(self, shell):
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
46 Screen.__init__(self, shell)
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
47 self.shell = shell
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
48 StartButton = Button('Main Menu', action = self.main_menu)
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
49 QuitButton = Button('Quit', action = shell.quit)
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
50 AddItemButton = Button('Add item', action = self.add_item)
24
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
51 Title = Label('Caught! ... In SPAACE')
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
52 menu = Column([
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
53 Title,
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
54 StartButton,
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
55 QuitButton,
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
56 AddItemButton,
24
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
57 ], align='l', spacing=20)
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
58 self.add_centered(menu)
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
59 self.inventory = InventoryView()
27
5c7bbbdf9296 Move inventory palette to the bottom left
Neil Muller <neil@dip.sun.ac.za>
parents: 26
diff changeset
60 self.inventory.bottomleft = self.bottomleft
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
61 self.add(self.inventory)
28
0f25f7b9b37a Add loading of initial state.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 27
diff changeset
62 # TODO: Randomly plonk the state here for now
0f25f7b9b37a Add loading of initial state.
Simon Cross <hodgestar+bzr@gmail.com>
parents: 27
diff changeset
63 self.state = initial_state()
24
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
64
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
65 def main_menu(self):
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
66 print 'Returning to menu'
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
67 self.shell.show_screen(self.shell.menu_screen)
9d5de13e2ac3 Add a game screen. So far, the game content looks a *lot* like the main menu.
Jeremy Thurgood <firxen@gmail.com>
parents:
diff changeset
68
26
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
69 def add_item(self):
0a68d137f509 Initial inventory palette thing.
Jeremy Thurgood <firxen@gmail.com>
parents: 24
diff changeset
70 self.inventory.add_item("white")