Return to repo list

heart-of-gold

Tactical RPG written in python, using pygame.
Return to HMagellan.com

commit 1e11414f7762b53ab7e8ba60060af4b620f9274a
parent 52888a86a3bc8aa4762d549fcb0ef5d9c0b08514
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Fri, 22 Jan 2021 09:06:03 -0600

Cursor now in base mode

Diffstat:
Msrc/base.py | 41++++++++++++++++++++++++++++++++++++++++-
Msrc/bus.py | 4+++-
Msrc/game.py | 6+++++-
Msrc/interface.py | 17+++++++++++++----
4 files changed, 61 insertions(+), 7 deletions(-)

diff --git a/src/base.py b/src/base.py @@ -1,5 +1,5 @@ import pygame -from . import manager, entity +from . import manager, entity, piece from .constants import * ########### @@ -26,3 +26,42 @@ class BaseManager(manager.Manager): # Parent initialization super().__init__(game, bus, camera, name) + + # Vals + self.base_entities = pygame.sprite.LayeredDirty() + self.tile_cursor = None + + def load_base_from_file(self, filename): + """ + Load the base from a given definition JSON. + """ + pass + + def load_ui_elements(self): + """ + Load the UI elemenst of the BaseManager. + """ + try: + sh = self.bus.fetch("sheet_manager", "sheets") + except ManagerBusError: + return + + self.tile_cursor = piece.TileCursor(sh["cursor1"], (0, 0), sh["cursor1"].animations["pulse"], True) + + def position_tile_cursor(self, tile_pos): + """ + Snap the TileCursor object's position to 'tile_pos' + and set the tile GID there as the current tile_cursor's + selected tile. + """ + self.tile_cursor.assign_tile(tile_pos, self.bus.fetch("board_manager", "board_tile_layer")[tile_pos]) + self.tile_cursor.snap_to_tile() + + def update_managed(self, surface = None): + """ + Update the base entities. + """ + if surface != None: + if self.game.control_mode == CTRL_MODES.Base_Normal: + self.tile_cursor.update(surface) + self.base_entities.update(surface) diff --git a/src/bus.py b/src/bus.py @@ -109,7 +109,7 @@ class ManagerBus(subsystem.GameSubsystem): self.game.menu_manager.trigger_button_at_pos(pos) def perform_select_piece_with_tile_cursor(self): self.game.piece_manager.select_piece_with_tile_cursor() - def perform_position_tile_cursor(self, tile_pos): + def perform_piece_manager_position_tile_cursor(self, tile_pos): self.game.piece_manager.position_tile_cursor(tile_pos) def perform_set_piece_move_along_tile_path(self, piece, path): self.game.piece_manager.set_piece_move_to_tile_path(piece, path) @@ -119,6 +119,8 @@ class ManagerBus(subsystem.GameSubsystem): self.game.piece_manager.execute_guard(piece) def perform_piece_manager_kill_piece(self, piece): self.game.piece_manager.kill_piece(piece) + def perform_base_manager_position_tile_cursor(self, tile_pos): + self.game.base_manager.position_tile_cursor(tile_pos) def perform_scene_manager_load_scene_from_file(self, scenefile): self.game.scene_manager.load_still_scene_from_file(scenefile) def perform_continue_current_scene_script(self): diff --git a/src/game.py b/src/game.py @@ -1,5 +1,5 @@ import pygame -from . import subsystem, bus, camera, interface, manager, images, sound, board, entity, piece, turn, menu, scene +from . import subsystem, bus, camera, interface, manager, images, sound, board, entity, piece, turn, menu, scene, base from .constants import * ########### @@ -54,6 +54,7 @@ class Game(object): self.menu_manager = menu.MenuManager(self, self.manager_bus, self.camera, "menu_manager") self.board_manager = board.BoardManager(self, self.manager_bus, self.camera, "board_manager") self.piece_manager = piece.PieceManager(self, self.manager_bus, self.camera, "piece_manager") + self.base_manager = base.BaseManager(self, self.manager_bus, self.camera, "base_manager") self.scene_manager = scene.SceneManager(self, self.manager_bus, self.camera, "scene_manager") self.turn_manager = turn.TurnManager(self, self.manager_bus, self.camera, "turn_manager") @@ -87,6 +88,8 @@ class Game(object): elif new_mode == STATE_MODES.Base_Mode: self.control_mode = CTRL_MODES.Base_Normal self.board_manager.load_board(data) + self.base_manager.load_base_from_file(data) + self.base_manager.load_ui_elements() self.camera.load_camera_surface(self.board_manager.current_board.pixel_dimensions) elif new_mode == STATE_MODES.Battle_Mode: self.control_mode = CTRL_MODES.Turn_Normal @@ -145,6 +148,7 @@ class Game(object): self.camera.update_camera(self.screen) elif self.state_mode == STATE_MODES.Base_Mode: self.board_manager.update(self.camera.camera_surface) + self.base_manager.update(self.camera.camera_surface) self.camera.update_camera(self.screen) elif self.state_mode == STATE_MODES.Battle_Mode: self.board_manager.update(self.camera.camera_surface) diff --git a/src/interface.py b/src/interface.py @@ -187,6 +187,9 @@ class GameInterface(subsystem.GameSubsystem): per frame. This is not the same as a drawing update for e.g. an Entity, and is logic-only. """ + mouseraw = pygame.mouse.get_pos() + mousepos = (mouseraw[0] - self.camera.camera_surface_offset[0], mouseraw[1] - self.camera.camera_surface_offset[1]) + # UNIVERSAL UPDATES # Doubleclick countdown if self.double_click_timer > 0: @@ -194,11 +197,17 @@ class GameInterface(subsystem.GameSubsystem): else: self.double_clicking = False + # BASE MODE ONLY UPDATES + # Update tile cursor + if self.game.state_mode == STATE_MODES.Base_Mode: + tilepos = self.bus.check_for_tile_by_screen_pos(mousepos) + + if tilepos != None: + self.bus.perform_base_manager_position_tile_cursor((tilepos[0], tilepos[1])) + # BATTLE MODE ONLY UPDATES # Update mouse position - if self.game.state_mode == STATE_MODES.Battle_Mode: - mouseraw = pygame.mouse.get_pos() - mousepos = (mouseraw[0] - self.camera.camera_surface_offset[0], mouseraw[1] - self.camera.camera_surface_offset[1]) + elif self.game.state_mode == STATE_MODES.Battle_Mode: tilepos = self.bus.check_for_tile_by_screen_pos(mousepos) # Drag facing @@ -226,7 +235,7 @@ class GameInterface(subsystem.GameSubsystem): # Position cursor if tilepos != None: - self.bus.perform_position_tile_cursor((tilepos[0], tilepos[1])) + self.bus.perform_piece_manager_position_tile_cursor((tilepos[0], tilepos[1])) # Watching a move complete elif self.game.control_mode == CTRL_MODES.Turn_Watch_Move: