aboutsummaryrefslogtreecommitdiff
path: root/level_map.wren
diff options
context:
space:
mode:
authorIndrajith K L2021-08-03 23:06:26 +0530
committerIndrajith K L2021-08-03 23:06:26 +0530
commitc3c5832587bfd36d12790537c5acb36c02574ddb (patch)
tree8890b34a79d411180284ddb8960814482de2997b /level_map.wren
parent705886d371cf2cfa619b321c0d87caca0773a789 (diff)
downloadrebirth-wren-c3c5832587bfd36d12790537c5acb36c02574ddb.tar.gz
rebirth-wren-c3c5832587bfd36d12790537c5acb36c02574ddb.tar.bz2
rebirth-wren-c3c5832587bfd36d12790537c5acb36c02574ddb.zip
Failed attempt to build collision detection
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) {