function love.load() player = { grid_x = 256, grid_y = 256, act_x = 200, act_y = 200, speed = 10, dir = "Your move" } map = { { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }, { 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 }, { 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 }, { 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 }, { 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }, { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, { 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0 }, { 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 }, { 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } } end function love.update(dt) player.act_y = player.act_y - ((player.act_y - player.grid_y) * player.speed * dt) player.act_x = player.act_x - ((player.act_x - player.grid_x) * player.speed * dt) if player.dir == "u" then if testMap(0, -1) then player.grid_y = player.grid_y - 32 end end if player.dir == "d" then if testMap(0, 1) then player.grid_y = player.grid_y + 32 end end if player.dir == "l" then if testMap(-1, 0) then player.grid_x = player.grid_x - 32 end end if player.dir == "r" then if testMap(1, 0) then player.grid_x = player.grid_x + 32 end end function love.draw() love.graphics.rectangle("fill", player.act_x, player.act_y, 32, 32) --Render the ones in the map. for y=1, #map do for x=1, #map[y] do if map[y][x] == 1 then love.graphics.rectangle("line", x *32, y * 32, 32, 32) end end end end function love.keypressed(key) if key == "up" then if testMap(0, -1) then player.dir = "u" end elseif key== "down" then if testMap(0, 1) then player.dir = "d" end elseif key == "left" then if testMap(-1, 0) then player.dir = "l" end elseif key == "right" then if testMap(1, 0) then player.dir = "r" end end end function testMap(x, y) if map[(player.grid_y / 32) + y][(player.grid_x / 32) + x] == 1 then return false end return true end end