mirror of
https://github.com/n0remac/game-jam-2020.git
synced 2025-12-10 06:05:20 -06:00
load_file in map.py sets the tiles based on a json file
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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. """
|
||||
|
||||
@@ -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:
|
||||
"""
|
||||
|
||||
BIN
triple-dungeon/resources/images/tiles/wall_tile.png
Normal file
BIN
triple-dungeon/resources/images/tiles/wall_tile.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
19
triple-dungeon/resources/levels/box.json
Normal file
19
triple-dungeon/resources/levels/box.json
Normal file
@@ -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"]
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user