summaryrefslogtreecommitdiff
path: root/game/text_events.lua
diff options
context:
space:
mode:
Diffstat (limited to 'game/text_events.lua')
-rw-r--r--game/text_events.lua43
1 files changed, 43 insertions, 0 deletions
diff --git a/game/text_events.lua b/game/text_events.lua
new file mode 100644
index 0000000..ace00eb
--- /dev/null
+++ b/game/text_events.lua
@@ -0,0 +1,43 @@
+local M = {}
+
+M.pieces = function(game)
+ local t = {text="pieces:\n0"}
+ game.loop:wrap(function()
+ while true do
+ local e = game.loop.poll("game.piece_placed")
+ t.text = "pieces:\n"..game.stats.pieces
+ end
+ end)
+ return t
+end
+
+M.lines = function(game, goal)
+ local t = {text="lines:\n0"..(goal and "/"..goal or "")}
+ game.loop:wrap(function()
+ while true do
+ local e = game.loop.poll("game.line_clear")
+ t.text = "lines:\n"..game.stats.lines..(goal and "/"..goal or "")
+ end
+ end)
+ return t
+end
+
+local function display_time(t)
+ local seconds = math.floor(t%60)
+ local minutes = math.floor(t/60)
+ local centiseconds = math.floor((t*100)%100)
+ return ("%02d:%02d:%02d"):format(minutes, seconds, centiseconds)
+
+end
+M.time = function(game)
+ local t = {text="time:\n"..display_time(0)}
+ game.loop:wrap(function()
+ while true do
+ local e = game.loop.poll("update")
+ t.text = "time:\n"..display_time(game.stats.time)
+ end
+ end)
+ return t
+end
+
+return M \ No newline at end of file