diff options
author | chai <chaifix@163.com> | 2018-08-20 08:15:34 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-08-20 08:15:34 +0800 |
commit | 98ab086f430d418f33c4410cf81f4eac52d5b835 (patch) | |
tree | 446cce66de209a10c9342bf98e21524de6e4ba05 /src/lua/embed/boot.lua.h | |
parent | 22bb9b537caff927ef8c83bde82d58253ffbb1e4 (diff) |
*update
Diffstat (limited to 'src/lua/embed/boot.lua.h')
-rw-r--r-- | src/lua/embed/boot.lua.h | 108 |
1 files changed, 74 insertions, 34 deletions
diff --git a/src/lua/embed/boot.lua.h b/src/lua/embed/boot.lua.h index c2efd0e..36615b0 100644 --- a/src/lua/embed/boot.lua.h +++ b/src/lua/embed/boot.lua.h @@ -1,6 +1,5 @@ /* boot.lua */ static const char* boot_lua = R"( - jin._argv[2] = jin._argv[2] or '.' jin.filesystem.init() jin.filesystem.mount(jin._argv[2]) @@ -9,31 +8,26 @@ local conf = {} if jin.filesystem.exist("config.lua") then conf = require "config" end -conf.width = conf.width or 600 -conf.height = conf.height or 500 -conf.fps = conf.fps or 60 -conf.vsync = conf.vsync or false -conf.title = conf.title or ("jin v" .. jin.version()) -conf.resizable = conf.resizable or false +conf.width = conf.width or 576 +conf.height = conf.height or 448 +conf.fps = conf.fps or 60 +conf.vsync = conf.vsync or false +conf.title = conf.title or ("jin v" .. jin.version()) +conf.resizable = conf.resizable or false conf.fullscreen = conf.fullscreen or false -- initialize subsystems jin.graphics.init(conf) jin.audio.init() --- open debug mode, must after jin.graphics.init -if jin._argv[3] == '-d' then - jin.debug.init() -end - -local function safecall(func, ...) +local function call(func, ...) if func then - func(...) + return func(...) end end function jin.core.run() - safecall(jin.core.onLoad) + call(jin.core.onLoad) local previous = jin.time.second() local SEC_PER_UPDATE = 1 / conf.fps local dt = SEC_PER_UPDATE @@ -45,22 +39,19 @@ function jin.core.run() elseif e.type == "keyup" then jin.keyboard.set(e.key, false) end - safecall(jin.core.onEvent, e) + call(jin.core.onEvent, e) running = jin.core.running() if not running then break end end if not running then break end - safecall(jin.core.onUpdate, dt) + call(jin.core.onUpdate, dt) jin.graphics.unbind() jin.graphics.clear() jin.graphics.color() jin.graphics.study() - safecall(jin.core.onDraw) - if jin.debug.status() then - jin.debug.render() - end + call(jin.core.onDraw) jin.graphics.present() local current = jin.time.second() @@ -91,24 +82,73 @@ local function onError(msg) end end +------------------------------------------------------------------------------- +-- No game handler +------------------------------------------------------------------------------- + +jin.nogame = { + cs = 64, + sw = jin.graphics.getWidth(), + sh = jin.graphics.getHeight(), + cw = 0, + ch = 0, + ww = 6, + ww2 = 6*2, + speed = 4, + t = 0, + load = function() + local nogame = jin.nogame + nogame.cw = nogame.sw / nogame.cs + nogame.ch = nogame.sh / nogame.cs + nogame.t = nogame.ww - 1 + end, + event = function(e) + if e.type == 'quit' then + jin.core.stop() + end + end, + update = function(dt) + local nogame = jin.nogame + nogame.t = nogame.t + dt * nogame.speed + if nogame.t > nogame.ww2 then + nogame.t = nogame.t - nogame.ww2 + end + end, + circle = function(x, y, r) + local nogame = jin.nogame + if r % nogame.ww2 > nogame.ww then + return + end + r = math.sin((r/nogame.ww)*math.pi)*nogame.cs/2 + local fact = (x + y) / nogame.ch * nogame.cw + jin.graphics.color(155 + 100 * math.sin(fact), 155 + 100 * math.cos(fact), 155 + 100 * math.sin(fact * fact), 255) + jin.graphics.circle("fill", x*nogame.cs + nogame.cs/2, y*nogame.cs + nogame.cs/2, r) + end, + draw = function() + local nogame = jin.nogame + for y = 0, nogame.ch - 1 do + for x = 0, nogame.cw - 1 do + nogame.circle(x, y, nogame.t+x+y) + end + end + end +} + +------------------------------------------------------------------------------- +-- Boot jin +------------------------------------------------------------------------------- + local function boot() if jin.filesystem.exist("main.lua") then -- require main game script xpcall(function() require"main" end, onError) jin.core.run() - else + else -- no game - function jin.core.onEvent(e) - if e.type == 'quit' then - jin.core.stop() - end - end - function jin.core.onDraw() - jin.graphics.clear(111, 134, 125, 255) - local ww, wh = jin.graphics.size() - local fw, fh = jin.graphics.box("no game", 20, 1, 20) - jin.graphics.write("no game", ww /2 - fw / 2, wh * 2/3, 16, 1, 18) - end + jin.core.onLoad = jin.nogame.load + jin.core.onEvent = jin.nogame.event + jin.core.onUpdate = jin.nogame.update + jin.core.onDraw = jin.nogame.draw jin.core.run() end -- quit subsystems @@ -118,6 +158,6 @@ local function boot() jin.core.quit() end -boot() +xpcall(boot, onError) )"; |