diff --git a/vacation.p8 b/vacation.p8 index ff59074..47c8029 100644 --- a/vacation.p8 +++ b/vacation.p8 @@ -65,45 +65,21 @@ function mknew(tt, more) end end --- intrusive singly-linked list. --- cannot be nested! -linked_list = {is_linked_list=true} -mknew(linked_list, function(x) +event_list = {is_event_list=true} +mknew(event_list, function(x) x.next=nil x.tail=x end) -function linked_list:push_back(x) +function event_list:push_back(x) self.tail.next = x self.tail = x end -function linked_list:push_front(x) - if (not self.next) self.tail = x - x.next = self.next - self.next = x -end - --- vore eats another linked list --- by appending its contents. --- the ingested linked is empty. -function linked_list:vore(x) - if (not x.next) return - self.tail.next = x.next - self.tail = x.tail - x.next = nil - x.tail = x -end - --- strip calls f(x) for each --- node, removing each node for --- which f(x) returns true. it --- returns the new tail; nil --- if the list is now empty. -function linked_list:strip(f) +function event_list:update() local p, n = self, self.next while n do - if f(n) then + if n:update() then p.next = n.next else p = n @@ -114,13 +90,7 @@ function linked_list:strip(f) return p end --- optimized special case - --- could be done with strip but --- this avoids extra function --- calls and comparisions since --- draw isn't allowed to kill --- the item -function linked_list:draw() +function event_list:draw() local n = self.next while n do n:draw() @@ -128,15 +98,6 @@ function linked_list:draw() end end - -function linked_list:pop_front() - local ret = self.next - if (not ret) return - self.next = ret.next - if (not ret.next) ret.tail = nil - return ret -end - -- if t[mname] is a thing, -- invoke it as a method. else, -- try each object in t @@ -172,8 +133,8 @@ function puke(item, indent, seen, hidekey) end local xpfx = pfx.." " - if item.is_linked_list then - local ret,n = "linked_list <",0 + if item.is_event_list then + local ret,n = "event_list <",0 item:strip(function(x) n += 1 ret ..= xpfx..tostr(n)..": "..puke(x, indent+2, seen, "next") @@ -395,41 +356,11 @@ end -->8 -- title screen + +-- currently just loading +-- whatever view I want to debug function newtitle() - local box = scootbox.new() - box:push(spring.new{ - v=txtbox.new{ - x=30, - text="sPRING tEST", - }, - to=64, - }) - setup_arcade_pal() - return view.of{ - { - update=function() - box.go = btn(4) - end - }, - bg.new{c=1}, - bg.new{ - y=28, - h=72, - c=5, - }, - box, - toyphin.new(), - { - x=128, - update=function(self) - self.x -= 1 - if (self.x < 0) self.x = 128 - end, - draw=function(self) - rectfill(self.x, 120, self.x, 128, 9) - end, - }, - } + return arcade_level.new() end -->8 @@ -441,20 +372,74 @@ end -->8 -- arcade mode +-- global wave amplitude clock +-- wave per 2 seconds +-- optional toff: offset. at +-- toff==0 draw directly under +-- the dolphin +function wave(toff) + toff = toff or 0 + return 2.5 * sin((t()+toff)>>1) +end + +waves={} +mknew(waves) + arcade_level = { score=0, maxscore=15, } mknew(arcade_level, function(x) - x.p = toyphin.new() + x.phin = toyphin.new{splasher=x} + -- TODO: decent looking sky and sea + x.sky = bg.new{c=12} + x.sea = bg.new{y=72, c=1} x.waves = waves.new() - x.words = linked_list.new() - x.fx = linked_list.new() + -- event list includes words + x.e = event_list.new() + -- TODO: score renderer + x.t0 = t() + + x.v = view.of{ + x.sky, + x.sea, + x.waves, + x.phin, + x.e, + } + + x.s = scootbox.new() + x.s:push(x.v) + + -- TODO: fade in level music end) --- global -function wave() - return 2.5 * sin(t()>>1) +function arcade_level:update() + -- TODO: timers, word loop, + -- level state tracking and + -- progression, etc. + self.s:update() +end + +function arcade_level:draw() + setup_arcade_pal() + self.s:draw() +end + +function arcade_level:dive_splash(x) + -- TODO: sfx, vfx for dive input +end + +function arcade_level:jump_splash(x) + -- TODO: sfx, vfx for jump input +end + +function arcade_level:surfacing_splash(x, force, harder) + -- TODO: sfx, vfx for surfacing from a dive +end + +function arcade_level:landing_splash(x, force, harder) + -- TODO: sfx, vfx for landing from a jump end -- dolphin sprite states: @@ -471,12 +456,12 @@ end phin_nrm_pal = { [2]=2, [7]=7, - [12]=12, + [14]=14, } phin_uw_pal = { [2]=130, - [7]=135, - [12]=140, + [7]=13, + [14]=141, } identity = { [0]=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 @@ -565,24 +550,8 @@ toyphin = { } mknew(toyphin) -function dive_splash(x) - -- TODO: sfx, vfx for dive input -end - -function jump_splash(x) - -- TODO: sfx, vfx for jump input -end - -function surfacing_splash(x, force, harder) - -- TODO: sfx, vfx for surfacing from a dive -end - -function landing_splash(x, force, harder) - -- TODO: sfx, vfx for landing from a jump -end - function toyphin:update() - local x, y, dy = self.x, self.y, self.dy + local x, y, dy, splash = self.x, self.y, self.dy, self.splasher -- entry mode? if not self.entered then x += 1 @@ -599,10 +568,10 @@ function toyphin:update() if self.entered and not self.exiting then if y >= 61 and y <= 67 and dy < 1 and dy > -1 then if (btn(2)) then - jump_splash(x) + splash:jump_splash(x) dy=-3.8 elseif (btn(3)) then - dive_splash(x) + splash:dive_splash(x) dy=3.8 end else @@ -616,7 +585,7 @@ function toyphin:update() local new_y = y + dy if new_y <= 64 and y > 64 then -- surfacing - surfacing_splash(x, -dy, btn(2) and (dy > -3.8)) + splash:surfacing_splash(x, -dy, btn(2) and (dy > -3.8)) if btn(2) then -- maybe boost if dy > -3.8 then @@ -637,7 +606,7 @@ function toyphin:update() end elseif new_y >= 64 and y < 64 then -- landing - landing_splash(x, dy, btn(3) and (dy < 3.8)) + splash:landing_splash(x, dy, btn(3) and (dy < 3.8)) if btn(3) then -- maybe boost if dy < 3.8 then @@ -697,30 +666,30 @@ __gfx__ 00000000777777777777777777777777777777777777777777777777777777777777777777777777777777777777777700000000000000000000000000000000 00000000700000000000000000000007700000000000000000000007700000000000000770000000000000000000000700000000000000000000000000000000 00700700700000000000000000000007700000000000000000000007700002222220000770000000000000000000000700000000000000000000000000000000 -00077000700000000000000000000007700000000000000000000007700002cccc20000770000000000000000000000700000000000000000000000000000000 -0007700070000000000000000000000770000000000000000000000770000222c220000770222200000000000000000700000000000000000000000000000000 -00700700700000000000000000000007702222022222222222222207700002cccc200007702cc222222222222222220700000000000000000000000000000000 -00000000700000000000000000000007702cc222c22c22cc22c2c2077000022222200007702c2c22c22c22cc22c2c20700000000000000000000000000000000 -00000000700000000000000000000007702c2c2c2c2c22c2c2c2c2077000022c22000007702c2c2c2c2c22c2c2c2c20700000000000000000000000000000000 -00000000700000000000000000000007702c2c2c2c2c22cc22ccc207700002c2c2200007702ccc2c2c2c22cc22ccc20700000000000000000000000000000000 -00000000702222022222222222222207702ccc22c22cc2c222c2c207700002cccc20000770222222c22cc2c222c2c20700000000000000000000000000000000 -00000000702cc222c22c22cc22c2c207702222222222222202222207700002222220000770000022222222220222220700000000000000000000000000000000 -00000000702c2c2c2c2c22c2c2c2c207700000000000000000000007700002222c20000770000000000000000000000700000000000000000000000000000000 -00000000702c2c2c2c2c22cc22ccc207700000000000000000000007700002cccc20000770000000000000000000000700000000000000000000000000000000 -00000000702ccc22c22cc2c222c2c207700000000000000000000007700002222220000770000000000000000000000700000000000000000000000000000000 -000000007022222222222222022222077000000000000000000000077000022cc220000770000000000000000000000700000000000000000000000000000000 -00000000700000000000000000000007777777777777777777777777700002c22c20000777777777777777777777777700000000000000000000000000000000 -000000007000000000000000000000077777777777777777777777777000022cc220000700000000000000000000000000000000000000000000000000000000 +00077000700000000000000000000007700000000000000000000007700002eeee20000770000000000000000000000700000000000000000000000000000000 +0007700070000000000000000000000770000000000000000000000770000222e220000770222200000000000000000700000000000000000000000000000000 +00700700700000000000000000000007702222022222222222222207700002eeee200007702ee222222222222222220700000000000000000000000000000000 +00000000700000000000000000000007702ee222e22e22ee22e2e2077000022222200007702e2e22e22e22ee22e2e20700000000000000000000000000000000 +00000000700000000000000000000007702e2e2e2e2e22e2e2e2e2077000022e22000007702e2e2e2e2e22e2e2e2e20700000000000000000000000000000000 +00000000700000000000000000000007702e2e2e2e2e22ee22eee207700002e2e2200007702eee2e2e2e22ee22eee20700000000000000000000000000000000 +00000000702222022222222222222207702eee22e22ee2e222e2e207700002eeee20000770222222e22ee2e222e2e20700000000000000000000000000000000 +00000000702ee222e22e22ee22e2e207702222222222222202222207700002222220000770000022222222220222220700000000000000000000000000000000 +00000000702e2e2e2e2e22e2e2e2e207700000000000000000000007700002222e20000770000000000000000000000700000000000000000000000000000000 +00000000702e2e2e2e2e22ee22eee207700000000000000000000007700002eeee20000770000000000000000000000700000000000000000000000000000000 +00000000702eee22e22ee2e222e2e207700000000000000000000007700002222220000770000000000000000000000700000000000000000000000000000000 +000000007022222222222222022222077000000000000000000000077000022ee220000770000000000000000000000700000000000000000000000000000000 +00000000700000000000000000000007777777777777777777777777700002e22e20000777777777777777777777777700000000000000000000000000000000 +000000007000000000000000000000077777777777777777777777777000022ee220000700000000000000000000000000000000000000000000000000000000 00000000700000000000000000000007700000000000000000000007700000222220000700000000000000000000000000000000000000000000000000000000 -000000007000000000000000000000077000000000000000000000077000022ccc20000700000000000000000000000000000000000000000000000000000000 -00000000700000000000000000000007700000000000000000000007700002c22c20000700000000000000000000000000000000000000000000000000000000 -00000000700000000000000000000007700000000000000000000007700002cccc20000700000000000000000000000000000000000000000000000000000000 +000000007000000000000000000000077000000000000000000000077000022eee20000700000000000000000000000000000000000000000000000000000000 +00000000700000000000000000000007700000000000000000000007700002e22e20000700000000000000000000000000000000000000000000000000000000 +00000000700000000000000000000007700000000000000000000007700002eeee20000700000000000000000000000000000000000000000000000000000000 00000000700000000000000000000007700000022222222222222207700002222220000700000000000000000000000000000000000000000000000000000000 -0000000070000000000000000000000770222222c22c22cc22c2c207700000000000000700000000000000000000000000000000000000000000000000000000 -00000000777777777777777777777777702cc22c2c2c22c2c2c2c207777777777777777700000000000000000000000000000000000000000000000000000000 -00000000000000000000000000000000702c2c2c2c2c22cc22ccc207000000000000000000000000000000000000000000000000000000000000000000000000 -00000000000000000000000000000000702c2c22c22cc2c222c2c207000000000000000000000000000000000000000000000000000000000000000000000000 -00000000000000000000000000000000702ccc222222222202222207000000000000000000000000000000000000000000000000000000000000000000000000 +0000000070000000000000000000000770222222e22e22ee22e2e207700000000000000700000000000000000000000000000000000000000000000000000000 +00000000777777777777777777777777702ee22e2e2e22e2e2e2e207777777777777777700000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000702e2e2e2e2e22ee22eee207000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000702e2e22e22ee2e222e2e207000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000702eee222222222202222207000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000702222200000000000000007000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000700000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000700000000000000000000007000000000000000000000000000000000000000000000000000000000000000000000000