I am working on an Asteroids remake. When the player's bullets hit a large meteor, it should break apart into 2 smaller meteors. This works when the player is only firing one bullet, but when the player's weapon is upgraded, shooting multiple bullets, sometimes two bullets hit the same meteor at the same time, causing it to break into 4 smaller meteors, not 2 as intended.
Is there a way to cancel out one of the collisions when there are two simultaneous collisions - or a way to omit the creation of the unwanted extra meteors when two bullets hit the same meteor at the same time?
Here is how I have the collision detection set up currently:
Bullet.each_collision(Meteor1) do |bullet, meteor| Explosion.create(:x => meteor.x, :y => meteor.y) Meteor2.create(:x => meteor.x, :y => meteor.y) Meteor2.create(:x => meteor.x, :y => meteor.y) meteor.destroy bullet.destroy @score += 100 Sound["media/audio/explosion.ogg"].play(0.2) end
Following are screenshots demonstrating the situation:
In the first two images (above) the player fires one bullet at a time, the large meteor breaks into two smaller meteors, and the score increases by 100.
In the last two images, the player fires three bullets at a time, the large meteor breaks apart into four smaller meteors, and the score increases by 200, due to a simultaneous collision.