micro-optimize bullet details
Shots that miss are most likely to not be there yet, so check Y-top first. If I assume shots will never be larger than 16 pixels per side, there is no reason to check the ship's genuine width and height.
This commit is contained in:
		| @@ -775,7 +775,7 @@ end | |||||||
| function bullet_base:move() | function bullet_base:move() | ||||||
|  local x,y = self.x + self.dx, self.y+self.dy |  local x,y = self.x + self.dx, self.y+self.dy | ||||||
|  self.x,self.y=x,y |  self.x,self.y=x,y | ||||||
|  return (y<=128) and (y >= -(self.height<<3)) and (x <= 128) and (x >= -(self.width<<3)) |  return (y<=128) and (y >= -16) and (x <= 128) and (x >= -16) | ||||||
| end | end | ||||||
|  |  | ||||||
| function bullet_base:draw() | function bullet_base:draw() | ||||||
| @@ -1351,11 +1351,11 @@ end | |||||||
|  |  | ||||||
| -- box: x1, y1, x2, y2 | -- box: x1, y1, x2, y2 | ||||||
| function collides(b1, b2) | function collides(b1, b2) | ||||||
| 	return  | 	return | ||||||
| 	  b1.x1<=b2.x2 |    b1.y1<=b2.y2 | ||||||
| 	  and b1.y1<=b2.y2 |  | ||||||
| 	  and b1.x2>=b2.x1 |  | ||||||
| 	  and b1.y2>=b2.y1 | 	  and b1.y2>=b2.y1 | ||||||
|  | 	  and b1.x1<=b2.x2 | ||||||
|  | 	  and b1.x2>=b2.x1 | ||||||
| end | end | ||||||
|  |  | ||||||
| collider = mknew{ | collider = mknew{ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user