From 5ce2f24a21b943f4254d7afdb8466a4aeec4ab45 Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Sat, 31 Dec 2022 23:34:47 -0800 Subject: [PATCH 1/3] Implement hint system and music mute. --- chameleonic.p8 | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/chameleonic.p8 b/chameleonic.p8 index e12c95c..2531fdd 100644 --- a/chameleonic.p8 +++ b/chameleonic.p8 @@ -8,6 +8,7 @@ real_modules={} frame=0 function _init() -- printh("restarting") + music_on() _doall("init") end function _update() frame+=1 @@ -15,6 +16,16 @@ function _update() function _draw() _doall("draw") end +function music_on() + music(0) + menuitem(3, "music: on", music_off) +end + +function music_off() + music(-1) + menuitem(3, "music: off", music_on) +end + mnames={} function names(root) local n=mnames[root] @@ -97,6 +108,15 @@ function sgn0(x) return x!=0 and sgn(x) or 0 end +function inorder(tbl) + local prev + for v in all(tbl) do + if (prev and v < prev) return + prev = v + end + return true +end + function _mnmx(x,y) if (x>y)return y,x return x,y @@ -266,6 +286,7 @@ function level:init() end function level:reinit(n) + self.hintlevel = 0 self.ix=n self.todo={} self.bigx,self.bigy=n%8,n\8 @@ -1704,6 +1725,62 @@ function level_text:draw() print(xys[4],xys[2],xys[3],6) end end + +-->8 +--hint system +function gsv(s) + local ret=split(s,"\n") + for i,v in ipairs(ret) do + ret[i] = type(v) == "string" and split(v,"`") or {v} end + return ret +end + +function rot13(s) + local sord = pack(ord(s,1,#s)) + for i,c in ipairs(sord) do + if (inorder{65, c, 77} or inorder{97, c, 109}) sord[i]=c+13 + if (inorder{78, c, 90} or inorder{110, c, 122}) sord[i]=c-13 + end + return chr(unpack(sord)) +end +--hint file format: +-- each row is one hint. 4 columns per row +-- separated with a grave (`) character +-- room# ` X (screen px) ` Y (screen px) ` message +-- message is ROT13d; works for a-zA-Z + +hints = {} +add(real_modules,hints) + +function hints:init() + local h = gsv[[1`64`64`zYRZ +2`32`32`fCYHOC]] + for rec in all(h) do + rec[4]=rot13(rec[4]) + local lh = self[rec[1]] + if not lh then + lh = {rec} + self[rec[1]] = lh + else + add(lh,rec) + end + end + menuitem(1,"get hint",function() level.hintlevel+=1 end) + menuitem(2,"hide hints",function() level.hintlevel=0 end) +end + +hintflicker={7,10,9,8,8,9,10,7} +function hints:draw2() + pal() + local c=hintflicker[t()%1*#hintflicker\1+1] + for i,h in ipairs(self[level.ix]) do + if (i > level.hintlevel) return + local _,x,y,txt=unpack(h) + print(txt,x-1,y+1,1) + print(txt,x,y,c) + end +end + __gfx__ 000030000000002200003000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeff1ff1ff1fffffff1ffffff1fffffff1dddddddd111111110005000000000000 003333300000332200333330eeffffffffffffffffffffeee5e555e55e555e5eff1ff1ffffffffffffffffffffffffffdddddddd111111110000500000000000 -- 2.34.1 From a2212c342f5f64adfa4419f949f12a0f744f63cc Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Sat, 31 Dec 2022 23:38:10 -0800 Subject: [PATCH 2/3] Test hints now both display on level 0 Allows testing progressive display of more hints. --- chameleonic.p8 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chameleonic.p8 b/chameleonic.p8 index 2531fdd..ac482ec 100644 --- a/chameleonic.p8 +++ b/chameleonic.p8 @@ -1753,8 +1753,8 @@ hints = {} add(real_modules,hints) function hints:init() - local h = gsv[[1`64`64`zYRZ -2`32`32`fCYHOC]] + local h = gsv[[0`64`64`zYRZ +0`32`32`fCYHOC]] for rec in all(h) do rec[4]=rot13(rec[4]) local lh = self[rec[1]] -- 2.34.1 From 8a192f87a22fe693eb4bf55d0d3d6b8a86787e1a Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Sat, 31 Dec 2022 23:54:27 -0800 Subject: [PATCH 3/3] Code review feedback, debug mode --- chameleonic.p8 | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/chameleonic.p8 b/chameleonic.p8 index ac482ec..017e2e9 100644 --- a/chameleonic.p8 +++ b/chameleonic.p8 @@ -26,6 +26,13 @@ function music_off() menuitem(3, "music: off", music_on) end +function gsv(s) + local ret=split(s,"\n") + for i,v in ipairs(ret) do + ret[i] = type(v) == "string" and split(v,"`") or {v} end + return ret +end + mnames={} function names(root) local n=mnames[root] @@ -1728,13 +1735,6 @@ end -->8 --hint system -function gsv(s) - local ret=split(s,"\n") - for i,v in ipairs(ret) do - ret[i] = type(v) == "string" and split(v,"`") or {v} end - return ret -end - function rot13(s) local sord = pack(ord(s,1,#s)) for i,c in ipairs(sord) do @@ -1758,21 +1758,29 @@ function hints:init() for rec in all(h) do rec[4]=rot13(rec[4]) local lh = self[rec[1]] - if not lh then - lh = {rec} - self[rec[1]] = lh - else + if lh then add(lh,rec) + else + self[rec[1]] = {rec} end end menuitem(1,"get hint",function() level.hintlevel+=1 end) menuitem(2,"hide hints",function() level.hintlevel=0 end) + -- debug mode: enable mouse + poke(0x5f2d,1) end hintflicker={7,10,9,8,8,9,10,7} function hints:draw2() pal() local c=hintflicker[t()%1*#hintflicker\1+1] + -- debug mode: mouse coord display + if stat(34) != 0 then + local mousex, mousey = stat(32), stat(33) + print("x ("..mousex..", "..mousey..")",mousex,mousey,c) + end + + for i,h in ipairs(self[level.ix]) do if (i > level.hintlevel) return local _,x,y,txt=unpack(h) -- 2.34.1