Weeeeee/modules/update_callback.lua

79 lines
2.3 KiB
Lua
Raw Normal View History

2022-03-02 18:36:52 +01:00
local game = {}
2022-03-02 20:31:33 +01:00
local camera = {}
2022-03-03 13:13:17 +01:00
local floors = {}
local function updateinit(gamex, camerax, floorsx)
2022-03-02 18:36:52 +01:00
game = gamex
2022-03-02 20:31:33 +01:00
camera = camerax
2022-03-03 13:13:17 +01:00
floors = floorsx
2022-03-02 18:36:52 +01:00
end
local function update(dt)
2022-03-03 13:13:17 +01:00
game.world:update(dt)
2022-03-02 18:36:52 +01:00
--update player_animation
2022-03-02 19:15:45 +01:00
if spritesheets["player_die"]:getFrame() ~= 16 then
2022-03-02 18:36:52 +01:00
spritesheets["player_die"]:update(dt)
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
2022-03-02 19:15:45 +01:00
player:idle(dt)
2022-03-02 18:36:52 +01:00
--move player
if key("d") then
player:walk_right(dt)
elseif key("a") then
player:walk_left(dt)
end
--jump player
if key("w") then
player:jump(dt)
2022-03-02 19:15:45 +01:00
player.speed = player.speed_jumping
else
player.speed = player.speed_walking
2022-03-02 18:36:52 +01:00
end
if game.debug then
if key("s") then
player:down(dt)
2022-03-02 19:15:45 +01:00
player.speed = player.speed_jumping
else
player.speed = player.speed_walking
2022-03-02 18:36:52 +01:00
end
if key("f") then
--die
2022-03-02 19:15:45 +01:00
player.spritesheets["player_die"]:setFrame(1)
2022-03-02 18:36:52 +01:00
player:die(dt)
elseif key("g") then
--revive player
2022-03-02 19:15:45 +01:00
player.spritesheets["player_die"]:setFrame(1)
2022-03-02 18:36:52 +01:00
player:revive(dt)
2022-03-02 20:31:33 +01:00
end
if key("x") then
2022-03-03 13:13:17 +01:00
--print coordinates of all objects
local allstr = floors:listFloors()
allstr = allstr .. ("Player: \""..game.player.object.body:getX().."\"; y: \""..game.player.object.body:getY().."\";;;")
print(allstr)
end
if key("c") then
--reset player position
player.object.body:setX(player.spawnx)
player.object.body:setY(player.spawny)
--and velocity
player.object.body:setLinearVelocity(0, 0)
--and rotation
player.object.body:setAngle(0)
2022-03-02 18:36:52 +01:00
end
end
2022-03-03 13:13:17 +01:00
player:update(dt)
local dx,dy = (player.object.body:getX() - camera.x) / 2, (player.object.body:getY() - camera.y) / 2
2022-03-02 20:31:33 +01:00
camera:move(dx, dy)
2022-03-02 18:36:52 +01:00
end
return {
update = update,
updateinit = updateinit
}