79 lines
2.3 KiB
Lua
79 lines
2.3 KiB
Lua
local game = {}
|
|
local camera = {}
|
|
local floors = {}
|
|
local function updateinit(gamex, camerax, floorsx)
|
|
game = gamex
|
|
camera = camerax
|
|
floors = floorsx
|
|
end
|
|
|
|
local function update(dt)
|
|
game.world:update(dt)
|
|
--update player_animation
|
|
if spritesheets["player_die"]:getFrame() ~= 16 then
|
|
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
|
|
player:idle(dt)
|
|
--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)
|
|
player.speed = player.speed_jumping
|
|
else
|
|
player.speed = player.speed_walking
|
|
end
|
|
if game.debug then
|
|
if key("s") then
|
|
player:down(dt)
|
|
player.speed = player.speed_jumping
|
|
else
|
|
player.speed = player.speed_walking
|
|
end
|
|
if key("f") then
|
|
--die
|
|
player.spritesheets["player_die"]:setFrame(1)
|
|
player:die(dt)
|
|
elseif key("g") then
|
|
--revive player
|
|
player.spritesheets["player_die"]:setFrame(1)
|
|
player:revive(dt)
|
|
end
|
|
if key("x") then
|
|
--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)
|
|
end
|
|
end
|
|
player:update(dt)
|
|
local dx,dy = (player.object.body:getX() - camera.x) / 2, (player.object.body:getY() - camera.y) / 2
|
|
camera:move(dx, dy)
|
|
end
|
|
return {
|
|
update = update,
|
|
updateinit = updateinit
|
|
} |