Return to repo list

heart-of-gold

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

commit 0e3b34b5cbf9fda75fb4c0156f9ea2b0496066c1
parent e54d9d81ded6f2f6230be3d082bfafdefa95d916
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Wed, 28 Oct 2020 15:16:35 -0500

Fixed error where you could interact with a moving unit

Diffstat:
Mdata/json/stats/jisella_1.json | 2+-
Msrc/constants.py | 4++++
Msrc/game.py | 34++++++++++++++++++++++++++++++----
Msrc/subsystem.py | 11+++++------
Msrc/vgo.py | 2+-
5 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/data/json/stats/jisella_1.json b/data/json/stats/jisella_1.json @@ -15,7 +15,7 @@ "INT_GR" : 90, "WIS" : 30, "WIS_GR" : 90, - "MOVE" : 4, + "MOVE" : 8, "CRIT" : 10, "SKIL" : 4, "RANK" : 1, diff --git a/src/constants.py b/src/constants.py @@ -23,6 +23,10 @@ TILE_WIDTH = 64 TILE_HEIGHT = 64 COLORKEY = (255, 0, 255) +# Other constants +PIECE_MOVE_SPEED = 2 +PIECE_MOVE_DELAY = PIECE_MOVE_SPEED * 3 + # File paths DATA_PATH = os.path.join(os.getcwd(), "data") IMAGE_PATH = os.path.join(DATA_PATH, "img") diff --git a/src/game.py b/src/game.py @@ -28,6 +28,8 @@ class Game(object): self.screen_dimensions = (SCREEN_WIDTH, SCREEN_HEIGHT) self.framerate = FRAMERATE self.on = True + self.no_control_timer = 0 + self.return_control_mode = None # PyGame objects self.screen = pygame.display.set_mode(self.screen_dimensions) @@ -66,7 +68,10 @@ class Game(object): game. Such data has no reason to exists e.g. as a JSON file. """ - self.state_mode = new_mode + if new_mode == None: + return + else: + self.state_mode = new_mode if new_mode == STATE_MODES.Main_Menu_Mode: self.control_mode = CTRL_MODES.Main_Menu_Normal @@ -86,6 +91,17 @@ class Game(object): # TODO: Generic-ify self.scene_manager.load_still_scene_from_file("testscene.json") + def lose_control(self, time = -1, followup_mode = None): + """ + Switch to no-control mode for a set period of time. + """ + if followup_mode != None: + self.return_control_mode = followup_mode + else: + self.return_control_mode = self.control_mode + self.control_mode = CTRL_MODES.No_Control + self.no_control_timer = time + def shift_frames(self): """ Shift to the next frame using the PyGame Clock object. @@ -93,9 +109,10 @@ class Game(object): """ self.frame_clock.tick(self.framerate) - def update_screen(self): + def update_game(self): """ - Update the entire game screen. + Update the entire game (screen, subsystems, internal + values, etc.). """ # First, fill the entire screen with black @@ -105,6 +122,7 @@ class Game(object): # TODO: This is WIP and will change self.interface.update_interface() + # State_Mode-specific actions (can be further subdivided by Control_Mode) if self.state_mode == STATE_MODES.Main_Menu_Mode: self.menu_manager.update_current_menu(self.screen) elif self.state_mode == STATE_MODES.Battle_Mode: @@ -117,6 +135,14 @@ class Game(object): elif self.state_mode == STATE_MODES.Still_Scene_Mode: self.scene_manager.update_scene(self.screen) + # State_Mode agnostic, Control_Mode specific actions + if self.control_mode == CTRL_MODES.No_Control: + if self.no_control_timer > 0: + self.no_control_timer -= 1 + elif self.no_control_timer == 0: + self.control_mode = self.return_control_mode + self.return_control_mode = None + # Last, update the screen pygame.display.update() @@ -139,7 +165,7 @@ class Game(object): while self.on: self.shift_frames() self.interface.handle_events(pygame.event.get()) - self.update_screen() + self.update_game() # When we turn off, cleanup and end pygame.quit() diff --git a/src/subsystem.py b/src/subsystem.py @@ -78,6 +78,7 @@ class GameInterface(GameSubsystem): """ React to a mousebutton being clicked. """ + # TODO: ManagerBus will have a field day here... if event.button == 1: if self.game.state_mode == STATE_MODES.Main_Menu_Mode: if self.game.control_mode == CTRL_MODES.Main_Menu_Normal: @@ -87,12 +88,10 @@ class GameInterface(GameSubsystem): if self.game.entity_manager.select_entities_with_tile_cursor(self.game.board_manager.get_tile_at_position(pygame.mouse.get_pos())): self.game.control_mode = CTRL_MODES.Turn_Select_Move elif self.game.control_mode == CTRL_MODES.Turn_Select_Move: - #if self.game.entity_manager.set_entity_move_to_tile_pos(self.game.entity_manager.selected_entity, self.game.board_manager.get_overlay_move_vgo_at_pos(pygame.mouse.get_pos())): - # self.game.control_mode = CTRL_MODES.Turn_Normal - # # TODO: Should this really be done here??? - # self.game.board_manager.load_overlay() - if self.game.entity_manager.set_entity_move_to_tile_path(self.game.entity_manager.selected_entity, self.game.board_manager.get_path_by_previous_moves(self.game.entity_manager.selected_entity.tile_pos, self.game.board_manager.get_tile_pos_at_position(pygame.mouse.get_pos()))): - self.game.control_mode = CTRL_MODES.Turn_Normal + to_path = self.game.board_manager.get_path_by_previous_moves(self.game.entity_manager.selected_entity.tile_pos, self.game.board_manager.get_tile_pos_at_position(pygame.mouse.get_pos())) + if self.game.entity_manager.set_entity_move_to_tile_path(self.game.entity_manager.selected_entity, to_path): + # TODO: The length of time shouldn't have magic numbers. Neither should unit visual movement speed. + self.game.lose_control(len(to_path) * PIECE_MOVE_DELAY, CTRL_MODES.Turn_Normal) self.game.board_manager.load_overlay() elif self.game.state_mode == STATE_MODES.Still_Scene_Mode: if self.game.control_mode == CTRL_MODES.Still_Scene_Normal: diff --git a/src/vgo.py b/src/vgo.py @@ -329,7 +329,7 @@ class Piece(Entity): if self.current_tile_path != None and self.path_moving: if self.motion == {} and self.current_tile_path_index < len(self.current_tile_path): next_tar = (self.current_tile_path[self.current_tile_path_index][0] * TILE_WIDTH, self.current_tile_path[self.current_tile_path_index][1] * TILE_HEIGHT) - self.set_motion(next_tar, 5) + self.set_motion(next_tar, PIECE_MOVE_SPEED) self.current_tile_path_index += 1 elif self.motion == {}: self.tile_pos = self.current_tile_path[self.current_tile_path_index - 1]