Return to repo list

tzed

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

commit fd47eaf0ff7a1951f98449d0e63b31c44b7bde5b
parent 36c3c710d55d8bb4af3dfdff3bb2b0b36e7d86aa
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Wed,  9 Jun 2021 21:19:38 -0500

now drawing board

Diffstat:
Adata/boards/test_town/test_town.tmx | 20++++++++++++++++++++
Adata/menus/mainmenu.json | 45+++++++++++++++++++++++++++++++++++++++++++++
Adata/tsx/tiles1.tsx | 637+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/board.py | 11+++++------
Msrc/envvars.py | 2+-
Msrc/game.py | 14++++++++++++--
Msrc/interface.py | 6++++--
Asrc/player.py | 29+++++++++++++++++++++++++++++
8 files changed, 753 insertions(+), 11 deletions(-)

diff --git a/data/boards/test_town/test_town.tmx b/data/boards/test_town/test_town.tmx @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="12" height="12" tilewidth="16" tileheight="16" infinite="0" nextlayerid="2" nextobjectid="1"> + <tileset firstgid="1" source="../../tsx/tiles1.tsx"/> + <layer id="1" name="Tile Layer 1" width="12" height="12"> + <data encoding="csv"> +81,81,92,32,51,14,91,11,11,11,11,11, +81,81,92,32,51,14,91,11,11,11,11,11, +73,76,74,32,51,14,117,115,118,115,122,115, +13,51,13,52,51,52,13,13,51,16,1,29, +51,51,51,51,51,51,51,51,51,14,2,2, +31,94,102,95,77,95,93,51,51,14,1,1, +1,91,81,81,81,81,92,32,51,14,1,21, +10,91,81,81,81,81,92,32,51,14,1,5, +27,91,81,81,81,81,92,32,51,14,1,5, +3,91,81,81,81,81,92,32,51,14,1,5, +28,91,81,81,81,81,92,32,51,14,1,19, +1,117,115,122,122,115,116,32,51,14,29,1 +</data> + </layer> +</map> diff --git a/data/menus/mainmenu.json b/data/menus/mainmenu.json @@ -0,0 +1,45 @@ +{ + "name" : "MainMenu", + "bg_sheet" : "mainmenubg", + "bg_sprite" : [0, 0], + "buttons" : { + "NewGame" : { + "sheet" : "mainmenu_buttons_1", + "sprite" : [0, 0], + "pos" : [100, 100], + "intlayer" : 0, + "effects" : [ + { + "call" : "ef_game_switch_mode", + "data" : ["Base_Mode", "testbase1"] + } + ] + }, + "LoadGame" : { + "sheet" : "mainmenu_buttons_1", + "sprite" : [0, 1], + "pos" : [100, 200], + "intlayer" : 0, + "effects" : [ + { + "call" : "ef_game_switch_mode", + "data" : ["Still_Scene_Mode", "scene1.json"] + } + ] + }, + "Options" : { + "sheet" : "mainmenu_buttons_1", + "sprite" : [0, 2], + "pos" : [100, 300], + "intlayer" : 0, + "effects" : [ + { + "call" : "ef_game_quit", + "data" : null + } + ] + } + }, + "entities" : { }, + "sublayouts" : { } +} diff --git a/data/tsx/tiles1.tsx b/data/tsx/tiles1.tsx @@ -0,0 +1,637 @@ +<?xml version="1.0" encoding="UTF-8"?> +<tileset version="1.4" tiledversion="1.4.3" name="tiles1" tilewidth="16" tileheight="16" tilecount="126" columns="18"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + <image source="../img/tiles1.png" width="288" height="112"/> + <tile id="0"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="1"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="2"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="3"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="4"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="5"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="6"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="7"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="8"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="9"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="10"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="11"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="12"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="13"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="14"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="15"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="16"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="17"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="18"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="19"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="20"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="21"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="22"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="23"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="24"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="25"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="26"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="27"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="28"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="29"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="30"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="31"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="32"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="33"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="34"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="35"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="36"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="37"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="38"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="39"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="40"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="41"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="42"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="43"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="44"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="45"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="46"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="47"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="48"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="49"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="50"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="51"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="52"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="53"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="54"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="55"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="56"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="57"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="58"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="59"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="60"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="61"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="62"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="63"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="64"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="65"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="66"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="67"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="68"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="69"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="70"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="71"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="72"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="73"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="74"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="75"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="76"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="77"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="78"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="79"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="80"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="81"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="82"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="83"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="84"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="85"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="86"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="87"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="88"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="89"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="90"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="91"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="92"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="93"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="94"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="95"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="96"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="97"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="98"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="99"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="100"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="101"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="102"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="103"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="104"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="105"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="106"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="107"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="108"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="109"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="110"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="111"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="112"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="113"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="114"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="115"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="116"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="117"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> + <tile id="118"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="119"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="120"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="121"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="122"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="123"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="124"> + <properties> + <property name="Passable" type="bool" value="false"/> + </properties> + </tile> + <tile id="125"> + <properties> + <property name="Passable" type="bool" value="true"/> + </properties> + </tile> +</tileset> diff --git a/src/board.py b/src/board.py @@ -34,7 +34,7 @@ class BoardManager(manager.Manager): """ # TODO: Bring this inline with loading in managers rather than in managed objects self.current_board = Board(self, boardname) - self.load_overlay() + #self.load_overlay() self.update(None) def load_overlay(self): @@ -47,7 +47,7 @@ class BoardManager(manager.Manager): if isinstance(layer, pytmx.TiledTileLayer): for x, y, gid in layer: if self.current_board.tmx_data.get_tile_properties_by_gid(gid)["Passable"] == 1: - e = entity.Entity(self.bus.fetch("sheet_manager", "sheets")["board_overlays_1"]) + e = entity.Entity(self.system_bus.fetch("sheet_system", "sheets")["board_overlays_1"]) e.set_position((x * self.current_board.tmx_data.tilewidth, y * self.current_board.tmx_data.tileheight)) e.custom_flags = "OverlayGrid" self.board_overlay.add(e) @@ -140,7 +140,7 @@ class BoardManager(manager.Manager): """ if surface != None: self.current_board.draw_board(surface) - self.board_overlay.update(surface) + #self.board_overlay.update(surface) ############################ # Section 2 - Board Object # @@ -163,7 +163,7 @@ class Board(object): # Pytmx values self.tmx_data = pytmx.load_pygame(os.path.join(BOARD_PATH, self.boardname, self.filename)) self.board_dimensions = (self.tmx_data.width, self.tmx_data.height) - self.pixel_dimensions = (self.tmx_data.width * TILE_WIDTH, self.tmx_data.height * TILE_HEIGHT) + self.pixel_dimensions = (self.tmx_data.width * BASE_TILE_WIDTH, self.tmx_data.height * BASE_TILE_HEIGHT) def draw_board(self, surface = None): """ @@ -175,5 +175,4 @@ class Board(object): for x, y, gid in layer: t = self.tmx_data.get_tile_image_by_gid(gid) if t: - surface.blit(t, (x * TILE_HEIGHT, y * TILE_WIDTH)) - + surface.blit(t, (x * BASE_TILE_WIDTH, y * BASE_TILE_HEIGHT)) diff --git a/src/envvars.py b/src/envvars.py @@ -41,7 +41,7 @@ METER_STATS = ["HP", "MP"] META_STATS = ["LVL", "EXP", "RNG"] # Enums -STATE_MODES = enum.Enum('STATE_MODES', 'Main_Menu_Mode Overworld_Mode Location_Mode Basic_Battle_Mode Location_Battle_Mode') +STATE_MODES = enum.Enum('STATE_MODES', 'Main_Menu_Mode Overworld_Mode Location_Mode Battle_Mode Dungeon_Mode') CTRL_MODES = enum.Enum('CTRL_MODES', 'No_Control Main_Menu_Normal') GAME_EFFECTS = enum.Enum('GAME_EFFECTS', 'ef_game_dummy ef_game_quit ef_game_switch_mode ef_game_switch_control') TEAMS = enum.Enum('TEAMS', 'Player Ally Neutral Enemy Other') diff --git a/src/game.py b/src/game.py @@ -49,7 +49,7 @@ class Game(object): self.subsystem_bus.update_system_fetch_data() # Switch to game control - self.switch_mode(STATE_MODES.Main_Menu_Mode) + self.switch_mode(STATE_MODES.Location_Mode) def switch_mode(self, new_mode, data = None): """ @@ -66,7 +66,10 @@ class Game(object): else: self.state_mode = new_mode - # TODO: Mode-specific switch logic + # State-specific logic + if new_mode == STATE_MODES.Location_Mode: + self.board_manager.load_board("test_town") + self.camera.load_camera_surface(self.board_manager.current_board.pixel_dimensions) def shift_frames(self, framerate = FRAMERATE): """ @@ -86,6 +89,13 @@ class Game(object): # Next, update the interface self.interface.update_interface() + # Manager updates + if self.state_mode in (STATE_MODES.Overworld_Mode, STATE_MODES.Location_Mode): + self.board_manager.update_managed(self.camera.camera_surface) + + # Draw the camera + self.camera.update_camera(self.screen) + # Last, update the screen pygame.display.update() diff --git a/src/interface.py b/src/interface.py @@ -88,8 +88,9 @@ class GameInterface(subsystem.GameSubsystem): React to a mousebutton being clicked. """ # First, get important mouse positional info, namely unoffset mouse position and camera-offset mouse position + camoff = self.bus.fetch("camera", "camera_surface_offset") mouseraw = pygame.mouse.get_pos() - mousepos = (mouseraw[0] - self.camera.camera_surface_offset[0], mouseraw[1] - self.camera.camera_surface_offset[1]) + mousepos = (mouseraw[0] - camoff[0], mouseraw[1] - camoff[1]) # Handle left-click if event.button == 1: @@ -121,8 +122,9 @@ class GameInterface(subsystem.GameSubsystem): React to a mousebutton being released. """ # First, get important mouse positional info, namely unoffset mouse position and camera-offset mouse position + camoff = self.bus.fetch("camera", "camera_surface_offset") mouseraw = pygame.mouse.get_pos() - mousepos = (mouseraw[0] - self.camera.camera_surface_offset[0], mouseraw[1] - self.camera.camera_surface_offset[1]) + mousepos = (mouseraw[0] - camoff[0], mouseraw[1] - camoff[1]) # Handle left-release if event.button == 1: diff --git a/src/player.py b/src/player.py @@ -0,0 +1,29 @@ +import pygame +from . import entity +from .envvars import * + +############# +# player.py # +############# + +# This file contains: +# 1. The Player class, which represents the character that the player controls in the overworld and in locations + +############################ +# Section 1 - Player class # +############################ + +class Player(entity.Entity): + """ + The Player object is the entity that is controlled + when in Overworld mode or Location mode. The Player + can move between tiles and certain commands are + affected by where the Player is located. + """ + + def __init__(self, sheet, sprite = (0, 0), animation = None, animated = False): + + # Parent initialization + super().__init__(sheet, sprite, animation, animated) + + # Important values