diff --git a/triple-dungeon/config.py b/triple-dungeon/config.py index 933abaf..5366d99 100644 --- a/triple-dungeon/config.py +++ b/triple-dungeon/config.py @@ -14,6 +14,7 @@ class Config(object): SCREEN_WIDTH = 1000 SCREEN_HEIGHT = 650 SCREEN_TITLE = "Triple Dungeon" + TILE_WIDTH = 63 # Constants used to scale our sprites from their original size CHARACTER_SCALING = 1 diff --git a/triple-dungeon/main.py b/triple-dungeon/main.py index 0b13d56..8d80d0a 100644 --- a/triple-dungeon/main.py +++ b/triple-dungeon/main.py @@ -7,6 +7,7 @@ Holds the main game window, as well as manages basic functions for organizing th import arcade from config import Config +from map import Level class Game(arcade.Window): @@ -47,21 +48,15 @@ class Game(arcade.Window): self.player_list = arcade.SpriteList() # Set up the player, specifically placing it at these coordinates. - image_source = "images/monsters/skeleton.png" + image_source = "resources/images/monsters/skeleton.png" self.player_sprite = arcade.Sprite(image_source, Config.CHARACTER_SCALING) self.player_sprite.center_x = Config.SCREEN_WIDTH / 2 self.player_sprite.center_y = Config.SCREEN_HEIGHT / 2 self.player_sprite.scale = 4 self.player_list.append(self.player_sprite) - # Create the floor - # This shows using a loop to place multiple sprites horizontally and vertically - for y in range(0, 1250, 63 * Config.TILE_SCALING): - for x in range(0, 1250, 63 * Config.TILE_SCALING): - floor = arcade.Sprite("images/tiles/floor_tile.png", Config.TILE_SCALING) - floor.center_x = x - floor.center_y = y - self.floor_list.append(floor) + # Create the level + self.floor_list, self.wall_list = Level.load_file('resources/levels/box.json') # Create the 'physics engine' self.physics_engine = arcade.PhysicsEngineSimple(self.player_sprite, self.wall_list) @@ -75,6 +70,7 @@ class Game(arcade.Window): # Draw our sprites self.floor_list.draw() self.player_list.draw() + self.wall_list.draw() def on_key_press(self, key, modifiers): """Called whenever a key is pressed. """ diff --git a/triple-dungeon/map.py b/triple-dungeon/map.py index beff019..ab6399f 100644 --- a/triple-dungeon/map.py +++ b/triple-dungeon/map.py @@ -5,9 +5,10 @@ Pathfinding will also depend on objects here, and is thus integral to it's funct """ from __future__ import annotations +from config import Config import arcade - +import json class Dungeon(object): """ @@ -69,7 +70,36 @@ class Level(object): :param path: Path to the Level file. :return: The new generated Level file. """ - pass + floor_list = arcade.SpriteList() + wall_list = arcade.SpriteList() + x = 0 + y = 0 + + with open(path) as file: + level = json.load(file) + elements = level['elements'] + structure = level['structure'] + + level_size = 10 * Config.TILE_SCALING * Config.TILE_WIDTH + + # Create the level + # This shows using a loop to place multiple sprites horizontally and vertically + for y_pos in range(0, level_size , 63 * Config.TILE_SCALING): + for x_pos in range(0, level_size, 63 * Config.TILE_SCALING): + cur_tile = structure[y][x] + sprite = elements[cur_tile] + floor = arcade.Sprite(sprite, Config.TILE_SCALING) + floor.center_x = x_pos + floor.center_y = y_pos + if(cur_tile == ' '): + floor_list.append(floor) + elif(cur_tile == 'w'): + wall_list.append(floor) + x += 1 + x = 0 + y += 1 + + return (floor_list, wall_list) def render(self) -> None: """ diff --git a/triple-dungeon/resources/images/tiles/wall_tile.png b/triple-dungeon/resources/images/tiles/wall_tile.png new file mode 100644 index 0000000..dec66a0 Binary files /dev/null and b/triple-dungeon/resources/images/tiles/wall_tile.png differ diff --git a/triple-dungeon/resources/levels/box.json b/triple-dungeon/resources/levels/box.json new file mode 100644 index 0000000..6defcda --- /dev/null +++ b/triple-dungeon/resources/levels/box.json @@ -0,0 +1,19 @@ +{ + "elements" : { + "w" : "resources/images/tiles/wall_tile.png", + " " : "resources/images/tiles/floor_tile.png", + "e" : "" + }, + "structure" : [ + ["w", "w", "w", "w", "w", "w", "w", "w", "w", "w"], + ["w", " ", " ", " ", " ", " ", " ", " ", " ", "w"], + ["w", " ", " ", " ", " ", " ", " ", " ", " ", "w"], + ["w", " ", " ", " ", " ", " ", " ", " ", " ", "w"], + ["w", " ", " ", " ", " ", " ", " ", " ", " ", "w"], + ["w", " ", " ", " ", " ", " ", " ", " ", " ", "w"], + ["w", " ", " ", " ", " ", " ", " ", " ", " ", "w"], + ["w", " ", " ", " ", " ", " ", " ", " ", " ", "w"], + ["w", " ", " ", " ", " ", " ", " ", " ", " ", "w"], + ["w", "w", "w", "w", "w", "w", "w", "w", "w", "w"] + ] +} \ No newline at end of file