Here is the code for the game, it's basically a simple mock-up for movement and map creation:
Code: Select all
function love.load()
player = {
grid_x = 256,
grid_y = 256,
spd = 10,
walkable = false
}
map1 = {
{1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1}
}
end
function drawMap(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.update(dt)
end
function love.draw()
drawMap(map1)
love.graphics.rectangle("fill", player.grid_x, player.grid_y, 32, 32)
end
function love.keypressed(key)
if key == "up" or key == "w" then
player.grid_y = player.grid_y - 32
elseif key == "down" or key == "s" then
player.grid_y = player.grid_y + 32
elseif key == "left" or key == "a" then
player.grid_x = player.grid_x - 32
elseif key == "right" or key == "d" then
player.grid_x = player.grid_x + 32
end
end