7 Commits

Author SHA1 Message Date
b18b4f885d trig zap gun; fixes
use the trig gun for the zap gun
2025-06-01 17:00:28 -07:00
2fdb8d1a05 trigenometry gun prototype 2025-06-01 16:48:39 -07:00
fc1f84fa28 Delete slip behavior 2025-06-01 16:15:46 -07:00
93b63a5831 Prevent new calls that won't work as expected 2025-06-01 16:11:35 -07:00
297e6e4996 implement clip reload time
two tiers of cooldowns, pretty much
2025-06-01 15:55:11 -07:00
9b3120c47b rewrite mknew to inherit fields before init
I am horrified to admit that C++'s constructor static initialization
list syntax abruptly makes sense to me and I understand the problem
it is trying to solve
2025-06-01 15:53:50 -07:00
abee6d1206 fix skirmisher sparks 2025-05-31 23:44:36 -07:00

View File

@ -29,23 +29,33 @@ end
-- if tt.init is defined, generated
-- new calls tt.init(ret) after
-- ret is definitely not nil,
-- before calling setmetatable.
-- after calling setmetatable.
-- use to initialize mutables.
--
-- if there was a previous new,
-- it is invoked on the new
-- object *after* more, because
-- this works better with the
-- `more` impls i use.
-- it is invoked before
-- setting tt's metatable, so
-- each new will see its
-- inheritance chain.
function mknew(tt)
local mt,oldnew,more = {__index=tt},tt.new,rawget(tt, "init")
local mt,oldinit,more = {__index=tt},tt.superinit,rawget(tt, "init")
tt.new=function(ret)
if(not ret) ret = {}
if(more) more(ret)
if(oldnew) oldnew(ret)
ret.new = false
setmetatable(ret, mt)
if(oldinit) oldinit(ret)
if (more) more(ret)
return ret
end
if oldinit and more then
tt.superinit = function(ret)
oldinit(ret)
more(ret)
end
elseif more then
tt.superinit = more
end
return tt
end
@ -520,8 +530,6 @@ ship_m = mknew{
shieldpenalty = 0x0.012c, --5s
shield_refresh_ready = 0,
slip = true, -- most enemies slide
xmomentum = 0,
ymomentum = 0,
@ -605,21 +613,13 @@ function ship_m:move()
self:maybe_shoot(self.main_gun)
if (shoot_spec1 and self.special_guns) self:maybe_shoot(self.special_guns[1])
if (shoot_spec2 and self.special_guns) self:maybe_shoot(self.special_guns[2])
if (dx ~= 0 or dy ~= 0) spark(self.sparks, self.x + 4*self.size, self.y + 4*self.size, dx*2.5, dy*2.5, self.sparkodds)
spark(self.sparks, self.x + 4*self.size, self.y + 4*self.size, dx*2.5, dy*2.5, self.sparkodds)
self.xmomentum = self:calc_velocity(self.xmomentum, dx)
self.ymomentum = self:calc_velocity(self.ymomentum, dy)
self.x += self.xmomentum
self.y += self.ymomentum
-- "scrolling" behavior
if self.slip then
self.y += scrollrate
if self.y >= 128 then
self:die()
return true
end
end
return false
end
@ -719,6 +719,10 @@ bullet_base = mknew{ }
gun_base = mknew{
shoot_ready = -32768,
new_clip = -32768,
clip_size = false,
clip_remain = 0,
clip_interval = 0x0.80,
icon = 20,
ammobonus = 1,
@ -849,15 +853,75 @@ end
function gun_base:shoot(x, y)
if (gframe < self.shoot_ready) return false
local csz,crm = self.clip_size, self.clip_remain
if csz then
if crm < csz and gframe >= self.new_clip then
self.clip_remain = csz
self.new_clip = gframe + self.clip_interval
elseif crm == 0 then
return false
end
end
if self.ammo then
if (self.ammo <= 0) return false
self.ammo -= 1
end
if csz then
self.clip_remain -= 1
end
self.shoot_ready = gframe + self.cooldown
self:actually_shoot(x, y)
return true
end
trig_gun = mknew(gun_base.new{
veloc = 1,
aim = 0.75, -- down; 0.25 is up
shot_idx = 0,
-- shots: list<list<[3]num>>
-- describing a cycling
-- firing pattern. shot_idx
-- tracks offset into pattern.
-- each nested list: a burst
-- of shots to fire; takes
-- 1 ammo; sequential
-- each shot: angle (turns,
-- relative to `aim`),
-- velocity, firing x-offset;
-- if velocity is nil, use
-- self.veloc instead;
-- if x-offset is nil, use 0
init = function(self)
if (not self.shots) self.shots = {{{0}}}
end
})
function trig_gun:actually_shoot(x, y)
local shots,veloc,aim,munition = self.shots,self.veloc,self.aim,self.munition
local idx = self.shot_idx % #shots + 1
self.shot_idx = idx
shots = shots[idx]
for s in all(shots) do
local a,v,xo = unpack(s)
v = v or veloc
a += aim
-- todo: switch munition
-- depending on angle
-- (allows for non-round
-- sprites and hitboxes on
-- shots from guns with
-- widely varying angles)
local m = munition.new{}
-- todo: automatically make
-- high velocity shots do
-- multiple collision checks
m.dy = sin(a) * veloc
m.dx = cos(a) * veloc
m:spawn_at(x+(xo or 0), y)
end
end
-->8
-- bullets and guns
@ -876,8 +940,6 @@ zap_e = mknew(bullet_base.new{
y_off = 8,
damage = 1,
dx = 0, -- px/frame
dy = 4,
hitship = const_fxn(true),
@ -886,19 +948,21 @@ zap_e = mknew(bullet_base.new{
zap_p = mknew(zap_e.new{
sprite = 8,
dy = -8,
y_off = 0,
category = player_blt_cat,
})
zap_gun_e = mknew(gun_base.new{
zap_gun_e = mknew(trig_gun.new{
cooldown = 0x0.0020, -- frames between shots
veloc = 4,
munition = zap_e,
})
zap_gun_p = mknew(zap_gun_e.new{
icon = 19,
munition = zap_p,
veloc = 8,
aim = 0.25,
hdr = "mAIN gUN",
})
@ -1074,7 +1138,6 @@ vulcan_p = mknew(vulcan_e.new{
vulcan_gun_e = mknew(gun_base.new{
icon = 37,
enemy = false,
cooldown = 0x0.0003, -- frames between shots
ammo = nil,
maxammo = nil,
@ -1092,6 +1155,14 @@ vulcan_gun_e = mknew(gun_base.new{
end
})
machine_gun_e = mknew(vulcan_gun_e.new{
icon = 38,
clip_size = 12,
clip_interval = 0x0.005a,
dxs = {0, 0},
xoffs = {1, -1},
})
vulcan_gun_p = mknew(vulcan_gun_e.new{
munition=vulcan_p,
maxammo = 100,
@ -1156,7 +1227,6 @@ player = mknew(ship_m.new{
thrust = 0.1875, -- momentum added from button
ymin = 0, ymax = 120, -- stay on screen
drag = 0.0625, -- momentum lost per frame
slip = false, -- does not slide down screen
act = function(self) -- fetch buttons
local b,th = btn(),self.thrust
local blr = b&0x3
@ -1312,7 +1382,6 @@ chasey = mknew(ship_m.new{
maxspd = 2,
thrust = 0.2,
drag = 0.075,
slip = true,
init = function(ship)
ship.main_gun=ship.main_gun or zap_gun_e.new{}
@ -1340,7 +1409,6 @@ xl_chasey=mknew(chasey.new{
hp = 19.5,
shield = 5,
boss = true,
slip = false,
act = function(self)
local dx,dy,shoot_spec,shoot_main = chasey.act(self)
if (self.y < 4) dy=self.thrust
@ -1351,9 +1419,6 @@ xl_chasey=mknew(chasey.new{
sspr(40, 0, 8, 8, self.x, self.y, 16, 16)
pal()
end,
init = function(ship)
ship.main_gun=ship.main_gun or zap_gun_e.new{}
end,
})
-- flotilla ships
@ -1365,16 +1430,20 @@ ship_f = mknew(ship_m.new{
-- no sparks
hp = 0.5,
xp = 0x0.0001,
fire_off_x = 4,
fire_off_y = 4,
maxspd = 3,
thrust = 0.1,
drag = 0.05,
slip = false,
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
end,
init = function(self)
if (self.gun_proto) self.main_gun = self.gun_proto.new()
end
})
ship_mook = mknew(ship_f.new{
@ -1388,12 +1457,14 @@ ship_defender = mknew(ship_f.new{
ship_turret = mknew(ship_f.new{
sprite=106,
xp = 0x0.0002,
gun_proto = machine_gun_e,
})
ship_skirmisher = mknew(ship_f.new{
sprite=107,
xp = 0x0.0004,
spark = smokespark,
sparkodds = 4,
sparks = smokespark,
sparkodds = 3,
fire_off_y = 7,
})
function rnd_spawn_loc()
@ -1695,15 +1766,15 @@ function spark_particle:draw()
end
function spark(sprs, x, y, dx, dy, odds, fg)
if (sprs==nil or flr(rnd(odds)) ~= 0) return
if (sprs==nil or flr(rnd(odds) or (abs(dx) < 0.5 and abs(dy))) ~= 0) return
local target = fg and intangibles_fg or intangibles_bg
target:push_back(spark_particle.new{
x = x + rnd(4) - 2,
y = y + rnd(4) - 2,
sprs = sprs,
sidx = 1,
dx = dx + rnd(2) - 1,
dy = dy + rnd(2) - 1,
dx = dx * rnd(2),
dy = dy * rnd(2),
})
end
-->8