Return to repo list

tzed

Simple story-driven open world 2D CRPG.
Return to HMagellan.com

commit 943b7d2254d151597bf1291c58f3dd8db85723ea
parent d90a5049c9799f1c218f789a84646d9fb56118a6
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Tue, 15 Jun 2021 20:20:23 -0500

different scales for ovw v loc

Diffstat:
Msrc/board.py | 6++++--
Msrc/camera.py | 10++++++----
Msrc/envvars.py | 3++-
Msrc/game.py | 5+++--
4 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/board.py b/src/board.py @@ -42,10 +42,11 @@ class BoardManager(manager.Manager): """ w = self.current_board.tmx_data.tilewidth h = self.current_board.tmx_data.tileheight + sf = self.system_bus.fetch("camera", "scale_factor") for layer in self.current_board.tmx_data.visible_layers: if isinstance(layer, pytmx.TiledTileLayer): for x, y, gid in layer: - if pos[0] >= x * w * TILE_SCALE_FACTOR and pos[0] < (x + 1) * w * TILE_SCALE_FACTOR and pos[1] >= y * w * TILE_SCALE_FACTOR and pos[1] < (y + 1) * w * TILE_SCALE_FACTOR: + if pos[0] >= x * w * sf and pos[0] < (x + 1) * w * sf and pos[1] >= y * w * sf and pos[1] < (y + 1) * w * sf: return (x, y) return None @@ -56,10 +57,11 @@ class BoardManager(manager.Manager): """ w = self.current_board.tmx_data.tilewidth h = self.current_board.tmx_data.tileheight + sf = self.system_bus.fetch("camera", "scale_factor") for layer in self.current_board.tmx_data.visible_layers: if isinstance(layer, pytmx.TiledTileLayer): for x, y, gid in layer: - if pos[0] >= x * w * TILE_SCALE_FACTOR and pos[0] < (x + 1) * w * TILE_SCALE_FACTOR and pos[1] >= y * w * TILE_SCALE_FACTOR and pos[1] < (y + 1) * w * TILE_SCALE_FACTOR: + if pos[0] >= x * w * sf and pos[0] < (x + 1) * w * sf and pos[1] >= y * w * sf and pos[1] < (y + 1) * w * sf: return (x, y, gid) return None diff --git a/src/camera.py b/src/camera.py @@ -32,6 +32,7 @@ class GameCamera(subsystem.GameSubsystem): self.camera_surface_offset = (0, 0) # The rect topleft is never changed; rather, this value is used by game to draw the camera surface at an offset self.camera_surface_base_dimensions = (0, 0) self.follow = False + self.scale_factor = 1 # Viewport vals self.viewport_rect = self.camera_surface.get_rect() @@ -41,7 +42,7 @@ class GameCamera(subsystem.GameSubsystem): if self.bus != None: self.bus.record(self.name, self) - def load_camera_surface(self, dimensions, follow = False, init_offset = (0, 0)): + def load_camera_surface(self, dimensions, scale_factor, follow = False, init_offset = (0, 0)): """ Load up the camera surface as a new PyGame surface object of the necessary size. Also @@ -54,6 +55,7 @@ class GameCamera(subsystem.GameSubsystem): self.follow = follow self.viewport_rect = self.camera_surface.get_rect() self.viewport_rect.topleft = (0, 0) + self.scale_factor = scale_factor def move_offset(self, rel_offset, speed_multiple = 1): """ @@ -91,7 +93,6 @@ class GameCamera(subsystem.GameSubsystem): is false. """ if force or self.follow: - #self.snap_to_position((entity.rect.center[0] * TILE_SCALE_FACTOR, entity.rect.center[1] * TILE_SCALE_FACTOR)) self.viewport_rect.center = entity.rect.center def update_camera(self, surface = None): @@ -101,8 +102,8 @@ class GameCamera(subsystem.GameSubsystem): self.update_fetch_data() if surface != None: # NOTE: The way I have done the below surface blit is probably really bad. Excuse me. - surface.blit(pygame.transform.scale(self.camera_surface, (self.camera_surface_base_dimensions[0] * TILE_SCALE_FACTOR, self.camera_surface_base_dimensions[1] * TILE_SCALE_FACTOR)), (-SCREEN_WIDTH * 0.9, -SCREEN_HEIGHT * 0.9)) - self.camera_surface.fill((0, 0, 0)) + surface.blit(pygame.transform.scale(self.camera_surface, (self.camera_surface_base_dimensions[0] * self.scale_factor, self.camera_surface_base_dimensions[1] * self.scale_factor)), (-SCREEN_WIDTH * 0.9, -SCREEN_HEIGHT * 0.9)) + self.camera_surface.fill((33, 33, 33)) def update_fetch_data(self): """ @@ -112,3 +113,4 @@ class GameCamera(subsystem.GameSubsystem): self.fetch_data["camera_surface_rect"] = self.camera_surface_rect self.fetch_data["camera_surface_offset"] = self.camera_surface_offset self.fetch_data["viewport_rect"] = self.viewport_rect + self.fetch_data["scale_factor"] = self.scale_factor diff --git a/src/envvars.py b/src/envvars.py @@ -22,7 +22,8 @@ OVERWORLD_BOARD = "test_ow" # Tile settings BASE_TILE_WIDTH = 16 BASE_TILE_HEIGHT = 16 -TILE_SCALE_FACTOR = 4 +LOCATION_SCALE_FACTOR = 4 +OVERWORLD_SCALE_FACTOR = 2 VIEWPORT_SIZE = (640, 480) COLORKEY = (255, 0, 255) diff --git a/src/game.py b/src/game.py @@ -37,6 +37,7 @@ class Game(object): self.sound_system = sound.SoundSystem(self, "sound_system", self.subsystem_bus) self.sheet_system = images.SheetSystem(self, "sheet_system", self.subsystem_bus) self.interface = interface.GameInterface(self, "interface", self.subsystem_bus, self.manager_bus) + # Managers self.board_manager = board.BoardManager(self, "board_manager", self.manager_bus, self.subsystem_bus) self.menu_manager = menu.MenuManager(self, "menu_manager", self.manager_bus, self.subsystem_bus) @@ -69,12 +70,12 @@ class Game(object): # State-specific logic if new_mode == STATE_MODES.Location_Mode: self.board_manager.load_board(data["boardname"]) - self.camera.load_camera_surface(VIEWPORT_SIZE, True) + self.camera.load_camera_surface(VIEWPORT_SIZE, LOCATION_SCALE_FACTOR, True) self.entity_manager.load_board_entities_from_file(data["boardname"]) self.entity_manager.load_board_overlay_from_file(data["boardname"]) elif new_mode == STATE_MODES.Overworld_Mode: self.board_manager.load_board(OVERWORLD_BOARD) - self.camera.load_camera_surface(VIEWPORT_SIZE, True) + self.camera.load_camera_surface((VIEWPORT_SIZE[0] * 2, VIEWPORT_SIZE[1] * 2), OVERWORLD_SCALE_FACTOR, True) self.entity_manager.load_board_entities_from_file(OVERWORLD_BOARD) if "overworld_tile_pos" in data.keys(): self.entity_manager.place_player_on_overworld(data["overworld_tile_pos"])