From 63e7bfeb408b7b56438cde9377a689ea22d8fe53 Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Tue, 6 Feb 2024 21:39:04 -0800 Subject: [PATCH] create orchestrator system that does not work --- vacation.p8 | 119 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 110 insertions(+), 9 deletions(-) diff --git a/vacation.p8 b/vacation.p8 index 335f7ca..495d5af 100644 --- a/vacation.p8 +++ b/vacation.p8 @@ -249,6 +249,7 @@ function _init() poke(0x5f34, 1) mainview = newtitle() + mainview:on_focus() end function _update60() @@ -382,10 +383,42 @@ end -->8 -- title screen +title_screen = { +} +mknew(title_screen) + +function title_screen:draw() + pal() + cls(12) + print("title screen", 30, 58, 0) + print("press right arrow", 20, 65, 0) +end + +function title_screen:on_focus() + self.active = true +end + +function title_screen:update() + if (self.sq or not self.active or not btnp(1)) return + self.sq = sequencer.new{ + { + activate = function(self, sq) + return arcade_level.new{ + maxscore=2, + sq = sq, + } + end, + dir=slide_left, + }, + } + self.sq:do_it() +end + + -- currently just loading -- whatever view I want to debug function newtitle() - return arcade_level.new() + return title_screen.new() end -->8 @@ -463,10 +496,10 @@ phinstate_error = { -- center point of the dolphin. -- many states are off-center. toyphin = { - x=-12, + x=-48, y=64, dy=0, - state=phinstate_nrm + state=phinstate_nrm, } mknew(toyphin) @@ -700,8 +733,9 @@ end arcade_level = { score=0, - wordcount=999, + maxscore=999, wordwait = 90, + -- sq: sequencer to call when done } mknew(arcade_level, function(x) x.phin = toyphin.new{splasher=x} @@ -711,9 +745,8 @@ mknew(arcade_level, function(x) x.bg = event_list.new() x.fg = event_list.new() x.words = event_list.new() - -- TODO: score renderer x.t0 = t() - x.wordremain = x.wordcount or arcade_level.wordcount + x.wordremain = x.maxscore or arcade_level.maxscore x.wordtimer = x.wordwait or arcade_level.wordwait x.v = view.of{ @@ -758,9 +791,9 @@ function arcade_level:update() if self.wordremain <= 0 and self.words.next == nil then self.phin.exiting = true end - if self.phin.x > 90 then - -- TODO: done callback - self:on_level_done() + if self.phin.x > 90 and not self.leaving then + self.sq:do_it() + self.leaving = true end -- TODO: timers, word loop, -- level state tracking and @@ -850,6 +883,74 @@ end -->8 -- game sequencer + +slider = {} +mknew(slider, function(x) + x.vf = view.of{x.from} + x.vt = view.of{x.to} + x.vt.x = x.dir.x + x.vt.y = x.dir.y +end) + +function slider:update() + local vf, vt = self.vf, self.vt + vf:update() + vt:update() + if vt.x == 0 and vt.y == 0 then + mainview = vt + if (vt.on_focus) vt:on_focus() + if (self.sq) self.sq:progress() + return true + end + local dx, dy = self.dir.dx, self.dir.dy + vt.x += dx + vt.y += dy + vf.x += dx + vf.y += dy +end + +function slider:draw() + self.vf:draw() + self.vt:draw() +end + +slide_left = { + x = 128, y = 0, dx = -4, dy = 0 +} +slide_right = { + x = -128, y = 0, dx = 4, dy = 0 +} +sequencer = { + next_idx = 1, + score = 0, + maxscore = 0, +} +mknew(sequencer) + +function sequencer:do_it() + local n = self[self.next_idx] + if n then + if (n.maxscore) self.maxscore += n.maxscore + if (mainview.score) self.score += mainview.score + mainview = slider.new{ + from = mainview, + to = n:activate(self), + dir = n.dir, + sq = self, + } + return + end + mainview = slider.new{ + from = mainview, + to = newtitle(), + dir = slide_right, + } +end + +function sequencer:progress() + self.next_idx += 1 +end + __gfx__ 00888800777777777777777777777777000000000000000000000000777777777777777700000000000000000000000000000000000000000000000000000000 0888e780700000000000000000000007000000000000000000000000700000000000000700000000000000000000000000000000000000000000000000000000