bullet microoptimization and velocity fix
This commit is contained in:
		| @@ -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 | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user