Ejemplo n.º 1
0
        private void CollisionHandler(BasicSprite s1, BasicSprite s2)
        {
            //Check to see if a bullet or ship is hitting a target object
            BasicSprite collidable;
            BasicSprite target;

            if ((s1.GetType() == typeof(ShipSprite)) || (s1.GetType() == typeof(BulletSprite)))
            {
                collidable = s1;
                target     = s2;
            }
            else
            {
                collidable = s2;
                target     = s1;
            }

            //remove the bullet/ship from collision checking and take off list
            collidable.Visible      = false; //will be ignored for future collisions
            collidable.DurationOver = true;  //will be removed at next update
            //if it was a ship, take away a life and restart the ship
            if (collidable.GetType() == typeof(ShipSprite))
            {
                shipSounds   = Sounds.ShipExplode;
                ship.Visible = false;
                //remove the ship from the sprite manager
                ship.DurationOver = true;
                //subtract a life
                livesRemaining--;
                //now make a new ship
                NewShip();
            }
            //Blow up object
            Destroy(target);
        }
Ejemplo n.º 2
0
 private void Destroy(BasicSprite sprite)
 {
     totalTargets--;
     gameSounds = 0; //clear out game sounds
     //sprite type should be: donut, pyramid, cube, or sphere
     if (sprite.GetType() == typeof(DonutSprite))
     {
         for (int i = 0; i < 3; i++)
         {
             s           = new PyramidSprite(pyramidTileSet);
             s.PositionY = sprite.PositionY;
             s.PositionX = sprite.PositionX;
             s.Angle     = (float)rnd.Next(0, 359);
             s.Velocity  = (float)rnd.Next(30, 200);
             sm.AddSprite(s);
             totalTargets++;
             gameSounds |= Sounds.DonutExplode;
         }
         totalScore += 10;
     }
     else if (sprite.GetType() == typeof(PyramidSprite))
     {
         for (int i = 0; i < 2; i++)
         {
             s           = new CubeSprite(cubeTileSet);
             s.PositionY = sprite.PositionY;
             s.PositionX = sprite.PositionX;
             s.Angle     = (float)rnd.Next(0, 359);
             s.Velocity  = (float)rnd.Next(30, 200);
             s.Visible   = true;
             sm.AddSprite(s);
             totalTargets++;
             gameSounds |= Sounds.PyramidExplode;
         }
         totalScore += 20;
     }
     else if (sprite.GetType() == typeof(CubeSprite))
     {
         for (int i = 0; i < 2; i++)
         {
             s           = new SphereSprite(sphereTileSet);
             s.PositionY = sprite.PositionY;
             s.PositionX = sprite.PositionX;
             s.Angle     = (float)rnd.Next(0, 359);
             s.Velocity  = (float)rnd.Next(50, 200);
             sm.AddSprite(s);
             totalTargets++;
             gameSounds |= Sounds.CubeExplode;
         }
         totalScore += 10;
     }
     else if (sprite.GetType() == typeof(SphereSprite))
     {
         totalScore += 10;
         gameSounds |= Sounds.SphereExplode;
     }
     sprite.Visible      = false; //will be ignored for future collisions
     sprite.DurationOver = true;  //will be removed at next update
 }
 private void Destroy(BasicSprite sprite)
 {
     totalTargets--;
     gameSounds = 0; //clear out game sounds
     //sprite type should be: donut, pyramid, cube, or sphere
     if (sprite.GetType() == typeof(DonutSprite)) {
         for(int i = 0; i < 3; i++) {
             s = new PyramidSprite(pyramidTileSet);
             s.PositionY = sprite.PositionY;
             s.PositionX = sprite.PositionX;
             s.Angle = (float)rnd.Next(0, 359);
             s.Velocity = (float) rnd.Next(30, 200);
             sm.AddSprite(s);
             totalTargets++;
             gameSounds |= Sounds.DonutExplode;
         }
         totalScore += 10;
     }
     else if (sprite.GetType() == typeof(PyramidSprite)) {
         for(int i = 0; i < 2; i++) {
             s = new CubeSprite(cubeTileSet);
             s.PositionY = sprite.PositionY;
             s.PositionX = sprite.PositionX;
             s.Angle = (float)rnd.Next(0, 359);
             s.Velocity = (float) rnd.Next(30, 200);
             s.Visible = true;
             sm.AddSprite(s);
             totalTargets++;
             gameSounds |= Sounds.PyramidExplode;
         }
         totalScore += 20;
     }
     else if (sprite.GetType() == typeof(CubeSprite)) {
         for(int i = 0; i < 2; i++) {
             s = new SphereSprite(sphereTileSet);
             s.PositionY = sprite.PositionY;
             s.PositionX = sprite.PositionX;
             s.Angle = (float)rnd.Next(0, 359);
             s.Velocity = (float) rnd.Next(50, 200);
             sm.AddSprite(s);
             totalTargets++;
             gameSounds |= Sounds.CubeExplode;
         }
         totalScore += 10;
     }
     else if (sprite.GetType() == typeof(SphereSprite)) {
         totalScore += 10;
         gameSounds |= Sounds.SphereExplode;
     }
     sprite.Visible = false; //will be ignored for future collisions
     sprite.DurationOver = true; //will be removed at next update
 }
        private void CollisionHandler(BasicSprite s1, BasicSprite s2)
        {
            //Check to see if a bullet or ship is hitting a target object
            BasicSprite collidable;
            BasicSprite target;

            if ((s1.GetType() == typeof(ShipSprite)) || (s1.GetType() == typeof(BulletSprite))) {
                collidable = s1;
                target = s2;
            }
            else {
                collidable = s2;
                target = s1;
            }

            //remove the bullet/ship from collision checking and take off list
            collidable.Visible = false; //will be ignored for future collisions
            collidable.DurationOver = true; //will be removed at next update
            //if it was a ship, take away a life and restart the ship
            if (collidable.GetType() == typeof(ShipSprite)) {
                shipSounds = Sounds.ShipExplode;
                ship.Visible = false;
                //remove the ship from the sprite manager
                ship.DurationOver = true;
                //subtract a life
                livesRemaining--;
                //now make a new ship
                NewShip();
            }
            //Blow up object
            Destroy(target);
        }