diff --git a/vacation.p8 b/vacation.p8 index 93d171e..6179abf 100644 --- a/vacation.p8 +++ b/vacation.p8 @@ -130,6 +130,10 @@ end function nop() end +blank = {} +function blank:update() end +function blank:draw() end + -- puke emits a verbose string -- describing item, indented to -- the specified depth (0 by @@ -344,6 +348,12 @@ spring = { } mknew(spring) +function easeoutovershoot(t) + t-=1 + return 1+2.7*t*t*t+1.7*t*t +end + + function spring:update() local v = self.v self.v:update() @@ -352,7 +362,7 @@ function spring:update() return true end local t, range = self.f/self.frames, self.to - self.from - v.y = self.to-range*(2^(-10*t)*cos(2*t)) + v.y = self.from + easeoutovershoot(t)*range self.f += 1 end @@ -376,7 +386,7 @@ function scoot:update() return true end self.f += 1 - if self.f < 0 then + if self.f <= 0 then v.y=self.from return end @@ -390,7 +400,10 @@ end scootbox = {} mknew(scootbox, function(x) - x.v = view.new() + x.v = view.new{ + x=x.x, + y=x.from or scoot.from, + } x.s = scoot.new{ from=x.from or scoot.from, to=x.to or scoot.to, @@ -437,15 +450,16 @@ function zonk_txt(s, x, y, p, md, amt, frms) frms = frms or 0 amt = amt or 0 local itv = (frms>>2)&0x7ff + local t1 = txtbox.new{ + x=x+1, + y=y+1, + interval=itv, + cols=cparr(shd_txt_pal), + mode=md, + text=s, + } local v = view.of{ - txtbox.new{ - x=x+1, - y=y+1, - interval=itv, - cols=cparr(shd_txt_pal), - mode=md, - text=s, - }, + t1, txtbox.new{ x=x, y=y, @@ -455,11 +469,13 @@ function zonk_txt(s, x, y, p, md, amt, frms) text=s, }, } - return spring.new{ - from=-amt, + itv=spring.new{ + from=amt, frames=frms, v=v, } + itv.eff_w=t1:xmax() + return itv end -->8 @@ -646,30 +662,138 @@ def_15_fade = split"0,128,129,133,141,13,13,6,6,15,15,136,135,7" def_13_fade = split"0,128,129,133,141,140,140,13,13,12" def_shd_fade = split"0,128,130,141,2" -zonk_mode = {} +-- frames per character to wait +-- during zonk text display. +fchr=2 + +zonk_mode = { + files={}, + lnh = 8, + --space width + spc_w = 2, + --text mode + txmd=0x81, + --text spring-in distance + txd=10, + --text spring-in frames + txf=20, + p=def_z_pal, + + twt=60, + expect_cfg_line=true, + txt_frame=blank, + playing_text=true, + cx=0, + cy=0, +} mknew(zonk_mode, function(self) self.stripes=fuzzy_stripey.new{} - self.brth=breather.new{} -- test renderer - clear_alt_pal_bits() - pal() - pal(self.p or def_z_pal, 1) self.brth.on = true - self.txtwnd = zonk_txt("tEXT tEST", 40, 60, nrm_txt_pal, 0x81, 32, 30) end) +function zonk_mode:set(_, field,value) + self[field]=value +end +function zonk_mode:g(_, fn, ...) + return _ENV[fn](...) +end +function zonk_mode:at(_, x, y) + self.txt_frame=scootbox.new{ + x=x, + from=y, + } +end + +function zonk_mode:activate() + clear_alt_pal_bits() + pal() + pal(self.p, 1) + if (type(self.file) == "string") self.file = split(self.file, "\n") + if (not self.file) self:next_file() + assert(self.file) +end +function zonk_mode:next_file() + if #self.files > 0 then + self.file=split(deli(self.files,1), "\n") + self.expect_cfg_line=true + end +end + +-- return char count, item +-- or 0, nil: end of page +-- or nil (, nil): end of file +function zonk_mode:next_item() + if not self.line then + if (not self.file or #self.file == 0) return + if self.expect_cfg_line then + self.expect_cfg_line = false + local cfg_line = split(deli(self.file, 1), " ") + for i,cmd in ipairs(cfg_line) do + local frags = split(cmd,":") + self[frags[1]](self, unpack(frags)) + end + return self:next_item() + end + local line = deli(self.file, 1) + if line == "-----" then + self.line = nil + self.expect_cfg_line = true + self.cx = 0 + self.cy = 0 + return 0, nil + end + self.line = split(line, " ") + end + if #self.line==0 then + self.line = nil + self.cx = 0 + self.cy += self.lnh + return self:next_item() + end + -- parse token + local token = tostr(deli(self.line, 1)) + local pp,cmult=nrm_txt_pal,1 + if (token[1]=="$") token,cmult=sub(token,2),2 + if (token[1]=="^") token,cmult=sub(token,2),0.5 + if (token[1]=="!") token,pp=sub(token,2),sfd_txt_pal + if (token[1]=="#") token,pp=sub(token,2),hlt_txt_pal + local ret = zonk_txt(token,self.cx,self.cy,pp,self.txmd,self.txf,self.txd*cmult) + self.cx = ret.eff_w+self.spc_w + return #token,ret +end + function zonk_mode:update() + if self.playing_text then + self.twt -= 1 + if self.twt <= 0 then + local cn,item = self:next_item() + if not cn then + self:next_file() + self.playing_text=false + elseif cn < 0 then + self.twt = -cn + else + self.twt = cn*fchr + end + if item then + self.txt_frame:push(item) + else + self.playing_text=false + end + end + end self.stripes:update() self.brth:update() - self.txtwnd:update() + self.txt_frame:update() end function zonk_mode:draw() cls(0) self.stripes:draw() self.brth:draw() - self.txtwnd:draw() + self.txt_frame:draw() end -->8 @@ -1304,6 +1428,7 @@ function sequencer:next() else mainview = rec.f() end + if(mainview.activate) mainview:activate() mainview:update() end @@ -1317,7 +1442,15 @@ function start_game() -- }, { f = zonk_mode.new, - params={}, + params={{ + file=[[at:15:15 +ZONK TEXT TEST +#ZONK TEXT #TEST +$ZONK $TEXT $TEST +!ZONK !TEXT !TEST +^ZONK ^TEXT ^TEST + ]], + }}, }, } seq:next()