diff --git a/vacuum_gambit.p8 b/vacuum_gambit.p8 index fb8dc68..8ffb885 100644 --- a/vacuum_gambit.p8 +++ b/vacuum_gambit.p8 @@ -874,6 +874,54 @@ function gun_base:shoot(x, y) return true end +trig_gun = mknew(gun_base.new{ + veloc = 1, + aim = 0.25, --use 0.75 for a player gun + shot_idx = 0, + -- shots: list> + -- 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