blob: d94238be489f3bb2b87965a2a29775b92aa967a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
--[[
main.lua
Main file used by LÖVE to start the game
by piernov
]]--
require 'love2d-fakecanvas/fakecanvas' -- Load canvas emulation library
Debug = false -- Set to true to view the answer in Solo mode
Mute = false
Screen = {} -- Contains window width and height
Fonts = {} -- Used to store preloaded fonts
Gamestate = require "hump.gamestate"
Config = require "Gamestates/Config"
Menu = require "Gamestates/Menu"
local min_dt = 1/25 -- Cap FPS to 25, avoid extensive CPU use, snippet from LÖVE Wiki under love.timer.sleep()
local next_time = 0
function love.load()
Config:loadUserConfig() -- Read user configuration file to load player_name
Screen.width, Screen.height = love.window.getDimensions()
love.resize(Screen.width, Screen.height) -- Call love.resize() in order to preload fonts
love.graphics.setFont(Fonts[4]) -- Use font with size 4% by default
Gamestate.registerEvents() -- Initialize hump Gamestate library
Gamestate.switch(Menu) -- Switch to menu
next_time = love.timer.getTime() -- FPS limiting
end
function love.resize(w, h)
Screen.width, Screen.height = w, h
Fonts[4] = love.graphics.newFont("Resources/vermin_vibes_1989.ttf", 0.04*Screen.height)
Fonts[3] = love.graphics.newFont("Resources/vermin_vibes_1989.ttf", 0.03*Screen.height)
end
-- FPS limiting
function love.update(dt)
next_time = next_time + min_dt
end
function love.draw()
local cur_time = love.timer.getTime()
if next_time <= cur_time then
next_time = cur_time
return
end
love.timer.sleep(next_time - cur_time)
end
-- End
function love.keypressed(key)
if key == "escape" then -- Handle return key on Android or Escape key on regular keyboard
if Previous then -- Switch to previous entry if we aren't a the menu's root, otherwise quit
Gamestate.switch(require(Previous))
else
love.event.quit()
end
end
end
|