-2
\$\begingroup\$

I am developing a game where I want to implement two or multiple time collision with single object.i mean if two bullets collide to a ship then only it will explode...

If a two bullet rectangles intersect with a single ship then ,ship will explode..Here is my collision code..

foreach (Enemy e in this.em.Enemies)
                {
                    if (e.boundingRectangle.Intersects(missiles[i].boundingRectangle))
                    {
                        shipHit = true;
                        pos = new Vector2(e.position.X, e.position.Y);
                        e.OnHit();

                        missiles[i].IsActive = false;
                        //count++;

                    }
                    //if (count == 2)
                    //{

                    //    break;
                    //}


                }

                }

please helpppppp.....

\$\endgroup\$
4
  • \$\begingroup\$ Please help us help you by rephrasing the question. \$\endgroup\$
    – Dialock
    Apr 14, 2014 at 16:56
  • \$\begingroup\$ I mean,when two bullets collide to a same ship,then only that ship will explode.,not with single bullet. \$\endgroup\$ Apr 14, 2014 at 18:07
  • \$\begingroup\$ So, if a ship gets hit twice you want it to explode right? If so, just make a counter in the class of the ship that holds the hits. If it's the right amount make it explode. \$\endgroup\$
    – Dries
    Apr 14, 2014 at 21:22
  • \$\begingroup\$ @stonemetal---yes it explodes on single hit.. \$\endgroup\$ Apr 15, 2014 at 3:44

1 Answer 1

1
\$\begingroup\$

If by your question you mean that a ship has to be hit twice (or multiple times) before exploding, simply give your ships hit points. Whenever a bullet collides, remove the bullet and decrement the hit point value.

When the hit points reach zero (or less), blow up the ship.

If, however, you mean that a ship explodes if, and only if two bullets collide with it at the same time, simply reset the ship's hit points back to maximum every time you have checked for all of the collisions.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for replying Jari,I have edited my question and there provided my collision code.Can u pls provide me any help,according to my code...Thanks again \$\endgroup\$ Apr 15, 2014 at 7:01

Not the answer you're looking for? Browse other questions tagged .