destination prototype
also ship bounds resets
This commit is contained in:
@ -466,9 +466,7 @@ ship_m = mknew{
|
|||||||
-- xmin, xmax, ymin, ymax:
|
-- xmin, xmax, ymin, ymax:
|
||||||
-- movement constraints
|
-- movement constraints
|
||||||
-- enforced by `constrain`.
|
-- enforced by `constrain`.
|
||||||
xmin = 0, xmax = 104,
|
xmin = 0, xmax = 104, ymin = 0, ymax = 120
|
||||||
-- ymin, ymax default to nil
|
|
||||||
-- pship needs more constraint
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function ship_m:die()
|
function ship_m:die()
|
||||||
@ -510,6 +508,10 @@ function ship_m:brake_dist(v0)
|
|||||||
return (chunk_zone + overage * (tri_frames + 1)) * sgn(v0), (overage > 0) and tri_frames + 1 or tri_frames
|
return (chunk_zone + overage * (tri_frames + 1)) * sgn(v0), (overage > 0) and tri_frames + 1 or tri_frames
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ship_m:reset_bounds()
|
||||||
|
self.xmin, self.xmax, self.ymin, self.ymax = 0, 104, 0, 120
|
||||||
|
end
|
||||||
|
|
||||||
function ship_m:constrain(p, dp, pmin, pmax, want)
|
function ship_m:constrain(p, dp, pmin, pmax, want)
|
||||||
if (not pmin) return want
|
if (not pmin) return want
|
||||||
local v1, bd, bf, bp
|
local v1, bd, bf, bp
|
||||||
@ -615,6 +617,54 @@ function ship_m:refresh_shield()
|
|||||||
self.shield_refresh_ready = gframe + self.shieldcooldown
|
self.shield_refresh_ready = gframe + self.shieldcooldown
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-->8
|
||||||
|
-- paths
|
||||||
|
|
||||||
|
-- destination: a point the
|
||||||
|
-- center of a ship approaches
|
||||||
|
destination = mknew{
|
||||||
|
-- 0..1: a point on a line
|
||||||
|
-- segment from the ship's
|
||||||
|
-- flotilla spot to the player;
|
||||||
|
-- -1 means center of play area
|
||||||
|
anchor_frac=0,
|
||||||
|
|
||||||
|
-- (0, 1]: relative to max
|
||||||
|
-- acceleration, how quickly
|
||||||
|
-- should the ship accelerate
|
||||||
|
-- to its destination?
|
||||||
|
-- 0: park here instead, using
|
||||||
|
-- constraint following
|
||||||
|
accel_frac=1,
|
||||||
|
|
||||||
|
-- how far to lerp between the
|
||||||
|
-- anchor and the screen bounds.
|
||||||
|
-- this is the "destination"-y
|
||||||
|
-- part of a destination.
|
||||||
|
x_off_frac = 0,
|
||||||
|
y_off_frac = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function lerp(a, b, f)
|
||||||
|
return (1-f)*a+b*f
|
||||||
|
end
|
||||||
|
|
||||||
|
function destination:anchor(fx, fy)
|
||||||
|
local af = self.anchor_frac
|
||||||
|
if (af == -1) return 55,63
|
||||||
|
return lerp(fx, primary_ship.x + 4, af), lerp(fy, primary_ship.y + 4, af)
|
||||||
|
end
|
||||||
|
|
||||||
|
function destination:target_from(fx, fy)
|
||||||
|
local rx, ry = self:anchor(fx, fy)
|
||||||
|
local xf, yf = self.x_off_frac, self.y_off_frac
|
||||||
|
if (xf < 0) rx = lerp(rx, 0, -xf)
|
||||||
|
if (xf > 0) rx = lerp(rx, 112, xf)
|
||||||
|
if (yf < 0) ry = lerp(ry, 0, -yf)
|
||||||
|
if (yf > 0) ry = lerp(ry, 128, yf)
|
||||||
|
return rx, ry
|
||||||
|
end
|
||||||
|
|
||||||
-->8
|
-->8
|
||||||
-- bullet and gun behaviors
|
-- bullet and gun behaviors
|
||||||
|
|
||||||
@ -1089,7 +1139,6 @@ player = mknew(ship_m.new{
|
|||||||
ymomentum = 0,
|
ymomentum = 0,
|
||||||
maxspd = 1.5, -- momentum cap
|
maxspd = 1.5, -- momentum cap
|
||||||
thrust = 0.1875, -- momentum added from button
|
thrust = 0.1875, -- momentum added from button
|
||||||
ymin = 0, ymax = 120, -- stay on screen
|
|
||||||
drag = 0.0625, -- momentum lost per frame
|
drag = 0.0625, -- momentum lost per frame
|
||||||
act = function(self) -- fetch buttons
|
act = function(self) -- fetch buttons
|
||||||
local b,th = btn(),self.thrust
|
local b,th = btn(),self.thrust
|
||||||
@ -1329,8 +1378,14 @@ ship_skirmisher = mknew(ship_f.new{
|
|||||||
sparks = smokespark,
|
sparks = smokespark,
|
||||||
sparkodds = 3,
|
sparkodds = 3,
|
||||||
fire_off_y = 7,
|
fire_off_y = 7,
|
||||||
|
xmin = -8,
|
||||||
|
xmax = 112,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function ship_skirmisher:reset_bounds()
|
||||||
|
self.xmin, self.xmax, self.ymin, self.ymax = -8, 112, 0, 120
|
||||||
|
end
|
||||||
|
|
||||||
function rnd_spawn_loc()
|
function rnd_spawn_loc()
|
||||||
local x,y = flr(rnd(304)), flr(rnd(32))
|
local x,y = flr(rnd(304)), flr(rnd(32))
|
||||||
if (x<184) return x-40,-y-8
|
if (x<184) return x-40,-y-8
|
||||||
|
Reference in New Issue
Block a user