Basic link established between scene and game

This commit is contained in:
duckduckdoof 2025-02-05 16:39:33 -05:00
parent 455f392965
commit d0e9beddba
5 changed files with 25 additions and 13 deletions

View file

@ -9,8 +9,10 @@ visual elements; this is handles in the scene/ python files
# IMPORTS ----------------------------------------------------------- # IMPORTS -----------------------------------------------------------
from global_config import *
from lib.engine.game_config import * from lib.engine.game_config import *
from lib.engine.game_board import LayeredFlatWorld from lib.engine.game_board import LayeredFlatWorld
from lib.engine.game_objects import str_to_game_object
# FUNCTIONS --------------------------------------------------------- # FUNCTIONS ---------------------------------------------------------
@ -19,7 +21,13 @@ def init_gb_from_scene_info(scene_info: dict):
Takes a dictionary of 2D arrays (organized by layer name), and Takes a dictionary of 2D arrays (organized by layer name), and
converts them into their proper game board of game objects. converts them into their proper game board of game objects.
""" """
board_layers = {}
for layer in scene_info.keys():
board_layers[layer] = [[None] * BOARD_HEIGHT for _ in range(BOARD_WIDTH)]
for i in range(BOARD_WIDTH):
for j in range(BOARD_HEIGHT):
board_layers[layer][i][j] = str_to_game_object(scene_info[layer][i][j])
return board_layers
# CLASSES ----------------------------------------------------------- # CLASSES -----------------------------------------------------------

View file

@ -12,7 +12,7 @@ interpreting player inputs on the screen, etc.
from arcade import Scene from arcade import Scene
from scene_config import * from lib.scene.scene_config import *
from global_config import * from global_config import *
# FUNCTIONS --------------------------------------------------------- # FUNCTIONS ---------------------------------------------------------
@ -31,6 +31,6 @@ def info_from_layered_tilemap(scene: Scene):
scene_info[layer] = [[""] * BOARD_HEIGHT for _ in range(BOARD_WIDTH)] scene_info[layer] = [[""] * BOARD_HEIGHT for _ in range(BOARD_WIDTH)]
# Populate the layer info as 2D arrays # Populate the layer info as 2D arrays
for i, S in enumerate(scene[layer]): for i, sprite in enumerate(scene[layer]):
scene_info[layer][i//BOARD_WIDTH][i%BOARD_HEIGHT] = scene[layer].properties[TILE_NAME] scene_info[layer][i//BOARD_WIDTH][i%BOARD_HEIGHT] = sprite.properties[TILE_NAME]
return scene_info return scene_info

View file

@ -56,7 +56,7 @@
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"height":20, "height":20,
"id":12, "id":12,
"name":"Foundation", "name":"Foundations",
"opacity":1, "opacity":1,
"type":"tilelayer", "type":"tilelayer",
"visible":true, "visible":true,

View file

@ -29,7 +29,7 @@
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
</data> </data>
</layer> </layer>
<layer id="12" name="Foundation" width="30" height="20"> <layer id="12" name="Foundations" width="30" height="20">
<data encoding="csv"> <data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

View file

@ -10,7 +10,10 @@ First attempt to make a tile-based colony-sim game.
import arcade import arcade
from global_config import *
from lib.scene.scene_config import * from lib.scene.scene_config import *
from lib.scene.scene_logic import info_from_layered_tilemap
from lib.engine.game_logic import GameLogic, init_gb_from_scene_info
# CLASSES ----------------------------------------------------------- # CLASSES -----------------------------------------------------------
@ -34,9 +37,6 @@ class GameBoard(arcade.Window):
) )
self.scene = arcade.Scene.from_tilemap(self.tile_map) self.scene = arcade.Scene.from_tilemap(self.tile_map)
for layer in self.scene.keys():
print(layer)
# Tiles selection # Tiles selection
self.selected_struct_tile = "[Nothing]" self.selected_struct_tile = "[Nothing]"
self.selected_env_tile = GROUND self.selected_env_tile = GROUND
@ -76,8 +76,12 @@ class GameBoard(arcade.Window):
color=arcade.color.RED_ORANGE color=arcade.color.RED_ORANGE
) )
# Initialize the Game Logic class # Initialize the Game Logic manager (this also inits the board)
# self.game_logic = GameLogic(self.scene, None) # First, get the layers from the scene, and convert them
# into proper game objects
scene_info = info_from_layered_tilemap(self.scene)
game_layers = init_gb_from_scene_info(scene_info)
self.game_logic = GameLogic(game_layers)
def on_key_release(self, symbol, modifiers): def on_key_release(self, symbol, modifiers):
if symbol == arcade.key.ESCAPE: if symbol == arcade.key.ESCAPE:
@ -114,11 +118,11 @@ class GameBoard(arcade.Window):
elif self.pressed_key == arcade.key.C: elif self.pressed_key == arcade.key.C:
res = self.game_logic.place_structure(CROPS, x, y) res = self.game_logic.place_structure(CROPS, x, y)
elif self.pressed_key == arcade.key.W: elif self.pressed_key == arcade.key.W:
res = self.game_logic.place_structure(HYDROPOWER, x, y) res = self.game_logic.place_structure(HYDRO_POWER, x, y)
elif self.pressed_key == arcade.key.H: elif self.pressed_key == arcade.key.H:
res = self.game_logic.place_structure(HOUSING, x, y) res = self.game_logic.place_structure(HOUSING, x, y)
elif self.pressed_key == arcade.key.M: elif self.pressed_key == arcade.key.M:
res = self.game_logic.place_structure(MINER, x, y) res = self.game_logic.place_structure(MINE, x, y)
elif self.pressed_key == arcade.key.F: elif self.pressed_key == arcade.key.F:
res = self.game_logic.place_structure(FACTORY, x, y) res = self.game_logic.place_structure(FACTORY, x, y)
elif self.pressed_key == arcade.key.J: elif self.pressed_key == arcade.key.J: