I'm new here and new to this language.
After reading tons of lines I come to a problem, reading can't fix...
After making an AnAl animation, my moving function doesn't work anymore.
The animation still works.
The start origin of my "little hero" doesn't work too...
I've made an screenshot and saved it on my webspace so you can better see the problem: http://trade-off.de/love2d/index.html
Last but not least - sry for my poor englisch
Here comes the code:
Code: Select all
--enemy.lua
enemy = {}
function enemy.load()
enemy.x = 0
enemy.y = 100
enemy.width = 0
enemy.height = 0
local img = love.graphics.newImage("enemy/animation/right/right1.png")
anim1 = newAnimation(img, 40, 50, 0.2, 0)
local img = love.graphics.newImage("enemy/animation/left/left1.png")
anim2 = newAnimation(img, 40, 50, 0.2, 0)
local img = love.graphics.newImage("enemy/animation/down/down1.png")
anim3 = newAnimation(img, 40, 50, 0.2, 0)
local img = love.graphics.newImage("enemy/animation/top/top1.png")
anim4 = newAnimation(img, 40, 50, 0.2, 0)
idleright = love.graphics.newImage("enemy/right.png")
sound = love.audio.newSource("sounds/walk.wav")
end
function enemy.draw()
if not love.keyboard.isDown('d','a','s','w')
then
love.graphics.draw(idleright, 40, 50)
end
if love.keyboard.isDown('d')
then
anim1:draw(40, 50)
end
if love.keyboard.isDown('a')
then
anim2:draw(40, 50)
end
if love.keyboard.isDown('s')
then
anim3:draw(40, 50)
end
if love.keyboard.isDown('w')
then
anim4:draw(40, 50)
end
end
function enemy.sounds(dt)
if love.keyboard.isDown('d','a','w','s') then
sound:play()
end
end
function love.keypressed(k)
if k == 'escape' then
love.event.quit()
end
end
function enemy.move(dt)
if love.keyboard.isDown('d') then
enemy.x = enemy.x + 1
end
if love.keyboard.isDown('a') then
enemy.x = enemy.x - 1
end
if love.keyboard.isDown('w') then
enemy.y = enemy.y - 1
end
if love.keyboard.isDown('s') then
enemy.y = enemy.y + 1
end
end
function enemy.boundary()
if enemy.x < 0 then
enemy.x = 0
end
if enemy.x > 800 - enemy.width then
enemy.x = 800 - enemy.width
end
if enemy.y < 100 then
enemy.y = 100
end
if enemy.y > 600 - enemy.height then
enemy.y = 600 - enemy.height
end
end
function UPDATE_ENEMY(dt)
anim1:update(dt)
anim2:update(dt)
anim3:update(dt)
anim4:update(dt)
enemy.move(dt)
enemy.boundary()
enemy.sounds(dt)
end
function DRAW_ENEMY()
enemy.draw()
end