1require("resources/modules/common") 2require("resources/modules/jlib") 3require("resources/modules/events") 4require("resources/modules/effects") 5 6-- Parse options and set video mode from that. 7function main() 8 -- Get access to some managers. 9 local persistenceManager = jvgslua.PersistenceManager_getInstance() 10 local videoManager = jvgslua.VideoManager_getInstance() 11 local inputConfiguration = jvgslua.InputConfiguration_getConfiguration() 12 local fontManager = jvgslua.FontManager_getInstance() 13 local levelManager = jvgslua.LevelManager_getInstance() 14 15 -- First load configration from file, then set values from command line 16 -- options. 17 local saveFile = (os.getenv("HOME") or ".") .. "/.jvgs.xml" 18 persistenceManager:load(saveFile) 19 jlib.parseOptions() 20 21 -- Parse and set video options. 22 local width = persistenceManager:isSet("width") 23 and persistenceManager:get("width") or nil 24 local height = persistenceManager:isSet("height") 25 and persistenceManager:get("height") or nil 26 local fullscreen = persistenceManager:isSet("height") 27 and persistenceManager:get("fullscreen") or nil 28 if width and height and not (fullscreen == "yes") then 29 videoManager:setVideoMode(jvgslua.Vector2D(width, height), "jvgs") 30 else 31 videoManager:setVideoMode("jvgs") 32 end 33 34 -- Warn when using global variables. 35 setmetatable(_G, { 36 __newindex = function(table, key, value) 37 print("Warning - setting global " .. key .. " to a " .. type(value)) 38 rawset(table, key, value) 39 end 40 }) 41 42 -- Set key configuration. 43 inputConfiguration:setKey("jump", jvgslua.KEY_SPACE) 44 inputConfiguration:setKey("action", jvgslua.KEY_LCTRL) 45 inputConfiguration:setKey("left", jvgslua.KEY_LEFT) 46 inputConfiguration:setKey("right", jvgslua.KEY_RIGHT) 47 inputConfiguration:setKey("up", jvgslua.KEY_UP) 48 inputConfiguration:setKey("down", jvgslua.KEY_DOWN) 49 50 -- Load a font 51 local font = jvgslua.Font("resources/font.ttf", 36) 52 fontManager:addFont("regular", font) 53 54 levelManager:queueLevel("resources/level-main-menu/main-menu.xml") 55 levelManager:run() 56 57 -- Make sure everything is saved. 58 persistenceManager:write(saveFile) 59end 60 61main() 62