126 lines
2.6 KiB
Lua
126 lines
2.6 KiB
Lua
|
function love.load()
|
||
|
do_pause = false
|
||
|
debug = false
|
||
|
debug_collision = false
|
||
|
textScale = 1
|
||
|
fps_count = 0
|
||
|
fps_second = 0
|
||
|
fps_draw = 0
|
||
|
fps_total = 0
|
||
|
love.graphics.setColor(1,1,1)
|
||
|
love.keyboard.setKeyRepeat(true)
|
||
|
love.graphics.setDefaultFilter("nearest") -- good pixel
|
||
|
game = {
|
||
|
scale = 2.5,
|
||
|
width = love.graphics.getWidth(),
|
||
|
height = love.graphics.getHeight(),
|
||
|
paused = false
|
||
|
}
|
||
|
require "data/scripts"
|
||
|
Camera.width = game.width
|
||
|
Camera.height = game.height
|
||
|
levelList = {"level1","level2","level3","tileset"}
|
||
|
levelNum = 1
|
||
|
currLevel = levelList[levelNum]
|
||
|
LoadTiles()
|
||
|
InitPlayer()
|
||
|
main_player = player:newPlayer(0,0)
|
||
|
main_player.sprite = love.graphics.newImage("assets/characters/nancy/idle1.png")
|
||
|
main_player:LoadAnimation(animation.nancy.idle)
|
||
|
end
|
||
|
|
||
|
function love.update(dt)
|
||
|
-- fps counter
|
||
|
if fps_second >= 1 then
|
||
|
fps_second = fps_second - 1
|
||
|
fps_draw = fps_count
|
||
|
fps_count = 0
|
||
|
fps_total = fps_total + 1
|
||
|
end
|
||
|
fps_second = fps_second + dt
|
||
|
fps_count = fps_count + 1
|
||
|
current_dt = dt
|
||
|
|
||
|
-- saveproof to game resize
|
||
|
game.width = love.graphics.getWidth()
|
||
|
game.height = love.graphics.getHeight()
|
||
|
|
||
|
-- GAME STEP
|
||
|
if not do_pause then
|
||
|
SetCollisionFlags(main_player)
|
||
|
main_player:DoInput()
|
||
|
main_player:DoPhysics()
|
||
|
main_player:HandleAnimation()
|
||
|
main_player:Animate()
|
||
|
AnimateTiles()
|
||
|
Camera:CenterAt(main_player.pos.x, main_player.pos.y,LevelInfo.Width,LevelInfo.Height)
|
||
|
--camera:ScreenAt(main_player.pos.x, main_player.pos.y,game.width,game.height)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function love.keypressed(key)
|
||
|
|
||
|
if key == "escape" then
|
||
|
if do_pause then
|
||
|
do_pause = false
|
||
|
else
|
||
|
pausepage = 1
|
||
|
do_pause = true
|
||
|
end
|
||
|
end
|
||
|
|
||
|
if key == "f1" then
|
||
|
if debug then
|
||
|
debug = false
|
||
|
debug_collision = true
|
||
|
elseif debug_collision then
|
||
|
debug_collision = false
|
||
|
else
|
||
|
debug = true
|
||
|
end
|
||
|
end
|
||
|
|
||
|
if key == "f2" then
|
||
|
main_player.pos.x, main_player.pos.y = 0,-0.1
|
||
|
end
|
||
|
|
||
|
if key == "f3" then
|
||
|
LoadLevel()
|
||
|
end
|
||
|
|
||
|
if key == "f5" then
|
||
|
levelNum = levelNum + 1
|
||
|
if levelNum > #levelList then levelNum = levelNum - #levelList end
|
||
|
currLevel = levelList[levelNum]
|
||
|
LoadTiles()
|
||
|
main_player.pos.x, main_player.pos.y = 0,-0.1
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function love.draw()
|
||
|
TilesDisplayBack()
|
||
|
main_player:Draw()
|
||
|
TilesDisplayFront()
|
||
|
|
||
|
-- Save color
|
||
|
local pcr, pcg, pcb, pca = love.graphics.getColor()
|
||
|
-- Scale control
|
||
|
if game.height > game.width then
|
||
|
textScale = game.height/480
|
||
|
else
|
||
|
textScale = game.width/640
|
||
|
end
|
||
|
|
||
|
--debug
|
||
|
if debug then DebugUI() end
|
||
|
if debug_collision then DebugColisions() end
|
||
|
|
||
|
-- reset color
|
||
|
love.graphics.setColor(pcr,pcg,pcb,pca)
|
||
|
|
||
|
|
||
|
local pcr, pcg, pcb, pca = love.graphics.getColor()
|
||
|
if do_pause then PauseUI() end
|
||
|
love.graphics.setColor(pcr,pcg,pcb,pca)
|
||
|
end
|