aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2022-11-19 21:36:09 -0500
committerClyne Sullivan <clyne@bitgloo.com>2022-11-19 21:36:09 -0500
commit38987e5c1957c61eb1c4930bc4579ec862f991e0 (patch)
tree217e4eaf1b5849fc95ca2e2ff3af3b0711a8fea0
parent72603f1641bb400be6c9b0604273a4bd38932136 (diff)
lua: ui object, queued dialogui
-rw-r--r--Scripts/init.lua17
-rw-r--r--Scripts/ui.lua33
2 files changed, 43 insertions, 7 deletions
diff --git a/Scripts/init.lua b/Scripts/init.lua
index 1ae2efc..c3b6d3b 100644
--- a/Scripts/init.lua
+++ b/Scripts/init.lua
@@ -1,6 +1,9 @@
game.loadFont("default", "Assets/FreePixel.ttf", 16)
game.loadFont("dialog", "Assets/FreePixel.ttf", 16)
+-- Include UI functionality
+dofile("Scripts/ui.lua")
+
player = {
Player = 0,
EventListeners = {
@@ -26,14 +29,14 @@ player = {
JumpKeyReleased = function(self)
end,
MousePressed = function(self, mx, my)
+ ui.dialog:update(mx, my)
+
mp = game.uiToWorldCoord(mx, my)
- if math.abs(mp.x - self.Position.x) < 1 and math.abs(mp.y - self.Position.y) < 1 then
- game.dialog(30, 50, 400, 100)
- game.puts("dialog", 36, 52, "What do you think you're doing?")
- else
- if mx > 30 and mx < 430 and my > 50 and my < 150 then
- game.dialogClear()
- end
+ if math.abs(mp.x - self.Position.x) < 1 and
+ math.abs(mp.y - self.Position.y) < 1 then
+ ui.dialog:queue("Hi there! My name is Bob.")
+ ui.dialog:queue("Maybe.")
+ ui.dialog:queue("I'm really not sure, actually...")
end
end
},
diff --git a/Scripts/ui.lua b/Scripts/ui.lua
new file mode 100644
index 0000000..f6c65f2
--- /dev/null
+++ b/Scripts/ui.lua
@@ -0,0 +1,33 @@
+ui = {
+ dialog = {
+ buf = {},
+ idx = 0,
+ rdx = 0,
+
+ queue = function(self, text)
+ self.idx = self.idx + 1
+ self.buf[self.idx] = text
+
+ if self.idx == 1 then
+ game.dialog(30, 50, 400, 100)
+ game.puts("dialog", 36, 52, text)
+ end
+ end,
+
+ update = function(self, mx, my)
+ if self.idx > 0 then
+ if mx > 30 and mx < 430 and my > 50 and my < 150 then
+ self.rdx = self.rdx + 1
+ if self.rdx == self.idx then
+ self.idx = 0
+ self.rdx = 0
+ game.dialogClear()
+ else
+ game.puts("dialog", 36, 52, self.buf[self.rdx + 1])
+ end
+ end
+ end
+ end
+ }
+}
+