aboutsummaryrefslogtreecommitdiffstats
path: root/main.lua
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2014-05-12 13:00:01 +0200
committerpiernov <piernov@piernov.org>2014-05-12 13:00:01 +0200
commite72226dbf8f61dacc2fe4d18297807faa27b207f (patch)
tree82fe32b0e1b594c5c7241353ba1685d1f50818ee /main.lua
parent344b536979556aa2cfec0f9b16d6140e8fed9fe5 (diff)
downloadMastermind-e72226dbf8f61dacc2fe4d18297807faa27b207f.tar.gz
Mastermind-e72226dbf8f61dacc2fe4d18297807faa27b207f.tar.bz2
Mastermind-e72226dbf8f61dacc2fe4d18297807faa27b207f.tar.xz
Mastermind-e72226dbf8f61dacc2fe4d18297807faa27b207f.zip
Multiplayer mode + various improvement
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua55
1 files changed, 48 insertions, 7 deletions
diff --git a/main.lua b/main.lua
index d6b4170..b34509a 100644
--- a/main.lua
+++ b/main.lua
@@ -1,21 +1,62 @@
-require 'love2d-fakecanvas/fakecanvas'
+--[[
+ main.lua
+ Main file used by LÖVE to start the game
+ by piernov
+]]--
-Screen = {}
+require 'love2d-fakecanvas/fakecanvas' -- Load canvas emulation library
+
+Debug = false -- Set to true to view the answer in Solo mode
+
+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()
- Gamestate.registerEvents()
- Gamestate.switch(Menu)
+ 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)
- Screen.width, Screen.height = love.window.getDimensions()
+ 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
- love.event.quit()
+ 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