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 1 },
}
water = love.graphics.newImage("water.jpg")
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)
end
function love.draw()
love.graphics.draw (water, 0, 0, 0, 12, 12, 0, 0)
love.graphics.setColor(189, 183, 107)
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.setColor(0,0,139)
love.graphics.draw(water)
end
end
end
for y=2, #map do
for x=2, #map[y] do
if map[y][x] == 2 then
love.graphics.setColor(92,51,23)
love.graphics.rectangle("fill", x * 32, y * 32, 32, 32)
end
end
end
end
function love.keypressed(key)
if key == "up" then
if testMap(0, -1) then
player.grid_y = player.grid_y - 32
end
elseif key == "down" then
if testMap(0, 1) then
player.grid_y = player.grid_y + 32
end
elseif key == "left" then
if testMap(-1, 0) then
player.grid_x = player.grid_x - 32
end
elseif key == "right" then
if testMap(1, 0) then
player.grid_x = player.grid_x + 32
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
So thats my code. I have quite a problems, so ill make a list here:
1. First off, i don't know how to scale everything up to the players monitor size.
2.On my "map" i want to print pictures for the 1's and 0's and so on. My problem is the love.graphics.draw draws it on the coordinates.
3. I have plenty more, but ill save them for later.