now there are spawn objects! now entity spawns are loaded from level! now entity spawns are saved to level!
175 lines
3.4 KiB
Lua
175 lines
3.4 KiB
Lua
function love.load()
|
|
logging = true
|
|
local love_mem_usage = collectgarbage("count")
|
|
local love_init_log = "love: "..love_mem_usage.." kB, time: "..os.clock().." seconds"
|
|
|
|
secs = 0
|
|
|
|
menu_type = "no"
|
|
debug = false
|
|
debug_collision = false
|
|
editor_mode = false
|
|
|
|
text_size = 1
|
|
|
|
|
|
love.graphics.setColor(1,1,1)
|
|
love.keyboard.setKeyRepeat(true)
|
|
love.graphics.setDefaultFilter("nearest") -- good pixel
|
|
|
|
game = {
|
|
seconds_since_start = 0,
|
|
scale = 2,
|
|
width = love.graphics.getWidth(),
|
|
height = love.graphics.getHeight(),
|
|
framerate = 60
|
|
}
|
|
|
|
require "code/require"
|
|
|
|
fps_history = AvgQueue:new(30,60)
|
|
|
|
|
|
logPrint(love_init_log)
|
|
love_init_log = nil
|
|
|
|
Camera.width = game.width
|
|
Camera.height = game.height
|
|
|
|
level_list = scandir("./data/levels")
|
|
level_current_num = 1
|
|
level_current = level_list[level_current_num]
|
|
logPrint("level_current: "..level_current)
|
|
|
|
loadLevelTiles()
|
|
|
|
language = "ENG"
|
|
loadLocale(language)
|
|
|
|
gravity = 0.14
|
|
-- Debug and log stuff
|
|
memory_usage, dtcount = 0, 0
|
|
logPrint("mothback: "..collectgarbage("count").." kB, Loading time: "..os.clock().." seconds")
|
|
|
|
main_player = Player:new(75,50)
|
|
|
|
activateSpawns()
|
|
--love.audio.play(music.placeholder)
|
|
end
|
|
|
|
function love.textinput(text)
|
|
if Prompt.active_prompt then
|
|
Prompt.active_prompt:textinput(text)
|
|
end
|
|
end
|
|
|
|
function love.keypressed(...)
|
|
if Prompt.active_prompt then
|
|
Prompt.active_prompt:keypressed(...)
|
|
end
|
|
end
|
|
|
|
function love.update(dt)
|
|
-- audio update
|
|
love.audio.update()
|
|
-- fps counter
|
|
fps_current = fps_history:push(1/dt)
|
|
|
|
current_dt = dt
|
|
game.seconds_since_start = game.seconds_since_start + dt
|
|
|
|
if DemoRecording or DemoPlayback then Demo:step() end
|
|
|
|
-- things per second
|
|
dtcount = dtcount + dt
|
|
game.seconds_since_start = game.seconds_since_start + dt
|
|
if dtcount >= 1 then
|
|
secs = secs + 1
|
|
dtcount = dtcount - 1
|
|
if debug or logging then
|
|
memory_usage = math.floor(collectgarbage("count"))
|
|
end
|
|
logWrite("Second "..secs..": "..memory_usage.." kB")
|
|
end
|
|
|
|
if Prompt.active_prompt then
|
|
-- try to stop the keypress that closed the menu from spilling into the rest of the game
|
|
Keybind:checkPressed(Keybind.menu.pause)
|
|
if Prompt.active_prompt.closing then
|
|
Prompt.active_prompt = nil
|
|
else
|
|
Prompt.active_prompt:update()
|
|
end
|
|
return
|
|
end
|
|
|
|
if Keybind:checkPressed(Keybind.debug.respawn) then
|
|
activateSpawns()
|
|
end
|
|
|
|
if love.keyboard.isDown("f7") then
|
|
local test_prompt = Prompt:new({
|
|
name = "test prompt",
|
|
func = function(prompt)
|
|
print("test prompt got input: "..prompt.input)
|
|
end,
|
|
})
|
|
test_prompt:activate()
|
|
end
|
|
|
|
--keypressed
|
|
if Keybind:checkPressed(Keybind.menu.pause) then
|
|
if do_pause then
|
|
do_pause = false
|
|
else
|
|
menu_type = "pause"
|
|
initMenu(menu_type)
|
|
end
|
|
end
|
|
|
|
--MenuStep
|
|
if menu_type ~= nil then stepMenu(menu_type) end
|
|
|
|
--editor
|
|
if editor_mode then
|
|
stepEditor()
|
|
else
|
|
stepGame()
|
|
end
|
|
end
|
|
|
|
|
|
function love.wheelmoved(_, y)
|
|
if editor_mode then
|
|
scrollEditor(y)
|
|
end
|
|
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
|
|
drawEditor()
|
|
else
|
|
drawGame()
|
|
end
|
|
|
|
if menu_type ~= nil then drawMenu(menu_type) end
|
|
|
|
love.graphics.print(game.scale,10,40)
|
|
|
|
if DemoRecording or DemoPlayback then Demo:draw() end
|
|
|
|
if Prompt.active_prompt then
|
|
Prompt.active_prompt:draw()
|
|
end
|
|
|
|
frameDebugFlush()
|
|
end
|