Mothback/main.lua

199 lines
4.0 KiB
Lua
Raw Normal View History

2021-10-25 23:19:22 +00:00
function love.load()
2021-10-25 23:19:22 +00:00
do_pause = false
2021-10-25 23:19:22 +00:00
debug = false
debug_collision = false
editor_mode = false
2021-10-25 23:19:22 +00:00
textScale = 1
fps_count = 0
fps_second = 0
fps_draw = 0
fps_total = 0
2021-10-25 23:19:22 +00:00
love.graphics.setColor(1,1,1)
love.keyboard.setKeyRepeat(true)
love.graphics.setDefaultFilter("nearest") -- good pixel
2021-10-25 23:19:22 +00:00
game = {
scale = 2,
width = love.graphics.getWidth(),
height = love.graphics.getHeight(),
paused = false
}
2021-10-25 23:19:22 +00:00
require "data/scripts"
Canvas = {
Darkness = CreateDarkness()
}
2021-10-27 09:06:08 +00:00
love.graphics.setCanvas(Canvas.Darkness)
SetDarkness()
love.graphics.setCanvas()
2021-10-25 23:19:22 +00:00
Camera.width = game.width
Camera.height = game.height
2021-10-25 23:19:22 +00:00
levelList = {"level1","2","3","ewae","tileset"}
levelNum = 1
currLevel = levelList[levelNum]
2021-10-27 09:06:08 +00:00
LoadedEntities = {}
2021-10-25 23:19:22 +00:00
LevelLoadTiles()
main_Player = Player:New(75,50)
2021-10-25 23:19:22 +00:00
table.insert(LoadedEntities,main_Player)
2022-01-18 10:21:42 +00:00
table.insert(LoadedEntities,Kupo:New(100,150))
table.insert(LoadedEntities,Kupo:New(300,150))
table.insert(LoadedEntities,Decoration:New(200,89,animation.decoration.candelabra,80))
table.insert(LoadedEntities,Fairy:New(200,88))
2022-01-18 10:21:42 +00:00
gravity = 0.05
2021-10-25 23:19:22 +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
if editor_mode then
2021-10-25 23:19:22 +00:00
AnimateTiles()
else
-- GAME STEP
if not do_pause then
SetCollisionFlags(main_Player)
for _, enty in pairs(LoadedEntities) do
enty:Smart()
enty:DoPhysics()
end
AnimateTiles()
Camera:CenterAt(main_Player.pos.x, main_Player.pos.y)
--camera:ScreenAt(main_Player.pos.x, main_Player.pos.y,game.width,game.height)
end
end
end
function love.wheelmoved(_, y)
if editor_mode then
if palette then
p_scroll = p_scroll + y
else
local oscale = game.scale
game.scale = math.max(0.1,game.scale + y/16)
end
2021-10-25 23:19:22 +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
if editor_mode then
else
main_Player.pos.x, main_Player.pos.y = 16,-10
end
2021-10-25 23:19:22 +00:00
end
if key == "f3" then
LoadLevel()
end
if key == "f4" then
if editor_mode then
editor_mode = false
else
editor_mode = true
end
2021-10-25 23:19:22 +00:00
end
end
function love.draw()
2021-10-27 09:06:08 +00:00
-- saveproof to game resize
if game.width ~= love.graphics.getWidth() or game.height ~= love.graphics.getHeight() then
game.width = love.graphics.getWidth()
game.height = love.graphics.getHeight()
Camera.height = game.height
Camera.width = game.width
Canvas.Darkness:release()
Canvas.Darkness = CreateDarkness()
love.graphics.setCanvas(Canvas.Darkness)
SetDarkness()
love.graphics.setCanvas()
end
2021-10-25 23:19:22 +00:00
-- GAME WORLD
love.graphics.scale(game.scale,game.scale)
love.graphics.setColor(1,1,1,1)
LevelDisplayBackground()
for _, enty in pairs(LoadedEntities) do
enty:HandleAnimation()
end
LevelDisplayForeground()
-- Save color
local pcr, pcg, pcb, pca = love.graphics.getColor()
2021-10-27 09:06:08 +00:00
2021-10-25 23:19:22 +00:00
love.graphics.setCanvas(Canvas.Darkness)
SetDarkness()
2021-10-25 23:19:22 +00:00
DoLights()
DoBorder()
-- reset to screen
love.graphics.setColor(1,1,1,1)
love.graphics.setCanvas()
love.graphics.scale(1,1)
DrawDarkness()
2021-10-25 23:19:22 +00:00
-- HUD
-- Scale control
textScale = 0.5
2021-10-27 09:06:08 +00:00
2021-10-25 23:19:22 +00:00
--debug
if debug then DebugUI() end
if debug_collision then
love.graphics.setCanvas(Canvas.Darkness)
SetDarkness()
love.graphics.setCanvas()
--DrawDarkness()
DebugColisions()
DebugEntities()
end
2021-10-25 23:19:22 +00:00
-- 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