--game loop
function _init()
map_setup()
make_player()
end
function _update()
move_player()
end
function _draw()
cls()
draw_map()
draw_player()
end
-->8
--map code
function map_setup()
--map tile settings
wall = 0
tools = 1
water = 1
anim1 = 3
anim2 = 4
lose = 6
win = 7
end
function draw_map()
map_x = flr(p.x / 16) * 16
map_y = flr(p.y / 16) * 16
camera(map_x * 8, map_y * 8)
map(0, 0, 0, 0, 128, 64)
end
function is_tile(tile_type, x, y)
tile = mget(x, y)
has_flag = fget(tile, tile_type)
return has_flag
end
function can_move(x, y)
return not is_tile(wall, x, y)
end
-->8
--player code
function make_player()
p = {}
p.x = 8
p.y = 7
p.sprite = 1
p.tools = 0
end
function draw_player()
spr(p.sprite, p.x * 8, p.y * 8)
end
function move_player()
new_x = p.x
new_y = p.y
if (btn(⬅️)) new_x -= 0.1
if (btn(➡️)) new_x += 0.1
if (btn(⬆️)) new_y -= 0.1
if (btn(⬇️)) new_y += 0.1
if (can_move(new_x, new_y)) then
p.x = mid(0, new_x, 127)
p.y = mid(0, new_y , 63)
else
sfx(0)
end