From e72226dbf8f61dacc2fe4d18297807faa27b207f Mon Sep 17 00:00:00 2001 From: piernov Date: Mon, 12 May 2014 13:00:01 +0200 Subject: Multiplayer mode + various improvement --- main.lua | 55 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 7 deletions(-) (limited to 'main.lua') 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 -- cgit v1.2.3-54-g00ecf