From 929f47fc78842d4ddf4ff0924e9ada4eb54ea51a Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Sat, 21 Jun 2025 17:33:42 -0700 Subject: [PATCH] bullet microoptimization and velocity fix --- vacuum_gambit.p8 | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/vacuum_gambit.p8 b/vacuum_gambit.p8 index b5c42ce..9438d2b 100644 --- a/vacuum_gambit.p8 +++ b/vacuum_gambit.p8 @@ -823,10 +823,13 @@ function bullet_base:hitship(_) end function bullet_base:move() - self.x += self.dx - self.y += self.dy - if (self.f) self.f -= 1 - return (self.y > 130) or (self.y < -self.height*8) or (self.f and self.f < 0) or (self.x > 128) or (self.x < -self.width*8) + local x,y,f = self.x + self.dx, self.y+self.dy,self.f + self.x,self.y=x,y + if f then + self.f = f-1 + if (f <= 0) return true + end + return (y> 130) or (y < -(self.height<<3)) or (x > 128) or (x < -(self.width<<3)) end function bullet_base:draw() @@ -868,25 +871,20 @@ function gun_base:actually_shoot(x, y) self.shot_idx = idx shots = shots[idx] for s in all(shots) do - local a,xo,v = unpack(s) - v = v or veloc - xo = xo or 0 + local a,xo,v = s[1]+aim, s[2] or 0, s[3] or veloc -- reverse x-offset for negative base angle if (aim < 0) xo = -xo - 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) + local m = munition.new{ + dx=sin(a)*v, + dy=cos(a)*v + } + m:spawn_at(x+xo, y) end end