diff --git a/apps/demos/crawl/data/assets/mossy_rock.png b/apps/demos/crawl/data/assets/mossy_rock.png new file mode 100644 index 0000000..8aa6f4b --- /dev/null +++ b/apps/demos/crawl/data/assets/mossy_rock.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:03e495dd39deb47191beb57267c1ad0e0c1e1a823c8e06bb1344c751e275bdb4 +size 34907 diff --git a/apps/demos/crawl/data/levels/00.lvl b/apps/demos/crawl/data/levels/00.lvl index 798b326..8631102 100644 --- a/apps/demos/crawl/data/levels/00.lvl +++ b/apps/demos/crawl/data/levels/00.lvl @@ -13,19 +13,20 @@ -- Defines classes under symbols, which could have properties attached. # stone_wall wall_texture : /assets/brick.png + solid : 1 . stone_floor - tile_texture : /assets/pebbles.png + tile_texture : /assets/mossy_rock.png @ player_spawn - unique : + unique : 1 face : south hold : torch - tile_texture : /assets/pebbles.png + tile_texture : /assets/mossy_rock.png X door open_on_signal : sg_torch0 - tile_texture : /assets/pebbles.png + tile_texture : /assets/mossy_rock.png / lever on_interact_emit : sg_torch0 - tile_texture : /assets/pebbles.png + tile_texture : /assets/mossy_rock.png @meta -- Arbitrary sections could be defined with value pairs. diff --git a/apps/demos/crawl/data/scripts/game.lua b/apps/demos/crawl/data/scripts/game.lua index 71e4a42..f5a73a2 100644 --- a/apps/demos/crawl/data/scripts/game.lua +++ b/apps/demos/crawl/data/scripts/game.lua @@ -36,15 +36,19 @@ function game_tick() ctx.udata.player.direction = { x = -ctx.udata.player.direction.z, y = ctx.udata.player.direction.y, z = ctx.udata.player.direction.x } end - local direction = { x = 0, z = 0 } + local move = { x = 0, y = 0 } if input_action_just_released { name = "walk_forward" } then - direction = { x = direction.x + ctx.udata.player.direction.z, z = direction.z + ctx.udata.player.direction.x } + move = { x = move.x + ctx.udata.player.direction.z, y = move.y + ctx.udata.player.direction.x } end if input_action_just_released { name = "walk_backward" } then - direction = { x = direction.x - ctx.udata.player.direction.z, z = direction.z - ctx.udata.player.direction.x } + move = { x = move.x - ctx.udata.player.direction.z, y = move.y - ctx.udata.player.direction.x } end - ctx.udata.player.position = { x = ctx.udata.player.position.x + direction.x, y = ctx.udata.player.position.y + direction.z } + if ctx.udata.level.grid[ctx.udata.player.position.y + move.y][ctx.udata.player.position.x + move.x].solid ~= nil then + move = { x = 0, y = 0 } + end + + ctx.udata.player.position = { x = ctx.udata.player.position.x + move.x, y = ctx.udata.player.position.y + move.y } ctx.udata.player.position_lerp.x = qlerp(ctx.udata.player.position_lerp.x, ctx.udata.player.position.x, ctx.frame_duration * 30) ctx.udata.player.position_lerp.y = qlerp(ctx.udata.player.position_lerp.y, ctx.udata.player.position.y, ctx.frame_duration * 30) @@ -53,9 +57,9 @@ function game_tick() draw_camera { position = { - x = ctx.udata.player.position_lerp.y * 2 + 1, + x = ctx.udata.player.position_lerp.y * 2 + 1 - ctx.udata.player.direction.x / 2, y = 1, - z = ctx.udata.player.position_lerp.x * 2 + 1, + z = ctx.udata.player.position_lerp.x * 2 + 1 - ctx.udata.player.direction.z / 2, }, direction = ctx.udata.player.direction_lerp, }