diff --git a/rearm_prototype.p8 b/rearm_prototype.p8 index 66ff364..1014209 100644 --- a/rearm_prototype.p8 +++ b/rearm_prototype.p8 @@ -4,6 +4,53 @@ __lua__ -- vacuum gambit -- by kistaro windrider +-- stdlib + +-- generate standard "overlay" +-- constructor for type tt. +-- if tt.init is defined, generated +-- new calls tt.init(ret) after +-- ret is definitely not nil, +-- before calling setmetatable. +-- use to initialize mutables. +-- +-- if there was a previous new, +-- it is invoked on the new +-- object *after* more, because +-- this works better with the +-- `more` impls i use. +function mknew(tt) + local mt,oldnew,more = {__index=tt},tt.new,rawget(tt, "init") + tt.new=function(ret) + if(not ret) ret = {} + if(more) more(ret) + if(oldnew) oldnew(ret) + setmetatable(ret, mt) + return ret + end + return tt +end + +function easeoutbounce(t) + local n1=7.5625 + local d1=2.75 + + if (t<1/d1) then + return n1*t*t; + elseif(t<2/d1) then + t-=1.5/d1 + return n1*t*t+.75; + elseif(t<2.5/d1) then + t-=2.25/d1 + return n1*t*t+.9375; + else + t-=2.625/d1 + return n1*t*t+.984375; + end +end + +-->8 +-- entry points function _draw() cls() draw_hud_placeholder() @@ -35,6 +82,9 @@ function draw_hud_placeholder() line(113,127) end +-->8 +-- rearm pane drawing + function glow_box(x0, y0, x1, y1, c, cf) rect(x0, y0, x1, y1, c[1]) rect(x0+1, y0+1, x1-1, y1-1, c[2]) @@ -68,6 +118,51 @@ function draw_rearm(c) print("full ammo\nfull shield\n+50% health",54, 106, 6) end +-->8 +-- rearm pane objects +easing_pane = mknew{ + -- to enter: pos = 1; to exit: pos = -1 + -- runs for 16 frames +} + +function easing_pane:update() + local pos = self.pos + if (not pos or pos == 0) return + -- increment is 0x0.1 -- 1/16th of pos + if (pos < 0) pos = min(pos + 0x0.1, 0) + if pos > 0 then + pos -= 0x0.1 + if (pos <= 0) pos = nil + end + self.pos = pos +end + +weapon_pane = mknew(easing_pane.new{ + is_left = true, + s = 1, + hdr = "hull", + body = "\n +1\n max\nhealth", + hot = function() return item == 1 end, +}) + +function weapon_pane:draw() + local pos, frac, is_left = self.pos, 1, self.is_left + if (not pos) return + if (pos < 0) frac = easeoutbounce(1+pos) + if (pos > 0) frac = easeoutbounce(1-pos) + camera( + frac * (is_left and 55 or 0) + (1-frac) * (is_left and 0 or -56), + frac * 55) + glow_box(0,0,55,100,c,1) + spr(self.s,5, 5) + print(self.hdr, 13, 8, 7) + print(self.body, 5, 15, 6) + camera() +end + +rearm_pane = mknew(easing_pane.new{}) + + __gfx__ 000000000b00000000000a0007700770000aa0000444440004444444000000000000000000000000000000000000000000000000000000000000000000000000 00000000bba80880000008000aa00aa00a0880a0447777700477777a000000000000000000000000000000000000000000000000000000000000000000000000