summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BeatEm/init.lua14
-rw-r--r--anim/anim.lua11
-rw-r--r--global/global.lua13
-rw-r--r--jin3d/init.lua0
-rw-r--r--main.lua11
-rw-r--r--timer/timer.lua104
6 files changed, 91 insertions, 62 deletions
diff --git a/BeatEm/init.lua b/BeatEm/init.lua
new file mode 100644
index 0000000..b9cab27
--- /dev/null
+++ b/BeatEm/init.lua
@@ -0,0 +1,14 @@
+local BeatEm = {
+ _NAME = "BeatEm"
+ _AUTHOR = "Chai",
+ _DESCRIPTION = [[
+A Fighting game utility for Jin game framework.
+ ]],
+ _JIN_REVISION = 101,
+ _REVISION = 100
+ _LISENCE = [[
+
+ ]]
+}
+
+return BeatEm \ No newline at end of file
diff --git a/anim/anim.lua b/anim/anim.lua
new file mode 100644
index 0000000..a1529c3
--- /dev/null
+++ b/anim/anim.lua
@@ -0,0 +1,11 @@
+local anim = {
+ _DESCRIPTION = [[
+
+ ]],
+ _AUTHOR = "Chai",
+ _JIN_REVISION = 101,
+
+}
+
+
+return anim \ No newline at end of file
diff --git a/global/global.lua b/global/global.lua
deleted file mode 100644
index 7cce50c..0000000
--- a/global/global.lua
+++ /dev/null
@@ -1,13 +0,0 @@
-local global = {}
-_G = _G or {}
-global._G = _G
-
-global.get = function(var)
- return _G[var]
-end
-
-global.set = function(var, value)
- _G[var] = value
-end
-
-return global \ No newline at end of file
diff --git a/jin3d/init.lua b/jin3d/init.lua
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/jin3d/init.lua
diff --git a/main.lua b/main.lua
index 3de3228..4f1e82d 100644
--- a/main.lua
+++ b/main.lua
@@ -1,19 +1,18 @@
local loghelper = require("loghelper")
loghelper.strict(loghelper.LEVEL.INFO)
-local global = require("global.global")
local timer = require("timer.timer")
-global.set("frame", 0)
+_G["frame"] = 0
jin.core.onLoad = function()
timer.every(1.0, function()
- loghelper.log(loghelper.LEVEL.INFO, global.get("frame") .. "fps")
- global.set("frame", 0)
+ loghelper.log(loghelper.LEVEL.INFO, _G["frame"] .. "fps")
+ _G["frame"] = 0
end)
end
jin.core.onEvent = function(e)
- if e.type == "quit" then
+ if e.type == "quit" then
jin.core.stop()
elseif e.type == "keydown" then
if e.key == "Escape" then
@@ -23,7 +22,7 @@ jin.core.onEvent = function(e)
end
jin.core.onUpdate = function(dt)
- global.set("frame", _G['frame'] + 1)
+ _G["frame"] = _G["frame"] + 1
timer.update(dt)
-- loghelper.log(loghelper.LEVEL.WARN, "版本" .. jin.revision())
end
diff --git a/timer/timer.lua b/timer/timer.lua
index 3566709..398f47f 100644
--- a/timer/timer.lua
+++ b/timer/timer.lua
@@ -1,60 +1,78 @@
-local timer = {}
+local Timer = {}
local MODE = {
+ NONE = 0,
EVERY = 1,
REPEATS = 2,
AFTER = 3,
}
-local timers = {}
-
-timer.update = function(sec)
- for i, pack in ipairs(timers) do
- pack.count = pack.count + sec
- if pack.count >= pack.time then
- if pack.mode == MODE.EVERY then
- pack.count = 0
- pack.callback()
- elseif pack.mode == MODE.REPEATS then
- pack.count = 0
- pack.callback()
- pack.repeats = pack.repeats + 1
- if pack.repeats >= pack.rpt then
- table.remove(timers, i)
+Timer.timers = {}
+local timer = {
+ new = function(self, _mod, _duration, _count, _callback)
+ local t = {}
+ setmetatable(t, self)
+ self.__index = self
+ t:_init(_mod, _duration, _count, _callback)
+ return t
+ end,
+ _init = function(self, _mod, _duration, _count, _callback)
+ self.tick = 0
+ self.duration = _duration
+ self.mode = _mod
+ self.count = _count
+ self.callback = _callback
+ end,
+ update = function(self, dt)
+ self.tick = self.tick + dt
+ if self.tick >= self.duration then
+ if self.mode == MODE.EVERY then
+ self.tick = 0
+ elseif self.mode == MODE.REPEATS then
+ self.tick = 0
+ self.count = self.count - 1
+ if self.count <= 0 then
+ -- remove this
+ for i, v in ipairs(Timer.timers) do
+ if v == self then
+ table.remove(Timer.timers, i)
+ break
+ end
+ end
+ end
+ elseif self.mode == MODE.AFTER then
+ -- remove this
+ for i, v in ipairs(Timer.timers) do
+ if v == self then
+ table.remove(Timer.timers, i)
+ break
+ end
end
- elseif pack.mode == MODE.AFTER then
- pack.callback()
- table.remove(timers, i)
+ end
+ if self.callback then
+ self.callback()
end
end
end
+}
+
+Timer.update = function(sec)
+ for _, t in ipairs(Timer.timers) do
+ t:update(sec)
+ end
end
-timer.every = function(sec, callback)
- local pack = {}
- pack.mode = MODE.EVERY
- pack.time = sec
- pack.callback = callback
- pack.count = 0
- table.insert(timers, pack)
+Timer.every = function(sec, callback)
+ local t = timer:new(MODE.EVERY, sec, nil, callback)
+ table.insert(Timer.timers, t)
end
-timer.repeats = function(sec, rpt, callback)
- local pack = {}
- pack.mode = MODE.REPEATS
- pack.time = sec
- pack.callback = callback
- pack.count = 0
- pack.repeats = 0
- pack.rpt = rpt
- table.insert(timers, pack)
+Timer.repeats = function(sec, rpt, callback)
+ local t = timer:new(MODE.REPEATS, sec, rpt, callback)
+ table.insert(Timer.timers, t)
end
-timer.after = function(sec, callback)
- local pack = {}
- pack.mode = MODE.AFTER
- pack.time = sec
- pack.callback = callback
- pack.count = 0
- table.insert(timers, pack)
+Timer.after = function(sec, callback)
+ local t = timer:new(MODE.AFTER, sec, nil, callback)
+ table.insert(Timer.timers, t)
end
-return timer
+return Timer \ No newline at end of file