Weeeeee/modules/update_callback.lua
2022-03-02 18:42:51 +01:00

54 lines
1.3 KiB
Lua

local game = {}
local function updateinit(gamex)
game = gamex
end
local function update(dt)
--update player_animation
if spritesheets["player_die"]:getFrame() ~= 16 and not game.die_animation_elapsed then
spritesheets["player_die"]:update(dt)
else
game.die_animation_elapsed = true
end
if player.alive then
spritesheets["player_jump"]:update(dt)
spritesheets["player_walk_left"]:update(dt)
spritesheets["player_walk_right"]:update(dt)
spritesheets["player_idle"]:update(dt)
spritesheets["player_default"]:update(dt)
end
--get keyboard
local key = love.keyboard.isDown
--move player
if key("d") then
player:walk_right(dt)
elseif key("a") then
player:walk_left(dt)
else
player:idle(dt)
end
--jump player
if key("w") then
player:jump(dt)
end
if game.debug then
if key("s") then
player:down(dt)
end
if key("f") then
--die
player:die(dt)
game.die_animation_elapsed = false
elseif key("g") then
--revive player
player:revive(dt)
game.die_animation_elapsed = false
end
end
end
return {
update = update,
updateinit = updateinit
}