2021-10-16 23:06:11 +00:00
|
|
|
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 = {
|
2021-10-25 00:00:21 +00:00
|
|
|
scale = 2,
|
2021-10-16 23:06:11 +00:00
|
|
|
width = love.graphics.getWidth(),
|
|
|
|
height = love.graphics.getHeight(),
|
|
|
|
paused = false
|
|
|
|
}
|
|
|
|
require "data/scripts"
|
|
|
|
Camera.width = game.width
|
|
|
|
Camera.height = game.height
|
2021-10-22 16:23:05 +00:00
|
|
|
levelList = {"level1","2","3","ewae","tileset"}
|
2021-10-16 23:06:11 +00:00
|
|
|
levelNum = 1
|
|
|
|
currLevel = levelList[levelNum]
|
2021-10-22 16:23:05 +00:00
|
|
|
LevelLoadTiles()
|
|
|
|
main_Player = Player:New(1220,220)
|
|
|
|
LoadedEntities = {}
|
|
|
|
table.insert(LoadedEntities,main_Player)
|
2021-10-25 00:00:21 +00:00
|
|
|
table.insert(LoadedEntities,Kupo:New(450,100))
|
|
|
|
table.insert(LoadedEntities,Kupo:New(250,150))
|
2021-10-22 16:23:05 +00:00
|
|
|
main_Player.sprite = love.graphics.newImage("assets/characters/nancy/idle1.png")
|
|
|
|
main_Player:LoadAnimation(animation.nancy.idle)
|
2021-10-16 23:06:11 +00:00
|
|
|
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()
|
2021-10-22 16:23:05 +00:00
|
|
|
Camera.height = game.height
|
|
|
|
Camera.width = game.width
|
2021-10-16 23:06:11 +00:00
|
|
|
-- GAME STEP
|
|
|
|
if not do_pause then
|
2021-10-22 16:23:05 +00:00
|
|
|
SetCollisionFlags(main_Player)
|
|
|
|
for _, enty in pairs(LoadedEntities) do
|
2021-10-24 23:41:40 +00:00
|
|
|
enty:Smart()
|
2021-10-22 16:23:05 +00:00
|
|
|
enty:DoPhysics()
|
|
|
|
end
|
2021-10-16 23:06:11 +00:00
|
|
|
AnimateTiles()
|
2021-10-22 16:23:05 +00:00
|
|
|
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)
|
2021-10-16 23:06:11 +00:00
|
|
|
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
|
2021-10-22 16:23:05 +00:00
|
|
|
main_Player.pos.x, main_Player.pos.y = 0,-0.1
|
2021-10-16 23:06:11 +00:00
|
|
|
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]
|
2021-10-22 16:23:05 +00:00
|
|
|
LevelLoadTiles()
|
|
|
|
main_Player.pos.x, main_Player.pos.y = 0,-0.1
|
2021-10-16 23:06:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.draw()
|
2021-10-25 00:00:21 +00:00
|
|
|
-- GAME WORLD
|
|
|
|
love.graphics.scale(game.scale,game.scale)
|
2021-10-22 16:23:05 +00:00
|
|
|
LevelDisplayBackground()
|
|
|
|
for _, enty in pairs(LoadedEntities) do
|
2021-10-24 23:41:40 +00:00
|
|
|
enty:HandleAnimation()
|
|
|
|
enty:Animate()
|
2021-10-22 16:23:05 +00:00
|
|
|
enty:Draw()
|
|
|
|
end
|
|
|
|
LevelDisplayForeground()
|
2021-10-16 23:06:11 +00:00
|
|
|
|
|
|
|
-- Save color
|
|
|
|
local pcr, pcg, pcb, pca = love.graphics.getColor()
|
2021-10-25 00:00:21 +00:00
|
|
|
|
|
|
|
-- HUD
|
|
|
|
love.graphics.scale(1,1)
|
2021-10-16 23:06:11 +00:00
|
|
|
-- Scale control
|
|
|
|
if game.height > game.width then
|
2021-10-25 00:00:21 +00:00
|
|
|
textScale = game.height/480/2
|
2021-10-16 23:06:11 +00:00
|
|
|
else
|
2021-10-25 00:00:21 +00:00
|
|
|
textScale = game.width/640/2
|
2021-10-16 23:06:11 +00:00
|
|
|
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
|