main #21

Closed
kistaro wants to merge 76 commits from main into some_level
Showing only changes of commit 693cdaa11d - Show all commits

View File

@ -8,6 +8,7 @@ real_modules={}
frame=0 frame=0
function _init() function _init()
-- printh("restarting") -- printh("restarting")
music_on()
_doall("init") end _doall("init") end
function _update() function _update()
frame+=1 frame+=1
@ -15,6 +16,23 @@ function _update()
function _draw() function _draw()
_doall("draw") end _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
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={} mnames={}
function names(root) function names(root)
local n=mnames[root] local n=mnames[root]
@ -97,6 +115,15 @@ function sgn0(x)
return x!=0 and sgn(x) or 0 return x!=0 and sgn(x) or 0
end 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) function _mnmx(x,y)
if (x>y)return y,x if (x>y)return y,x
return x,y return x,y
@ -266,6 +293,7 @@ function level:init()
end end
function level:reinit(n) function level:reinit(n)
self.hintlevel = 0
self.ix=n self.ix=n
self.todo={} self.todo={}
self.bigx,self.bigy=n%8,n\8 self.bigx,self.bigy=n%8,n\8
@ -1704,6 +1732,63 @@ function level_text:draw()
print(xys[4],xys[2],xys[3],6) print(xys[4],xys[2],xys[3],6)
end end
end end
-->8
--hint system
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[[0`64`64`zYRZ
0`32`32`fCYHOC]]
for rec in all(h) do
rec[4]=rot13(rec[4])
local lh = self[rec[1]]
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)
print(txt,x-1,y+1,1)
print(txt,x,y,c)
end
end
__gfx__ __gfx__
000030000000002200003000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeff1ff1ff1fffffff1ffffff1fffffff1dddddddd111111110005000000000000 000030000000002200003000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeff1ff1ff1fffffff1ffffff1fffffff1dddddddd111111110005000000000000
003333300000332200333330eeffffffffffffffffffffeee5e555e55e555e5eff1ff1ffffffffffffffffffffffffffdddddddd111111110000500000000000 003333300000332200333330eeffffffffffffffffffffeee5e555e55e555e5eff1ff1ffffffffffffffffffffffffffdddddddd111111110000500000000000