Use eship_collider for ship collisions, too.
This commit is contained in:
		| @@ -238,14 +238,17 @@ function updategame() | |||||||
|   lst:strip(call_move) |   lst:strip(call_move) | ||||||
|  end |  end | ||||||
|  |  | ||||||
|  | 	-- eship collider will be used | ||||||
|  |  -- both for pship and pbullets. | ||||||
|  |  local eship_collider = collider.new{from=eships} | ||||||
|  |  | ||||||
|  if not ps.dead then |  if not ps.dead then | ||||||
|   ps:move() |   ps:move() | ||||||
|   local pbox = hurtbox(ps) |   local pbox = hurtbox(ps) | ||||||
|   eships:strip(function(es) |   for es in all(eship_collider:get_collisions(pbox)) do | ||||||
|    if(not collides(pbox, hurtbox(es))) return |  | ||||||
|    ps:hitship(es) |    ps:hitship(es) | ||||||
|    return es:hitship(ps) |    if(es:hitship(ps)) eship_collider:yoink(es) | ||||||
|   end) |   end | ||||||
|   ebullets:strip(function(eb) |   ebullets:strip(function(eb) | ||||||
|    -- loopify this when split moves implemented |    -- loopify this when split moves implemented | ||||||
|    eb:move() |    eb:move() | ||||||
| @@ -257,12 +260,8 @@ function updategame() | |||||||
|   ebullets:strip(call_move) |   ebullets:strip(call_move) | ||||||
|  end |  end | ||||||
|  |  | ||||||
| 	-- many bullets and many enemy ships; |  | ||||||
| 	-- use bucket collider for efficiency |  | ||||||
|  local eship_collider = collider.new{from=eships} |  | ||||||
|  |  | ||||||
|  pbullets:strip(function(pb) |  pbullets:strip(function(pb) | ||||||
|   for es in all(eship_collider:get_collisions(pb)) do |   for es in all(eship_collider:get_collisions(hurtbox(pb))) do | ||||||
|    if (es:hitbullet(pb)) eship_collider:yoink(es) |    if (es:hitbullet(pb)) eship_collider:yoink(es) | ||||||
|    if (pb:hitship(es)) return true |    if (pb:hitship(es)) return true | ||||||
|   end |   end | ||||||
| @@ -1469,10 +1468,9 @@ function collider:yoink(item) | |||||||
|  end |  end | ||||||
| end | end | ||||||
|  |  | ||||||
| function collider:get_collisions(item) | function collider:get_collisions(box) | ||||||
|  local found = { } |  local found = { } | ||||||
|  local seen = { } |  local seen = { } | ||||||
|  local box = hurtbox(item) |  | ||||||
|  local bucket_ids = collider_indexes(box) |  local bucket_ids = collider_indexes(box) | ||||||
|  for b_idx in all(bucket_ids) do |  for b_idx in all(bucket_ids) do | ||||||
|   local bucket = self[b_idx] |   local bucket = self[b_idx] | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user