/// <summary> /// Implement the collision between the bullet and a game component by /// making the bullet invisible. /// In case the colliding component is a space ship bullet, we'll /// randomly decide whether the bullet will be hit. /// </summary> /// <param name="i_OtherComponent">The component the bullet colided with</param> public override void Collided(XnaGamesInfrastructure.ObjectInterfaces.ICollidable i_OtherComponent) { bool collided = true; if (i_OtherComponent is Bullet) { // Randomly choose whether the bullet will be hit collided = Math.Round(new Random().NextDouble()) == 1; } if (collided) { base.Collided(i_OtherComponent); } }
/// <summary> /// Call the parent collided method and raise a PlayActionSoundEvent /// </summary> /// <param name="i_OtherComponent">The other component we collided with</param> public override void Collided(XnaGamesInfrastructure.ObjectInterfaces.ICollidable i_OtherComponent) { base.Collided(i_OtherComponent); onPlayActionSoundEvent(eSoundActions.MotherShipHit); }
/// <summary> /// Implement the collision between the bullet and a game component by /// changing the bullet to invisible and raising a BulletCollision event /// <param name="i_OtherComponent">The component the ship colided with</param> public override void Collided(XnaGamesInfrastructure.ObjectInterfaces.ICollidable i_OtherComponent) { base.Collided(i_OtherComponent); onBulletCollision(i_OtherComponent); }
/// <summary> /// Check for collision with a given component. /// </summary> /// <param name="i_OtherComponent">the component we want to check for collision /// against</param> /// <returns>true in case the bullet collides with the given component /// or false in case the given component is a space ship or there is /// no collision between the components </returns> public override bool CheckForCollision(XnaGamesInfrastructure.ObjectInterfaces.ICollidable i_OtherComponent) { return !(i_OtherComponent is IPlayer) && !(i_OtherComponent is SpaceShipBullet) && base.CheckForCollision(i_OtherComponent); }
/// <summary> /// Implement the component collision logic. /// In case we collided with a defend component we do nothing, /// otherwise we call the base logic. /// </summary> /// <param name="i_OtherComponent">The colliding component</param> public override void Collided(XnaGamesInfrastructure.ObjectInterfaces.ICollidable i_OtherComponent) { if (!(i_OtherComponent is IDefend)) { base.Collided(i_OtherComponent); onPlayActionSound(this.HitAction); } }