bullet microoptimization and velocity fix
This commit is contained in:
		| @@ -823,10 +823,13 @@ function bullet_base:hitship(_) | |||||||
| end | end | ||||||
|  |  | ||||||
| function bullet_base:move() | function bullet_base:move() | ||||||
|  self.x += self.dx |  local x,y,f = self.x + self.dx, self.y+self.dy,self.f | ||||||
|  self.y += self.dy |  self.x,self.y=x,y | ||||||
|  if (self.f) self.f -= 1 |  if f then | ||||||
|  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) |   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 | end | ||||||
|  |  | ||||||
| function bullet_base:draw() | function bullet_base:draw() | ||||||
| @@ -868,25 +871,20 @@ function gun_base:actually_shoot(x, y) | |||||||
|  self.shot_idx = idx |  self.shot_idx = idx | ||||||
|  shots = shots[idx] |  shots = shots[idx] | ||||||
|  for s in all(shots) do |  for s in all(shots) do | ||||||
|   local a,xo,v = unpack(s) |   local a,xo,v = s[1]+aim, s[2] or 0, s[3] or veloc | ||||||
|   v = v or veloc |  | ||||||
|   xo = xo or 0 |  | ||||||
|   -- reverse x-offset for negative base angle |   -- reverse x-offset for negative base angle | ||||||
|   if (aim < 0) xo = -xo |   if (aim < 0) xo = -xo | ||||||
|   a += aim |  | ||||||
|   -- todo: switch munition |   -- todo: switch munition | ||||||
|   --  depending on angle |   --  depending on angle | ||||||
|   --  (allows for non-round |   --  (allows for non-round | ||||||
|   --   sprites and hitboxes on |   --   sprites and hitboxes on | ||||||
|   --   shots from guns with |   --   shots from guns with | ||||||
|   --   widely varying angles) |   --   widely varying angles) | ||||||
|   local m = munition.new{} |   local m = munition.new{ | ||||||
|   -- todo: automatically make |    dx=sin(a)*v, | ||||||
|   -- high velocity shots do |    dy=cos(a)*v | ||||||
|   -- multiple collision checks |   } | ||||||
|   m.dy = sin(a) * veloc |   m:spawn_at(x+xo, y) | ||||||
|   m.dx = cos(a) * veloc |  | ||||||
|   m:spawn_at(x+(xo or 0), y) |  | ||||||
|  end |  end | ||||||
| end | end | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user