Mercurial > boomslang
comparison gamelib/gamescreen.py @ 53:3d460c1274ee
Add button size constant
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Mon, 23 Aug 2010 12:57:06 +0200 |
parents | 7a977f8f433a |
children | 0abd45c58bd3 |
comparison
equal
deleted
inserted
replaced
52:7a977f8f433a | 53:3d460c1274ee |
---|---|
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, Item | 5 from state import initial_state, Item |
6 from hand import HandButton | 6 from hand import HandButton |
7 from constants import BUTTON_SIZE | |
7 | 8 |
8 from pygame.color import Color | 9 from pygame.color import Color |
9 from pygame import Rect | 10 from pygame import Rect |
10 from pygame.locals import BLEND_ADD | 11 from pygame.locals import BLEND_ADD |
11 from albow.screen import Screen | 12 from albow.screen import Screen |
19 | 20 |
20 sel_color = Color("yellow") | 21 sel_color = Color("yellow") |
21 sel_width = 2 | 22 sel_width = 2 |
22 | 23 |
23 def __init__(self, state, handbutton): | 24 def __init__(self, state, handbutton): |
24 PaletteView.__init__(self, (50, 50), 1, 6, scrolling=True) | 25 PaletteView.__init__(self, (BUTTON_SIZE, BUTTON_SIZE), 1, 6, scrolling=True) |
25 self.state = state | 26 self.state = state |
26 self.selection = None | 27 self.selection = None |
27 self.handbutton = handbutton | 28 self.handbutton = handbutton |
28 | 29 |
29 def num_items(self): | 30 def num_items(self): |
45 | 46 |
46 | 47 |
47 class StateWidget(Widget): | 48 class StateWidget(Widget): |
48 | 49 |
49 def __init__(self, state): | 50 def __init__(self, state): |
50 Widget.__init__(self, Rect(0, 0, 800, 550)) | 51 Widget.__init__(self, Rect(0, 0, 800, 600 - BUTTON_SIZE)) |
51 self.state = state | 52 self.state = state |
52 | 53 |
53 def draw(self, surface): | 54 def draw(self, surface): |
54 self.state.draw(surface) | 55 self.state.draw(surface) |
55 | 56 |
77 Button('Use titanium_leg', action = lambda: self.state.scenes['cryo'].things['cryo.door'].interact(self.state.items['titanium_leg'])), | 78 Button('Use titanium_leg', action = lambda: self.state.scenes['cryo'].things['cryo.door'].interact(self.state.items['titanium_leg'])), |
78 ], align='l', spacing=20) | 79 ], align='l', spacing=20) |
79 self.add_centered(menu) | 80 self.add_centered(menu) |
80 self.menubutton = Button('Menu', action=self.main_menu) | 81 self.menubutton = Button('Menu', action=self.main_menu) |
81 self.menubutton.font = get_font(16, 'Vera.ttf') | 82 self.menubutton.font = get_font(16, 'Vera.ttf') |
82 self.menubutton.set_rect(Rect(0, 0, 50, 50)) | 83 self.menubutton.set_rect(Rect(0, 0, BUTTON_SIZE, BUTTON_SIZE)) |
83 self.menubutton.bottomleft = self.bottomleft | 84 self.menubutton.bottomleft = self.bottomleft |
84 self.menubutton.margin = (50 - self.menubutton.font.get_linesize()) / 2 | 85 self.menubutton.margin = (BUTTON_SIZE - self.menubutton.font.get_linesize()) / 2 |
85 self.add(self.menubutton) | 86 self.add(self.menubutton) |
86 self.handbutton = HandButton(action=self.hand_pressed) | 87 self.handbutton = HandButton(action=self.hand_pressed) |
87 self.handbutton.bottomleft = self.bottomleft | 88 self.handbutton.bottomleft = self.bottomleft |
88 self.handbutton.get_rect().move_ip(50, 0) | 89 self.handbutton.get_rect().move_ip(BUTTON_SIZE, 0) |
89 self.add(self.handbutton) | 90 self.add(self.handbutton) |
90 self.inventory = InventoryView(self.state, self.handbutton) | 91 self.inventory = InventoryView(self.state, self.handbutton) |
91 | 92 |
92 self.inventory.bottomleft = self.bottomleft | 93 self.inventory.bottomleft = self.bottomleft |
93 self.inventory.get_rect().move_ip(100, 0) | 94 self.inventory.get_rect().move_ip(2 * BUTTON_SIZE, 0) |
94 self.add(self.inventory) | 95 self.add(self.inventory) |
95 | 96 |
96 # Test items | 97 # Test items |
97 self.state.add_inventory_item('triangle') | 98 self.state.add_inventory_item('triangle') |
98 self.state.add_inventory_item('titanium_leg') | 99 self.state.add_inventory_item('titanium_leg') |