aboutsummaryrefslogtreecommitdiff
path: root/level_map.wren
diff options
context:
space:
mode:
Diffstat (limited to 'level_map.wren')
-rw-r--r--level_map.wren27
1 files changed, 15 insertions, 12 deletions
diff --git a/level_map.wren b/level_map.wren
index 88ce9c6..4d46321 100644
--- a/level_map.wren
+++ b/level_map.wren
@@ -4,7 +4,8 @@ import "math" for Math
import "./layer_type" for LayerType, ObjectType
import "./entities/player_entity" for Player
class LevelMap {
- construct new(mapName) {
+ construct new(mapName, gameState) {
+ __gameState = gameState
_mapData = Json.load("assets/%(mapName).json")
var tileSheetData = _mapData["tilesets"][0] // Assuming there is only a single tilesheet/level
_tileSheet = ImageData.loadFromFile("assets/%(tileSheetData["image"])")
@@ -21,8 +22,8 @@ class LevelMap {
"x": 0,
"y": 0
}
+ _levelEntities = []
placeObjects()
-
}
playerPos = (position) {
@@ -40,22 +41,24 @@ class LevelMap {
"x": object["x"],
"y": object["y"]
}
- _player = Player.new(playerPos["x"], playerPos["y"])
+ _player = Player.new(playerPos["x"], playerPos["y"], __gameState)
+ __gameState.addEntities(_player)
+ }
+
+ if(object["type"]==ObjectType.COLLIDER) {
+ __gameState.addCollidable({
+ "x": Math.floor(object["x"]),
+ "y": Math.floor(object["y"]),
+ "width": Math.floor(object["width"]),
+ "height": Math.floor(object["height"])
+ })
}
}
}
}
}
- draw(dt) {
- _player.draw(dt)
- }
-
- update() {
- _player.update()
- }
-
- render(x, y) {
+ draw(x, y) {
var startX = x
var startY = y
for(layer in _layers) {