aboutsummaryrefslogtreecommitdiff
path: root/level_map.wren
diff options
context:
space:
mode:
Diffstat (limited to 'level_map.wren')
-rw-r--r--level_map.wren42
1 files changed, 39 insertions, 3 deletions
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) {