I am currently playing around with Lua and love (using the ZeroBrane IDE) and I have managed to make my little pac-man thing move its mouth; however, I don't seem to be having any luck making it move using the "wasd" keys. I will attach a zip file with the main.lua and the pngs, but here is the bulk of the code:
Code: Select all
function love.load()
animation = {}
frame = 1
counter = 0
love.graphics.setBackgroundColor({255, 255, 255})
animation.x = 300
animation.y = 300
animation.speed = 100
animation[1] = love.graphics.newImage("first.png")
animation[2] = love.graphics.newImage("second.png")
end
function love.update(dt)
counter = counter + dt
if counter >=0.2 then
counter = 0
frame = frame +1
if frame == 3 then
frame = 1
end
end
if love.keyboard.isDown("a") then
animation.x = animation.x - animation.speed*dt
elseif love.keyboard.isDown("s") then
animation.y = animation.y + animation.speed*dt
elseif love.keyboard.isDown("d") then
animation.x = animation.x + animation.speed*dt
elseif love.keyboard.isDown("w") then
animation.y = animation.y - animation.speed*dt
end
end
function love.draw()
love.graphics.draw(animation[frame], 0, 0)
end