Thanks in advance
Blake
EDIT
If you don't want to download it to try and find something here is the main.lua
Code: Select all
local sti = require "STI"
function love.load()
map = sti.new("Map")
collision = map:getCollisionMap("Collision")
player = {
x = 32,
y = 32,
gridX = 3,
gridY = 3,
width = 16,
height = 16
}
canMoveRight = true
canMoveLeft = true
canMoveup = true
canMoveDown = true
end
function love.update(dt)
map:update(dt)
if love.keyboard.isDown("right") then
if canMoveRight then
player.x = player.x + 2
end
if collision.data[player.gridY][player.gridX + 1] ~= 1 then
if player.x % 8 == 0 and player.x > player.gridX * 16 - 16 then
player.gridX = player.gridX + 1
end
end
if collision.data[player.gridY][player.gridX + 1] == 1 and player.x % 16 == 0 then
canMoveRight = false
else
canMoveRight = true
end
end
if love.keyboard.isDown("left") then
if canMoveLeft then
player.x = player.x - 2
end
if collision.data[player.gridY][player.gridX - 1] ~= 1 then
if player.x % 8 == 0 and player.x < player.gridX * 16 - 16 then
player.gridX = player.gridX - 1
end
end
if collision.data[player.gridY][player.gridX - 1] == 1 and player.x % 16 == 0 then
canMoveLeft = false
else
canMoveLeft = true
end
end
if love.keyboard.isDown("up") then
if canMoveUp then
player.y = player.y - 2
end
if collision.data[player.gridY - 1][player.gridX] ~= 1 then
if player.y % 8 == 0 and player.y < player.gridY * 16 - 16 then
player.gridY = player.gridY - 1
end
end
if collision.data[player.gridY - 1][player.gridX] == 1 and player.y % 16 == 0 then
canMoveUp = false
else
canMoveUp = true
end
end
if love.keyboard.isDown("down") then
if canMoveDown then
player.y = player.y + 2
end
if collision.data[player.gridY + 1][player.gridX] ~= 1 then
if player.y % 8 == 0 and player.y > player.gridY * 16 - 16 then
player.gridY = player.gridY + 1
end
end
if collision.data[player.gridY + 1][player.gridX] == 1 and player.y % 16 == 0 then
canMoveDown = false
else
canMoveDown = true
end
end
end
function love.draw()
map:draw()
love.graphics.rectangle( "fill", (player.gridX * 16 - 16), player.gridY * 16 - 16, player.width, player.height )
love.graphics.setColor(0,0,0)
love.graphics.rectangle( "fill", player.x, player.y, player.width, player.height)
love.graphics.setColor(255,255,255)
love.graphics.print(player.x % 16, 300, 300, 0, 2)
love.graphics.print(player.y % 16, 300, 350, 0, 2)
end
function love.resize(w, h)
map:resize(w, h)
end