diff --git a/vacation.p8 b/vacation.p8 index 2592360..62b60b6 100644 --- a/vacation.p8 +++ b/vacation.p8 @@ -473,6 +473,11 @@ phin_uw_pal = { [7]=135, [12]=140, } +phin_err_pal = { + [2]=2, + [7]=7, + [12]=8, +} phinstate_nrm = { s={4, 36, 4, 9}, @@ -536,6 +541,13 @@ phinstate_return = { phinstate_rise_wax = phinstate_dive_wane phinstate_rise_full = phinstate_dive_full +phinstate_error = { + s={17}, + ws=1, + hs=2, + p=phin_err_pal, +} + -- coordinates are the notional -- center point of the dolphin. -- many states are off-center. @@ -547,6 +559,22 @@ toyphin = { } mknew(toyphin) +function dive_bloop() + -- TODO: sfx, vfx for dive input +end + +function jump_bloop() + -- 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() -- entry mode? if not self.entered then @@ -560,30 +588,85 @@ function toyphin:update() end end + local y, dy = self.y, self.dy -- button handling - if self.entered and not self.exiting and not self.launching then + if self.entered and not self.exiting then if self.state.idle then if (btnp(0)) then - --TODO: launch upwards + jump_bloop() + dy=-4.125 elseif (btnp(1)) then - --TODO: launch downwards + dive_bloop() + dy=4.125 end else - --TODO: nudge momentum + dy += (btnp(1) and 0.1875 or 0) - (btnp(0) and 0.1875 or 0) end end - if self.launching then - --TODO: advance launch mode + + if (y > 64) dy += 0.375 + if (y < 64) dy -= 0.375 + + local new_y = y + dy + if new_y <= 64 && y > 64 then + -- surfacing + surfacing_splash(self.x, -dy, btn(0) and (dy > -4.125)) + if btn(0) then + -- maybe boost + if dy > -4.125 then + new_y = 64 + ((dy + y - 64)/dy * -4.125) + dy = 4.125 + end + else + -- brake + if dy > -0.5 then + --stabilize + new_y = 64 + dy = 0 + else + dy /= 4 + new_y = 48 + new_y/4 + end + elseif new_y >= 64 && y < 64 then + -- landing + landing_splash(self.x, dy, btn(1) and (dy < 4.125)) + if btn(1) then + -- maybe boost + if dy < 4.125 then + new_y = 64 - ((dy - y + 64)/dy * 4.125) + dy = 4.125 + end + else + --brake + if dy < 0.5 then + --stabilize + new_y = 64 + dy = 0 + else + dy /= 4 + new_y = 80 - new_y/4 + end + end + y=new_y + + local wet, st = y > 64, phinstate_error + if dy < -1.5 then + st = wet and phinstate_rise_full or phinstate_jump_full + elseif dy <= -0.5 then + st = wet and phinstate_rise_wax or phinstate_jump_wane + elseif dy < 0.5 then + -- handle idle special case later + st = wet and phinstate_return or phinstate_crest + elseif dy <= 1.5 then + st = wet and phinstate_dive_wane or phinstate_fall_wax + else + st = wet and phinstate_dive_full or phinstate_fall_full end - if not self.state.idle then - end - --TODO: gravity - --TODO: crossing 64 - + if (y == 64 and dy == 0) st = phinstate_nrm -- test mode --if (btn(5)) self.exiting = true - + self.y, self.dy, self.state = y, dy, st end -- hitbox for current state @@ -594,6 +677,7 @@ end function toyphin:draw() local st, y = self.state, self.y + pal(st.p, 1) if (st.idle) y += wave() spr(st.s[1+(((t()<<1)&0x0.FFFF*#st.s)&0x7FFF)], self.x + st.xo, y + st.yo, self.state.ws, self.state.hs) end