try using a path for a skirmisher
slightly stabilized but the length operator does not work in the presence of Lua Crimes like this so it needs more work
This commit is contained in:
@ -194,7 +194,9 @@ function updategame()
|
||||
interlude -= 1
|
||||
else
|
||||
current_wave = flotilla.new()
|
||||
current_wave:load(rnd() > 0.5 and 7 or 0, 0, min(ones(waves_complete)\2, 4))
|
||||
--current_wave:load(rnd() > 0.5 and 7 or 0, 0, min(ones(waves_complete)\2, 4))
|
||||
current_wave:load(0, 0, min(ones(waves_complete)\2, 4))
|
||||
current_wave:update()
|
||||
end
|
||||
events = filtermoved(events)
|
||||
appendmove(events, new_events)
|
||||
@ -662,7 +664,7 @@ function destination:target_from(fx, fy)
|
||||
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
|
||||
return rx, ry, self.accel_frac
|
||||
end
|
||||
|
||||
segment = mknew{
|
||||
@ -689,7 +691,7 @@ segment = mknew{
|
||||
x.init = segment.reset
|
||||
mknew(x)
|
||||
if not x.mirror then
|
||||
local mirrored = {mirror=x}
|
||||
local mirrored = {mirror=x, init=segment.reset}
|
||||
for i, v in ipairs(x) do
|
||||
mirrored[i] = destination.new{
|
||||
anchor_frac=v.anchor_frac,
|
||||
@ -698,7 +700,7 @@ segment = mknew{
|
||||
y_off_frac=v.y_off_frac,
|
||||
}
|
||||
end
|
||||
x.mirror = x.new(mirrored)
|
||||
x.mirror = mknew(x.new(mirrored))
|
||||
end
|
||||
end
|
||||
}
|
||||
@ -712,9 +714,9 @@ function segment:reset()
|
||||
end
|
||||
|
||||
function segment:target_from(fx, fy)
|
||||
local rx, ry = self[self.current_idx]:target_from(fx, fy)
|
||||
local rx, ry, af = self[self.current_idx]:target_from(fx, fy)
|
||||
self.dest_x, self.dest_y = rx, ry
|
||||
return rx, ry
|
||||
return rx, ry, af
|
||||
end
|
||||
|
||||
function segment:update(x, y)
|
||||
@ -1487,13 +1489,26 @@ ship_f = mknew(ship_m.new{
|
||||
act = function(self)
|
||||
local wx,wy=self.want_x,self.want_y
|
||||
self.xmin,self.xmax,self.ymin,self.ymax = wx,wx,wy,wy
|
||||
return 0,0,false,false
|
||||
return 0,0
|
||||
end,
|
||||
init = function(self)
|
||||
if (self.gun_proto) self.main_gun = self.gun_proto.new()
|
||||
if (self.path) self.path = self.path.new()
|
||||
end
|
||||
})
|
||||
|
||||
diamond_loop = segment.new{
|
||||
destination.new{
|
||||
x_off_frac=0.25
|
||||
}, destination.new{
|
||||
y_off_frac=0.25
|
||||
}, destination.new {
|
||||
x_off_frac = -0.25
|
||||
}, destination.new {
|
||||
y_off_frac = -0.25
|
||||
},
|
||||
}
|
||||
|
||||
ship_mook = mknew(ship_f.new{
|
||||
sprite=103
|
||||
})
|
||||
@ -1515,12 +1530,33 @@ ship_skirmisher = mknew(ship_f.new{
|
||||
fire_off_y = 7,
|
||||
xmin = -8,
|
||||
xmax = 112,
|
||||
path = diamond_loop,
|
||||
})
|
||||
|
||||
function ship_skirmisher:reset_bounds()
|
||||
self.xmin, self.xmax, self.ymin, self.ymax = -8, 112, 0, 120
|
||||
end
|
||||
|
||||
function ship_skirmisher:act()
|
||||
local tx, ty, af = self.path:target_from(self.want_x+4, self.want_y+4)
|
||||
tx -= 4
|
||||
ty -= 4
|
||||
if af <= 0 then
|
||||
self.xmin, self.xmax, self.ymin, self.ymax = tx,tx,ty,ty
|
||||
return 0,0
|
||||
end
|
||||
self:reset_bounds()
|
||||
local ax, ay, th = tx - self.x, ty - self.y, self.thrust*af
|
||||
local ma = max(abs(ax), abs(ay))
|
||||
return ax*th/ma, ay*th/ma
|
||||
end
|
||||
|
||||
function ship_skirmisher:move()
|
||||
if (not ship_f.move(self)) return
|
||||
if (not self.path:update(self.x+4, self.y+4)) self.path:reset()
|
||||
return true
|
||||
end
|
||||
|
||||
function rnd_spawn_loc()
|
||||
local x,y = flr(rnd(304)), flr(rnd(32))
|
||||
if (x<184) return x-40,-y-8
|
||||
|
Reference in New Issue
Block a user