Yep, you could use any number of numbers. You could so use letters with a tiny bit of modification. An example of having more numbers which render differently:
Code: Select all
function love.draw()
love.graphics.rectangle("fill", player.act_x, player.act_y, 32, 32)
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)
elseif map[y][x] == 2 then
love.graphics.rectangle("fill", x * 32, y * 32, 32, 32)
end
end
end
end
To have multiple players, move the player variables into that new subtable, and add a couple variations. Something about like this:
Code: Select all
function love.load()
player = {
{
grid_x = 32,
grid_y = 32,
act_x = 32,
act_y = 32,
speed = 10
},
{
grid_x = 64,
grid_y = 256,
act_x = 64,
act_y = 256,
speed = 10
},
{
grid_x = 256,
grid_y = 256,
act_x = 256,
act_y = 256,[code]
speed = 10
}
}
end
[/code]
We will also need a viable to keep track of which player we're controlling, and may want to move some of the redundant variables out, like so:
Code: Select all
function love.load()
playermeta = {
index = 1,
speed = 10
}
end
Now we can can control the players by cycling through the index:
Code: Select all
function love.keypressed(key)
if key == "up" then
if testMap(0, -1) then
player[playermeta.index].grid_y = player[playermeta.index].grid_y - 32
end
elseif key == "down" then
if testMap(0, 1) then
player[playermeta.index].grid_y = player[playermeta.index].grid_y + 32
end
elseif key == "left" then
if testMap(-1, 0) then
player[playermeta.index].grid_x = player[playermeta.index].grid_x - 32
end
elseif key == "right" then
if testMap(1, 0) then
player[playermeta.index].grid_x = player[playermeta.index].grid_x + 32
end
elseif key == "return" then
if playermeta.index < #player then
playermeta.index = playermeta.index + 1
else
playermeta.index = 1
end
end
end
We'll also need to change the testMap function to use the current player.