From 705886d371cf2cfa619b321c0d87caca0773a789 Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Tue, 3 Aug 2021 17:53:10 +0530 Subject: Bug Fixes Player Placement Basic Player Movement --- level_map.wren | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'level_map.wren') diff --git a/level_map.wren b/level_map.wren index 2bfb941..88ce9c6 100644 --- a/level_map.wren +++ b/level_map.wren @@ -1,8 +1,8 @@ import "json" for Json import "graphics" for ImageData import "math" for Math -import "./layer_type" for LayerType - +import "./layer_type" for LayerType, ObjectType +import "./entities/player_entity" for Player class LevelMap { construct new(mapName) { _mapData = Json.load("assets/%(mapName).json") @@ -17,9 +17,45 @@ class LevelMap { _layers = _mapData["layers"] _rows = Math.floor(_tileSheetW/_tileW) _cols = Math.floor(_tileSheetH/_tileH) + _playerPos = { + "x": 0, + "y": 0 + } + placeObjects() + + } + + playerPos = (position) { + _playerPos = position + } + + playerPos { _playerPos } + + placeObjects() { + for(layer in _layers) { + if(layer["type"] == LayerType.Object) { + for(object in layer["objects"]) { + if(object["type"]==ObjectType.PLAYER) { + playerPos = { + "x": object["x"], + "y": object["y"] + } + _player = Player.new(playerPos["x"], playerPos["y"]) + } + } + } + } + } + + draw(dt) { + _player.draw(dt) + } + + update() { + _player.update() } - draw(x, y) { + render(x, y) { var startX = x var startY = y for(layer in _layers) { -- cgit v1.2.3