Compare commits
5 Commits
6efd05febe
...
main
Author | SHA1 | Date | |
---|---|---|---|
6b5748dae7
|
|||
1d816e0c6a
|
|||
be321db355
|
|||
7c3fc833df
|
|||
10aef3b1ed
|
224
vacuum_gambit.p8
224
vacuum_gambit.p8
@@ -653,17 +653,17 @@ end
|
|||||||
|
|
||||||
function destination:anchor(fx, fy)
|
function destination:anchor(fx, fy)
|
||||||
local af = self.anchor_frac
|
local af = self.anchor_frac
|
||||||
if (af == -1) return 55,63
|
if (af == -1) return 51,59
|
||||||
return lerp(fx, primary_ship.x + 4, af), lerp(fy, primary_ship.y + 4, af)
|
return lerp(fx, primary_ship.x, af), lerp(fy, primary_ship.y, af)
|
||||||
end
|
end
|
||||||
|
|
||||||
function destination:target_from(fx, fy)
|
function destination:target_from(fx, fy)
|
||||||
local rx, ry = self:anchor(fx, fy)
|
local rx, ry = self:anchor(fx, fy)
|
||||||
local xf, yf = self.x_off_frac, self.y_off_frac
|
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, 0, -xf)
|
||||||
if (xf > 0) rx = lerp(rx, 112, xf)
|
if (xf > 0) rx = lerp(rx, 104, xf)
|
||||||
if (yf < 0) ry = lerp(ry, 0, -yf)
|
if (yf < 0) ry = lerp(ry, 0, -yf)
|
||||||
if (yf > 0) ry = lerp(ry, 128, yf)
|
if (yf > 0) ry = lerp(ry, 120, yf)
|
||||||
return rx, ry, self.accel_frac
|
return rx, ry, self.accel_frac
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -686,21 +686,21 @@ segment = mknew{
|
|||||||
-- dest_x, dest_y: stored
|
-- dest_x, dest_y: stored
|
||||||
-- current destination to
|
-- current destination to
|
||||||
-- figure out approach/depart
|
-- figure out approach/depart
|
||||||
-- [1..n]: destinations
|
-- dests[1..n]: destinations
|
||||||
init = function(x)
|
init = function(x)
|
||||||
x.init = segment.reset
|
x.init = segment.reset
|
||||||
mknew(x)
|
mknew(x)
|
||||||
if not x.mirror then
|
if not x.mirror then
|
||||||
local mirrored = {mirror=x, init=segment.reset}
|
local mdests = {}
|
||||||
for i, v in ipairs(x) do
|
for i, v in ipairs(x.dests) do
|
||||||
mirrored[i] = destination.new{
|
mdests[i] = destination.new{
|
||||||
anchor_frac=v.anchor_frac,
|
anchor_frac=v.anchor_frac,
|
||||||
accel_frac=v.accel_frac,
|
accel_frac=v.accel_frac,
|
||||||
x_off_frac=-v.x_off_frac,
|
x_off_frac=-v.x_off_frac,
|
||||||
y_off_frac=v.y_off_frac,
|
y_off_frac=v.y_off_frac,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
x.mirror = mknew(x.new(mirrored))
|
x.mirror = mknew(x.new{mirror=x, init=segment.reset, dests=mdests})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
@@ -714,7 +714,7 @@ function segment:reset()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function segment:target_from(fx, fy)
|
function segment:target_from(fx, fy)
|
||||||
local rx, ry, af = self[self.current_idx]:target_from(fx, fy)
|
local rx, ry, af = self.dests[self.current_idx]:target_from(fx, fy)
|
||||||
self.dest_x, self.dest_y = rx, ry
|
self.dest_x, self.dest_y = rx, ry
|
||||||
return rx, ry, af
|
return rx, ry, af
|
||||||
end
|
end
|
||||||
@@ -725,7 +725,8 @@ function segment:update(x, y)
|
|||||||
if (rem > 0) rem -= 1
|
if (rem > 0) rem -= 1
|
||||||
|
|
||||||
if self:should_step(x, y) then
|
if self:should_step(x, y) then
|
||||||
if self.current_idx == #self then
|
self.prev_x, self.prev_y, self.was_approaching = false, false, false
|
||||||
|
if self.current_idx == #self.dests then
|
||||||
self.current_idx = self.loop_idx
|
self.current_idx = self.loop_idx
|
||||||
if (rem < 0) rem += 1
|
if (rem < 0) rem += 1
|
||||||
else
|
else
|
||||||
@@ -737,45 +738,40 @@ function segment:update(x, y)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function segment:should_step(x, y)
|
function segment:should_step(x, y)
|
||||||
local dest_x, dest_y, ret = self.dest_x, self.dest_y, false
|
local dest_x, dest_y = self.dest_x, self.dest_y
|
||||||
local dx1, dy1 = x - dest_x, y-dest_y
|
local dx1, dy1 = x - dest_x, y-dest_y
|
||||||
if abs(dx1) <= 4 and abs(dy1) <= 4 then
|
if (abs(dx1) <= 1.5 and abs(dy1) <= 1.5) return true
|
||||||
self.was_approaching = false
|
|
||||||
ret = true
|
|
||||||
end
|
|
||||||
if self.prev_x then
|
if self.prev_x then
|
||||||
local dx0, dy0 = self.prev_x - dest_x, self.prev_y - dest_y
|
local dx0, dy0 = self.prev_x - dest_x, self.prev_y - dest_y
|
||||||
if dx1 * dx1 + dy1 * dy1 > dx0 * dx0 + dy0 * dy0 then
|
local d12, d02 = dx1 * dx1 + dy1 * dy1, dx0 * dx0 + dy0 * dy0
|
||||||
if self.was_approaching then
|
if d12 > d02 then
|
||||||
self.was_approaching = false
|
if (self.was_approaching) return true
|
||||||
ret = true
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
|
if (d12 == d02 and self.was_approaching) return true
|
||||||
self.was_approaching = true
|
self.was_approaching = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.prev_x, self.prev_y = x, y
|
self.prev_x, self.prev_y = x, y
|
||||||
return ret
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
path = mknew {
|
path = mknew {
|
||||||
loop_idx = 1,
|
loop_idx = 1,
|
||||||
-- [1..n]: destinations
|
-- segs[1..n]: segments or subpaths
|
||||||
init=function(x)
|
init=function(x)
|
||||||
if not x.mirror then
|
if not x.mirror then
|
||||||
local mirrored = {
|
local msegs = {}
|
||||||
mirror = x,
|
for i, v in ipairs(x.segs) do
|
||||||
loop_idx = x.loop_idx,
|
msegs[i]=v.mirror
|
||||||
}
|
|
||||||
for i, v in ipairs(x) do
|
|
||||||
mirrored[i]=v.mirror
|
|
||||||
end
|
end
|
||||||
x.mirror = path.new(mirrored)
|
x.mirror = path.new{mirror=x, loop_idx=x.loop_idx, segs=msegs}
|
||||||
end
|
end
|
||||||
x.init = function(y)
|
x.init = function(y)
|
||||||
for i, v in ipairs(x) do
|
local ysegs = {}
|
||||||
y[i]=v.new{}
|
for i, v in ipairs(x.segs) do
|
||||||
|
ysegs[i]=v.new{}
|
||||||
end
|
end
|
||||||
|
y.segs = ysegs
|
||||||
y:reset()
|
y:reset()
|
||||||
end
|
end
|
||||||
mknew(x)
|
mknew(x)
|
||||||
@@ -784,22 +780,27 @@ path = mknew {
|
|||||||
|
|
||||||
function path:reset()
|
function path:reset()
|
||||||
self.current_idx = 1
|
self.current_idx = 1
|
||||||
|
for s in all(self.segs) do
|
||||||
|
s:reset()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function path:target_from(fx, fy)
|
function path:target_from(fx, fy)
|
||||||
return self[self.current_idx]:target_from(fx, fy)
|
return self.segs[self.current_idx]:target_from(fx, fy)
|
||||||
end
|
end
|
||||||
|
|
||||||
function path:update(x, y)
|
function path:update(x, y)
|
||||||
local idx = self.current_idx
|
local idx, segs = self.current_idx, self.segs
|
||||||
if self[idx]:update(x, y) then
|
if not segs[idx]:update(x, y) then
|
||||||
if idx == #self then
|
segs[idx]:reset()
|
||||||
|
if idx == #segs then
|
||||||
self.current_idx = self.loop_idx
|
self.current_idx = self.loop_idx
|
||||||
return true
|
return
|
||||||
else
|
else
|
||||||
self.current_idx = idx+1
|
self.current_idx = idx+1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-->8
|
-->8
|
||||||
@@ -1406,71 +1407,6 @@ shield will
|
|||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
-- original prototype leftover;
|
|
||||||
-- likely to be the basis of a
|
|
||||||
-- standard raider type, so
|
|
||||||
-- i am keeping it around
|
|
||||||
chasey = mknew(ship_m.new{
|
|
||||||
sprite = 5,
|
|
||||||
xp = 0x0.0004,
|
|
||||||
size = 1,
|
|
||||||
hurt = {
|
|
||||||
x_off = 1,
|
|
||||||
y_off = 2,
|
|
||||||
width = 6,
|
|
||||||
height = 5,
|
|
||||||
},
|
|
||||||
sparks = smokespark,
|
|
||||||
sparkodds = 8,
|
|
||||||
hp = 1.5,
|
|
||||||
shield = 1,
|
|
||||||
maxshield = 1,
|
|
||||||
|
|
||||||
fire_off_x = 4,
|
|
||||||
fire_off_y = 7,
|
|
||||||
|
|
||||||
maxspd = 2,
|
|
||||||
thrust = 0.2,
|
|
||||||
drag = 0.075,
|
|
||||||
|
|
||||||
init = function(ship)
|
|
||||||
--ship.main_gun=ship.main_gun or zap_gun_e.new{}
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
function chasey:act()
|
|
||||||
self.xmin = max(primary_ship.x-8, 0)
|
|
||||||
self.xmax = min(primary_ship.x + 8, 112 - 8*self.size)
|
|
||||||
return 0, 0, false, self.y > 10 and self.x - 16 < primary_ship.x and self.x + 16 > primary_ship.x
|
|
||||||
end
|
|
||||||
|
|
||||||
xl_chasey=mknew(chasey.new{
|
|
||||||
size=2,
|
|
||||||
xp = 0x0.000a,
|
|
||||||
maxspd=1.25,
|
|
||||||
hurt = {
|
|
||||||
x_off = 2,
|
|
||||||
y_off = 4,
|
|
||||||
width = 12,
|
|
||||||
height = 10
|
|
||||||
},
|
|
||||||
fire_off_x = 8,
|
|
||||||
fire_off_y = 15,
|
|
||||||
hp = 19.5,
|
|
||||||
shield = 5,
|
|
||||||
boss = true,
|
|
||||||
act = function(self)
|
|
||||||
local dx,dy,shoot_spec,shoot_main = chasey.act(self)
|
|
||||||
if (self.y < 4) dy=self.thrust
|
|
||||||
return dx,dy,shoot_spec,shoot_main
|
|
||||||
end,
|
|
||||||
draw = function(self)
|
|
||||||
if(self.fx_pal) pal(self.fx_pal)
|
|
||||||
sspr(40, 0, 8, 8, self.x, self.y, 16, 16)
|
|
||||||
pal()
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
-- flotilla ships
|
-- flotilla ships
|
||||||
|
|
||||||
ship_f = mknew(ship_m.new{
|
ship_f = mknew(ship_m.new{
|
||||||
@@ -1498,15 +1434,65 @@ ship_f = mknew(ship_m.new{
|
|||||||
})
|
})
|
||||||
|
|
||||||
diamond_loop = segment.new{
|
diamond_loop = segment.new{
|
||||||
|
dests = {
|
||||||
destination.new{
|
destination.new{
|
||||||
x_off_frac=0.25
|
x_off_frac=0.125
|
||||||
}, destination.new{
|
}, destination.new{
|
||||||
y_off_frac=0.25
|
y_off_frac=0.125
|
||||||
}, destination.new {
|
}, destination.new {
|
||||||
x_off_frac = -0.25
|
x_off_frac = -0.125
|
||||||
}, destination.new {
|
}, destination.new {
|
||||||
y_off_frac = -0.25
|
y_off_frac = -0.125
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
park = segment.new{
|
||||||
|
dests = {
|
||||||
|
destination.new{
|
||||||
|
accel_frac = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
diamond_bounce = path.new{
|
||||||
|
segs = {
|
||||||
|
park,
|
||||||
|
diamond_loop,
|
||||||
|
park,
|
||||||
|
diamond_loop.mirror,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
swoop = segment.new {
|
||||||
|
dests = {
|
||||||
|
destination.new{
|
||||||
|
accel_frac = 0
|
||||||
|
}, destination.new{
|
||||||
|
x_off_frac = -0.75,
|
||||||
|
anchor_frac = 0.25,
|
||||||
|
}, destination.new {
|
||||||
|
x_off_frac = -0.375,
|
||||||
|
anchor_frac = 0.625,
|
||||||
|
}, destination.new {
|
||||||
|
y_off_frac = -0.125,
|
||||||
|
anchor_frac = 1,
|
||||||
|
}, destination.new {
|
||||||
|
x_off_frac = 0.375,
|
||||||
|
anchor_frac = 0.625,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
swoop_loop = path.new {
|
||||||
|
segs = {
|
||||||
|
diamond_loop,
|
||||||
|
swoop,
|
||||||
|
park,
|
||||||
|
diamond_loop.mirror,
|
||||||
|
swoop.mirror,
|
||||||
|
park,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ship_mook = mknew(ship_f.new{
|
ship_mook = mknew(ship_f.new{
|
||||||
@@ -1525,22 +1511,21 @@ ship_turret = mknew(ship_f.new{
|
|||||||
ship_skirmisher = mknew(ship_f.new{
|
ship_skirmisher = mknew(ship_f.new{
|
||||||
sprite=107,
|
sprite=107,
|
||||||
xp = 0x0.0004,
|
xp = 0x0.0004,
|
||||||
|
hp = 1.5,
|
||||||
sparks = smokespark,
|
sparks = smokespark,
|
||||||
sparkodds = 3,
|
sparkodds = 3,
|
||||||
fire_off_y = 7,
|
fire_off_y = 7,
|
||||||
xmin = -8,
|
xmin = -8,
|
||||||
xmax = 112,
|
xmax = 112,
|
||||||
path = diamond_loop,
|
path = swoop_loop,
|
||||||
})
|
})
|
||||||
|
|
||||||
function ship_skirmisher:reset_bounds()
|
function ship_skirmisher:reset_bounds()
|
||||||
self.xmin, self.xmax, self.ymin, self.ymax = -8, 112, 0, 120
|
self.xmin, self.xmax, self.ymin, self.ymax = -8, 112, 0, 128
|
||||||
end
|
end
|
||||||
|
|
||||||
function ship_skirmisher:act()
|
function ship_skirmisher:act()
|
||||||
local tx, ty, af = self.path:target_from(self.want_x+4, self.want_y+4)
|
local tx, ty, af = self.path:target_from(self.want_x, self.want_y)
|
||||||
tx -= 4
|
|
||||||
ty -= 4
|
|
||||||
if af <= 0 then
|
if af <= 0 then
|
||||||
self.xmin, self.xmax, self.ymin, self.ymax = tx,tx,ty,ty
|
self.xmin, self.xmax, self.ymin, self.ymax = tx,tx,ty,ty
|
||||||
return 0,0
|
return 0,0
|
||||||
@@ -1553,7 +1538,7 @@ end
|
|||||||
|
|
||||||
function ship_skirmisher:move()
|
function ship_skirmisher:move()
|
||||||
if (not ship_f.move(self)) return
|
if (not ship_f.move(self)) return
|
||||||
if (not self.path:update(self.x+4, self.y+4)) self.path:reset()
|
if (not self.path:update(self.x, self.y)) self.path:reset()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1657,7 +1642,7 @@ flotilla = mknew{
|
|||||||
[8]=mknew(ship_turret.new{ship_t=8}),
|
[8]=mknew(ship_turret.new{ship_t=8}),
|
||||||
[9]=mknew(ship_turret.new{ship_t=9, sprite=4}),
|
[9]=mknew(ship_turret.new{ship_t=9, sprite=4}),
|
||||||
[12]=mknew(ship_skirmisher.new{ship_t=12}),
|
[12]=mknew(ship_skirmisher.new{ship_t=12}),
|
||||||
[13]=mknew(ship_skirmisher.new{ship_t=13, sprite=26}),
|
[13]=mknew(ship_skirmisher.new{ship_t=13, sprite=26, path=diamond_bounce}),
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
@@ -1673,6 +1658,7 @@ function flotilla:load(ulc_cx, ulc_cy, lvl)
|
|||||||
[12]=0,
|
[12]=0,
|
||||||
[13]=0,
|
[13]=0,
|
||||||
}
|
}
|
||||||
|
local maxcol = 0
|
||||||
repeat
|
repeat
|
||||||
local row,cx,opt,f,mode = {},ulc_cx,{},0,0
|
local row,cx,opt,f,mode = {},ulc_cx,{},0,0
|
||||||
for i,v in ipairs(self.opt_odds) do
|
for i,v in ipairs(self.opt_odds) do
|
||||||
@@ -1684,7 +1670,7 @@ function flotilla:load(ulc_cx, ulc_cy, lvl)
|
|||||||
mode = f&0x03
|
mode = f&0x03
|
||||||
if mode==2 then
|
if mode==2 then
|
||||||
-- bits 0x0c: ship class
|
-- bits 0x0c: ship class
|
||||||
local ship_t = f&0x0c
|
local ship_t, col = f&0x0c, cx-ulc_cx
|
||||||
-- bit 0x20: optional?
|
-- bit 0x20: optional?
|
||||||
if f&0x20 == 0 or opt[ship_t] then
|
if f&0x20 == 0 or opt[ship_t] then
|
||||||
-- bit 0x10: alternate ship?
|
-- bit 0x10: alternate ship?
|
||||||
@@ -1693,7 +1679,8 @@ function flotilla:load(ulc_cx, ulc_cy, lvl)
|
|||||||
-- and we allow alternates
|
-- and we allow alternates
|
||||||
-- for this type of ship
|
-- for this type of ship
|
||||||
ship_t+=(uv>>ship_t&0x1)&((f&0x10)>>4)
|
ship_t+=(uv>>ship_t&0x1)&((f&0x10)>>4)
|
||||||
add(row, self.ship_bases[ship_t].new{col=cx-ulc_cx})
|
add(row, self.ship_bases[ship_t].new{col=col})
|
||||||
|
if (col > maxcol) maxcol = col
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
cx += 1
|
cx += 1
|
||||||
@@ -1713,6 +1700,13 @@ function flotilla:load(ulc_cx, ulc_cy, lvl)
|
|||||||
-- control mark bit 0x04: end of flotilla
|
-- control mark bit 0x04: end of flotilla
|
||||||
until f&0x04 > 0
|
until f&0x04 > 0
|
||||||
self.rows=rows
|
self.rows=rows
|
||||||
|
-- mirror right half paths; alternate center column if odd
|
||||||
|
local rh = maxcol>>1
|
||||||
|
for r, row in ipairs(rows) do
|
||||||
|
for s in all(row) do
|
||||||
|
if ((s.path) and (s.col > rh or (s.col == rh and r & 1 == 1))) s.path = s.path.mirror.new()
|
||||||
|
end
|
||||||
|
end
|
||||||
self:statisfy(counts)
|
self:statisfy(counts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user