Need a little help?
Posted: Fri Feb 15, 2013 5:19 am
Ok, so I borrowed some code so I could modify it to suit my needs. Its the general tiled map loader for love, but whats confusing me is 1) how do I add collision to the map? and 2) how do I add a player sprite?
Its going to be a top down shooter, so any input/examples of making the character rotate to follow the mouse will be helpful too.
Heres the code: (in main.lua)
Its going to be a top down shooter, so any input/examples of making the character rotate to follow the mouse will be helpful too.
Heres the code: (in main.lua)
Code: Select all
love.filesystem.load("tiledmap.lua")()
gKeyPressed = {}
gCamX,gCamY = 100,100
function love.load()
player = love.graphics.newImage("gfx/player.png")
print(player:type()) -- outputs: Image
x = 0
y = 0
TiledMap_Load("map/map01.tmx")
end
function love.keyreleased( key )
gKeyPressed[key] = nil
end
function love.keypressed( key, unicode )
gKeyPressed[key] = true
if (key == "escape") then os.exit(0) end
if (key == " ") then -- space = next mal
gMapNum = (gMapNum or 1) + 1
if (gMapNum > 10) then gMapNum = 1 end
TiledMap_Load(string.format("map/map%02d.tmx",gMapNum))
gCamX,gCamY = 100,100
end
end
function love.update( dt )
local s = 500*dt
if (gKeyPressed.w) then gCamY = gCamY - s end
if (gKeyPressed.s) then gCamY = gCamY + s end
if (gKeyPressed.a) then gCamX = gCamX - s end
if (gKeyPressed.d) then gCamX = gCamX + s end
end
function love.draw()
love.graphics.print("Current FPS: "..tostring(love.timer.getFPS( )), 10, 10)
love.graphics.print('WASD=scroll, space=next map', 50, 50)
love.graphics.setBackgroundColor(0x80,0x80,0x80)
TiledMap_DrawNearCam(gCamX,gCamY)
end