diff --git a/assets/tiles/demo_tilemap.tilemap.json b/assets/tiles/demo_tilemap.tilemap.json new file mode 100644 index 0000000..bd6c2ca --- /dev/null +++ b/assets/tiles/demo_tilemap.tilemap.json @@ -0,0 +1,8 @@ +{ + "id": "demo_tilemap", + "tile_size": 32, + "tiles": [ + {"id": "grass", "walkable": true}, + {"id": "stone", "walkable": false} + ] +} diff --git a/init.lua b/init.lua index 8c6341c..403fe31 100644 --- a/init.lua +++ b/init.lua @@ -8,11 +8,15 @@ local player_control = { hello = function() return "player_control stub" end } local actor = { hello = function() return "actor stub" end } local interaction = { hello = function() return "interaction stub" end } +-- Load + activate the demo map (P.0.lib.maps slice) +local demo_map = maps.load("maps/demo.map.json") +maps.set_current(demo_map) + local frames = 0 local TARGET_FRAMES = 60 function init(ctx) - engine.print("spine-prototype init: " .. maps.hello()) + engine.print("spine-prototype init: maps loaded") engine.print("inline stubs loaded: " .. render.hello() .. ", " .. camera.hello() .. ", " @@ -20,6 +24,16 @@ function init(ctx) .. player_control.hello() .. ", " .. actor.hello() .. ", " .. interaction.hello()) + + local size = maps.size() + engine.print(string.format("map size: %dx%d", size.w, size.h)) + + local corner = maps.tile_at(0, 0) + local interior = maps.tile_at(5, 5) + engine.print("tile at (0,0): " .. corner.id) + engine.print("tile at (5,5): " .. interior.id) + engine.print("walkable at (0,0): " .. tostring(maps.is_walkable(0, 0))) + engine.print("walkable at (5,5): " .. tostring(maps.is_walkable(5, 5))) end function update(ctx, dt) diff --git a/maps/demo.map.json b/maps/demo.map.json new file mode 100644 index 0000000..af8d150 --- /dev/null +++ b/maps/demo.map.json @@ -0,0 +1,23 @@ +{ + "id": "demo", + "tilemap": "demo_tilemap", + "size": {"w": 16, "h": 16}, + "tiles": [ + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, + 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 + ] +}