Changeset 17:cbbc5da7708a


Ignore:
Timestamp:
Aug 30, 2009, 5:15:23 PM (11 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@18
Message:

Interaction with the game board.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gamelib/gameboard.py

    r14 r17  
    22
    33from pgu import gui, tilevid
     4from pygame.locals import MOUSEBUTTONDOWN
    45
    56import data
     
    89class GameBoard(object):
    910    TILE_DIMENSIONS = (20, 20)
     11    TOOLBAR_WIDTH = 22
    1012
    1113    def __init__(self):
     
    1618        self.tools = tilevid.Tilevid()
    1719        self.tools.tga_load_tiles(data.filepath('tiles.tga'), self.TILE_DIMENSIONS)
    18         self.tools.resize((1, 2))
    1920        self.populate_toolbar()
    2021
     22        self.selected_tool = None
     23
    2124    def populate_toolbar(self):
     25        self.tools.resize((1, 2))
    2226        self.tools.set((0,0), 2)
    2327        self.tools.set((0,1), 3)
     
    2529    def split_screen(self, screen):
    2630        leftbar_rect = screen.get_rect()
    27         leftbar_rect.width = self.TILE_DIMENSIONS[0] + 2
     31        leftbar_rect.width = self.TOOLBAR_WIDTH
    2832        main_rect = screen.get_rect()
    2933        main_rect.width -= leftbar_rect.width
     
    4852
    4953    def loop(self):
     54        return
    5055        x = random.randint(0, self.tv.size[0]-1)
    5156        y = random.randint(0, self.tv.size[1]-1)
     
    5358        self.tv.set((x, y), tile)
    5459
     60    def select_tool(self, e):
     61        tool_pos = self.tools.screen_to_tile(e.pos)
     62        if tool_pos[1] < 2:
     63            self.selected_tool = self.tools.get(tool_pos)
     64        else:
     65            self.selected_tool = None
     66
     67    def use_tool(self, e):
     68        if self.selected_tool is None:
     69            return
     70        pos = self.tv.screen_to_tile((e.pos[0] - self.TOOLBAR_WIDTH, e.pos[1]))
     71        self.tv.set(pos, self.selected_tool)
     72
    5573    def event(self, e):
    56         pass
     74        if e.type == MOUSEBUTTONDOWN:
     75            if e.pos[0] < self.TOOLBAR_WIDTH:
     76                self.select_tool(e)
     77            else:
     78                self.use_tool(e)
Note: See TracChangeset for help on using the changeset viewer.