first guess at movement. untested

This commit is contained in:
Kistaro Windrider 2024-02-03 20:52:48 -08:00
parent e00bce0426
commit 525c7e0cb6
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8

View File

@ -473,6 +473,11 @@ phin_uw_pal = {
[7]=135, [7]=135,
[12]=140, [12]=140,
} }
phin_err_pal = {
[2]=2,
[7]=7,
[12]=8,
}
phinstate_nrm = { phinstate_nrm = {
s={4, 36, 4, 9}, s={4, 36, 4, 9},
@ -536,6 +541,13 @@ phinstate_return = {
phinstate_rise_wax = phinstate_dive_wane phinstate_rise_wax = phinstate_dive_wane
phinstate_rise_full = phinstate_dive_full phinstate_rise_full = phinstate_dive_full
phinstate_error = {
s={17},
ws=1,
hs=2,
p=phin_err_pal,
}
-- coordinates are the notional -- coordinates are the notional
-- center point of the dolphin. -- center point of the dolphin.
-- many states are off-center. -- many states are off-center.
@ -547,6 +559,22 @@ toyphin = {
} }
mknew(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() function toyphin:update()
-- entry mode? -- entry mode?
if not self.entered then if not self.entered then
@ -560,30 +588,85 @@ function toyphin:update()
end end
end end
local y, dy = self.y, self.dy
-- button handling -- 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 self.state.idle then
if (btnp(0)) then if (btnp(0)) then
--TODO: launch upwards jump_bloop()
dy=-4.125
elseif (btnp(1)) then elseif (btnp(1)) then
--TODO: launch downwards dive_bloop()
dy=4.125
end end
else else
--TODO: nudge momentum dy += (btnp(1) and 0.1875 or 0) - (btnp(0) and 0.1875 or 0)
end end
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 end
if not self.state.idle then if (y == 64 and dy == 0) st = phinstate_nrm
end
--TODO: gravity
--TODO: crossing 64
-- test mode -- test mode
--if (btn(5)) self.exiting = true --if (btn(5)) self.exiting = true
self.y, self.dy, self.state = y, dy, st
end end
-- hitbox for current state -- hitbox for current state
@ -594,6 +677,7 @@ end
function toyphin:draw() function toyphin:draw()
local st, y = self.state, self.y local st, y = self.state, self.y
pal(st.p, 1)
if (st.idle) y += wave() 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) 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 end