Beispiel #1
0
    def __init__(self, map, *args, **kwargs):
        super(GameWindow, self).__init__(MAP_DISPLAY_WIDTH + UI_PANEL_WIDTH, MAP_DISPLAY_HEIGHT, *args, **kwargs)
        self.map = map
        self.turn = 1

        self.__initializeUI()

        self.map_display = MapDisplay(map)
        self.display_panel = DisplayPanel()

        pyglet.clock.schedule_interval(self.update, 1 / 45.0)

        # tracks the current position of the mouse,
        # updated on_mouse_motion
        self.mouse_pos = None
Beispiel #2
0
class GameWindow(pyglet.window.Window):
    def __init__(self, map, *args, **kwargs):
        super(GameWindow, self).__init__(MAP_DISPLAY_WIDTH + UI_PANEL_WIDTH, MAP_DISPLAY_HEIGHT, *args, **kwargs)
        self.map = map
        self.turn = 1

        self.__initializeUI()

        self.map_display = MapDisplay(map)
        self.display_panel = DisplayPanel()

        pyglet.clock.schedule_interval(self.update, 1 / 45.0)

        # tracks the current position of the mouse,
        # updated on_mouse_motion
        self.mouse_pos = None

    def on_draw(self):
        self.clear()

        self.map_display.batch.draw()
        self.map_display.drawPaths()

        self.display_panel.draw()
        if self._show_fps:
            self.fps_display.draw()

    def update(self, dt):
        if self.map_display.scroll():
            active_tile = self.map_display.updateActiveTile(self.mouse_pos[0], self.mouse_pos[1])
            self.display_panel.updateTileLabels(active_tile)

    def on_key_press(self, symbol, modifiers):
        if symbol == key.GRAVE:
            self._show_fps = not self._show_fps
        elif symbol == key.SPACE:
            self.turn += 1
            self.display_panel.updateTurnLabel(self.turn)

            all_units = self.map.allUnits()
            for unit in all_units:
                unit.restoreMoves()
                tiles = self.map.moveUnit(unit)
                self.map_display.moveUnit(unit, tiles[0], tiles[1])

            self.map_display.drawNewTurn()

    def on_mouse_press(self, x, y, button, modifiers):
        if button == mouse.LEFT:
            self.map_display.pathFromSelectedToActiveTile()

        elif button == mouse.RIGHT:
            self.map_display.deselectUnitTile()
            self.display_panel.updateTileLabels(self.map_display.active_tile)

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        self.on_mouse_motion(x, y, dx, dy)

        if buttons & mouse.LEFT:
            self.map_display.dragPathFromSelectedToActiveTile()

    def on_mouse_release(self, x, y, button, modifiers):
        if button == mouse.LEFT:
            self.map_display.selectUnitOrDestination(x, y)

    def on_mouse_motion(self, x, y, dx, dy):
        self.mouse_pos = [x, y]
        self.map_display.updateActiveTile(x, y)

        self.display_panel.updateTileLabels(self.map_display.active_tile)

    def on_mouse_leave(self, x, y):
        self.map_display.stopScroll()

    def __initializeUI(self):
        self.fps_display = pyglet.window.FPSDisplay(self)
        self._show_fps = True