Mothback/main.lua

137 lines
2.6 KiB
Lua
Raw Permalink Normal View History

2022-01-18 19:45:57 +00:00
function love.load()
2022-02-07 08:41:53 +00:00
logging = true
loveMemUsage = collectgarbage("count")
loveInitLog = "love: "..loveMemUsage.." kB, time: "..os.clock().." seconds"
2022-01-18 20:12:13 +00:00
arrow = 0
2022-01-18 19:45:57 +00:00
menu_type = "no"
2022-01-18 19:45:57 +00:00
debug = false
debug_collision = false
editor_mode = false
textScale = 1
2022-02-27 03:45:11 +00:00
2022-01-18 19:45:57 +00:00
love.graphics.setColor(1,1,1)
love.keyboard.setKeyRepeat(true)
love.graphics.setDefaultFilter("nearest") -- good pixel
game = {
secondsSinceStart = 0,
2022-01-18 19:45:57 +00:00
scale = 2,
width = love.graphics.getWidth(),
2022-02-27 02:02:06 +00:00
height = love.graphics.getHeight(),
framerate = 60
2022-01-18 19:45:57 +00:00
}
2022-02-12 10:36:43 +00:00
require "code/require"
2022-02-27 03:45:11 +00:00
fps_history = AvgQueue:New(30,60)
logPrint(loveInitLog)
loveInitLog = nil
2022-01-18 19:45:57 +00:00
Camera.width = game.width
Camera.height = game.height
2022-02-12 09:35:45 +00:00
levelList = scandir("./data/levels")
2022-01-18 19:45:57 +00:00
levelNum = 1
currLevel = levelList[levelNum]
logPrint("currLevel: "..currLevel)
LoadedParticles = {}
2022-01-18 19:45:57 +00:00
LevelLoadTiles()
language = "ENG"
2022-01-31 10:06:24 +00:00
LocaleLoad(language)
gravity = 0.14
-- Debug and log stuff
memoryUsage, dtcount = 0, 0
logPrint("mothback: "..collectgarbage("count").." kB, Loading time: "..os.clock().." seconds")
2022-01-18 19:45:57 +00:00
main_Player = Player:New(75,50)
--Kupo:New(100,150)
--Kupo:New(300,150)
2022-02-15 09:21:24 +00:00
HookAnchor:New(200,89)
HookAnchor:New(400,89)
Fairy:New(200,88)
--CursedBook:New(180,68)
2022-01-18 19:45:57 +00:00
--love.audio.play(music.placeholder)
2022-01-18 19:45:57 +00:00
end
function love.update(dt)
-- audio update
love.audio.update()
2022-01-18 19:45:57 +00:00
-- fps counter
2022-02-27 03:45:11 +00:00
fps_current = fps_history:Push(1/dt)
2022-01-18 19:45:57 +00:00
current_dt = dt
game.secondsSinceStart = game.secondsSinceStart + dt
2022-01-18 19:45:57 +00:00
if DemoRecording or DemoPlayback then Demo:Step() end
-- things per second
dtcount = dtcount + dt
if dtcount >= 1 then
if secs == nil then secs = 0 end
secs = secs + 1
dtcount = dtcount - 1
if debug or logging then
memoryUsage = math.floor(collectgarbage("count"))
end
2022-02-07 08:41:53 +00:00
logWrite("Second "..secs..": "..memoryUsage.." kB")
end
--keypressed
if Keybind:CheckPressed(Keybind.menu.pause) then
2022-01-18 19:45:57 +00:00
if do_pause then
do_pause = false
else
menu_type = "pause"
MenuInit(menu_type)
2022-01-18 19:45:57 +00:00
end
end
--MenuStep
if menu_type ~= nil then MenuStep(menu_type) end
--editor
if editor_mode then
EditorStep()
else
GameStep()
end
end
function love.wheelmoved(_, y)
if editor_mode then
EditorScroll(y)
end
2022-01-18 19:45:57 +00:00
end
function love.draw()
if game.width ~= love.graphics.getWidth() or game.height ~= love.graphics.getHeight() then
game.width = love.graphics.getWidth()
game.height = love.graphics.getHeight()
game_resize = true
else
game_resize = false
end
if editor_mode then
EditorDraw()
2022-01-18 19:45:57 +00:00
else
GameDraw()
2022-01-18 19:45:57 +00:00
end
if menu_type ~= nil then MenuDraw(menu_type) end
2022-01-31 06:38:15 +00:00
love.graphics.print(game.scale,10,40)
if DemoRecording or DemoPlayback then Demo:Draw() end
2022-01-18 19:45:57 +00:00
end