comparison gamelib/gamescreen.py @ 34:e5c043aeed65

Inventory and items. And stuff.
author Jeremy Thurgood <firxen@gmail.com>
date Sun, 22 Aug 2010 19:59:42 +0200
parents 6322d92dc8f0
children ebc76bc0c067
comparison
equal deleted inserted replaced
33:f8e02d02c782 34:e5c043aeed65
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 state import initial_state 5 from state import initial_state, Item
6 6
7 from pygame.color import Color 7 from pygame.color import Color
8 from pygame import Rect 8 from pygame import Rect
9 from albow.screen import Screen 9 from albow.screen import Screen
10 from albow.controls import Button, Label, Widget 10 from albow.controls import Button, Label, Widget
12 from albow.palette_view import PaletteView 12 from albow.palette_view import PaletteView
13 13
14 14
15 class InventoryView(PaletteView): 15 class InventoryView(PaletteView):
16 16
17 info = ["red", "green", "blue", "cyan", "magenta", "yellow"]
18
19 sel_color = Color("white") 17 sel_color = Color("white")
20 sel_width = 2 18 sel_width = 2
21 19
22 def __init__(self): 20 def __init__(self, state):
23 PaletteView.__init__(self, (50, 50), 1, 6, scrolling=True) 21 PaletteView.__init__(self, (50, 50), 1, 6, scrolling=True)
22 self.state = state
24 self.selection = None 23 self.selection = None
25 24
26 def num_items(self): 25 def num_items(self):
27 return len(self.info) 26 return len(self.state.inventory)
28 27
29 def draw_item(self, surface, item_no, rect): 28 def draw_item(self, surface, item_no, rect):
30 d = -2 * self.sel_width 29 d = -2 * self.sel_width
31 r = rect.inflate(d, d) 30 r = rect.inflate(d, d)
32 color = Color(self.info[item_no]) 31 surface.blit(self.state.inventory[item_no].get_inventory_image(), r, None, BLEND_ADD)
33 surface.fill(color, r)
34 32
35 def click_item(self, item_no, event): 33 def click_item(self, item_no, event):
36 self.selection = item_no 34 self.selection = item_no
37 35
38 def item_is_selected(self, item_no): 36 def item_is_selected(self, item_no):
39 return self.selection == item_no 37 return self.selection == item_no
40 38
41 def add_item(self, colstr): 39 def add_item(self, item):
42 self.info.append(colstr) 40 self.info.append(item)
41
42 def remove_item(self, item):
43 self.info.remove(item)
43 44
44 45
45 class StateWidget(Widget): 46 class StateWidget(Widget):
46 47
47 def __init__(self, state): 48 def __init__(self, state):
53 54
54 55
55 class GameScreen(Screen): 56 class GameScreen(Screen):
56 def __init__(self, shell): 57 def __init__(self, shell):
57 Screen.__init__(self, shell) 58 Screen.__init__(self, shell)
58 self.shell = shell
59 59
60 # TODO: Randomly plonk the state here for now 60 # TODO: Randomly plonk the state here for now
61 self.state = initial_state() 61 self.state = initial_state()
62 self.state_widget = StateWidget(self.state) 62 self.state_widget = StateWidget(self.state)
63 self.add(self.state_widget) 63 self.add(self.state_widget)
72 QuitButton, 72 QuitButton,
73 AddItemButton, 73 AddItemButton,
74 ], align='l', spacing=20) 74 ], align='l', spacing=20)
75 self.add_centered(menu) 75 self.add_centered(menu)
76 76
77 self.inventory = InventoryView() 77 self.inventory = InventoryView(self.state)
78 self.inventory.bottomleft = self.bottomleft 78 self.inventory.bottomleft = self.bottomleft
79 self.add(self.inventory) 79 self.add(self.inventory)
80
81 # Test items
82 self.state.add_inventory_item('triangle')
83 self.state.add_inventory_item('square')
80 84
81 def main_menu(self): 85 def main_menu(self):
82 print 'Returning to menu' 86 print 'Returning to menu'
83 self.shell.show_screen(self.shell.menu_screen) 87 self.shell.show_screen(self.shell.menu_screen)
84 88