From bf3fbc24a50c2f4d732fd559f1a81523eeb066c6 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 5 Jan 2024 03:50:58 +0000 Subject: refactor, nicer errors --- texts.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 texts.lua (limited to 'texts.lua') diff --git a/texts.lua b/texts.lua new file mode 100644 index 0000000..9f9ff97 --- /dev/null +++ b/texts.lua @@ -0,0 +1,35 @@ +local util = require 'util' + +local texts = {} + +local function add(text,x,y) + table.insert(texts,{ + x=x,y=y,life=3,text=text + }) +end + +local function draw() + for i=#texts,1,-1 do + local t = texts[i] + util.write_at(t.text,t.x,t.y) + end +end + +local SPEED = 0.1 + +local function update(dt) + for i=#texts,1,-1 do + local t = texts[i] + t.y = t.y - SPEED * dt + t.life = t.life - dt + if t.life < 0 then + table.remove(texts, i) + end + end +end + +return { + add=add, + update=update, + draw=draw, +} -- cgit v1.2.3