skip call to sparks if there are no sparks
Then don't check for nil spark colors in sparks itself. Also uses a more verbose but more efficient exit check, and fixes a bug.
This commit is contained in:
		| @@ -539,7 +539,7 @@ function ship_m:move() | ||||
|  if (self.dead) return; | ||||
|  self:refresh_shield() | ||||
|  local dx, dy, shoot_spec1, shoot_spec2 = self:act() | ||||
|  local sg, xm, ym = self.special_guns, self.xmomentum, self.ymomentum | ||||
|  local sg, xm, ym, sp = self.special_guns, self.xmomentum, self.ymomentum, self.sparks | ||||
|  dx = self:constrain(self.x, xm, self.xmin, self.xmax, dx) | ||||
|  dy = self:constrain(self.y, ym, self.ymin, self.ymax, dy) | ||||
|  self:maybe_shoot(self.main_gun) | ||||
| @@ -547,7 +547,7 @@ function ship_m:move() | ||||
|   if (shoot_spec1) self:maybe_shoot(sg[1]) | ||||
|   if (shoot_spec2) self:maybe_shoot(sg[2]) | ||||
|  end | ||||
|  spark(self.sparks, self.x + 4*self.size, self.y + 4*self.size, dx*2.5, dy*2.5, self.sparkodds) | ||||
|  if(sp) spark(sp, self.x + 4*self.size, self.y + 4*self.size, dx*2.5, dy*2.5, self.sparkodds) | ||||
|  xm = self:calc_velocity(xm, dx) | ||||
|  ym = self:calc_velocity(ym, dy) | ||||
|  | ||||
| @@ -1637,7 +1637,7 @@ function spark_particle:draw() | ||||
| end | ||||
|  | ||||
| function spark(sprs, x, y, dx, dy, odds, fg) | ||||
|  if (sprs==nil or flr(rnd(odds) or (abs(dx) < 0.5 and abs(dy))) ~= 0) return | ||||
|  if ((dx > -0.5 and dx < 0.5 and dy > -0.5 and dy < 0.5) or rnd(odds) >= 1) return | ||||
|  local target = fg and intangibles_fg or intangibles_bg | ||||
|  target[#target+1] = spark_particle.new{ | ||||
|   x = x + rnd(4) - 2, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user