/// <summary> /// Executes when a collison occurs with another GameObject /// </summary> /// <param name="collisonName"></param> /// <param name="other"></param> /// <returns> /// <c>true</c> if the object is to be deleted /// </returns> public override bool OnCollide(CollisionPairEvaluator.Name collisonName, GameObject other) { bool willBeDeleted = false; // Wall vs UFO if (collisonName == CollisionPairEvaluator.Name.Wall_vs_UFO) { // Destroy self... // But only if the UFO is moving right toward the right wall bool approachingRightWall = this.speed > 0.0f && this.X < other.X; // Or if the UFO is moving left toward the left wall bool approachingLeftWall = this.speed <0.0f && this.X> other.X; if (approachingLeftWall || approachingRightWall) { willBeDeleted = true; } } // PlayerLaser vs UFO else if (collisonName == CollisionPairEvaluator.Name.PlayerLaser_vs_UFO) { willBeDeleted = true; // Play the death sound this.sndDeath.Play(); // Create small explosion DeadPlayerLaser smallExplosion = new DeadPlayerLaser(this.X, this.Y, 1.0f); } return(willBeDeleted); }
/// <summary> /// Executes when a collison occurs with another GameObject /// </summary> /// <param name="collisonName"></param> /// <param name="other"></param> /// <returns> /// <c>true</c> if the object is to be deleted /// </returns> public override bool OnCollide(CollisionPairEvaluator.Name collisonName, GameObject other) { bool willBeDeleted = false; // PlayerLaser vs AlienLaser if (collisonName == CollisionPairEvaluator.Name.PlayerLaser_vs_AlienLaser) { willBeDeleted = true; } // Player vs AlienLaser else if (collisonName == CollisionPairEvaluator.Name.Player_vs_AlienLaser) { willBeDeleted = true; // Create small explosion DeadPlayerLaser smallExplosion = new DeadPlayerLaser(this.X, this.Y); smallExplosion.SetColor(Colors.Green); // Move up. This is important! // Removing this line will make the Aliens rain laser everywhere! GameObject parent = this.Parent as GameObject; parent.SetPosition(parent.X, parent.Y + this.Height); } // AlienLaser vs Shields else if (collisonName == CollisionPairEvaluator.Name.AlienLaser_vs_Shield) { willBeDeleted = true; // Create small explosion DeadPlayerLaser smallExplosion = new DeadPlayerLaser(this.X, this.Y); smallExplosion.SetColor(Colors.Green); } // AlienLaser vs WallBottom else if (collisonName == CollisionPairEvaluator.Name.AlienLaser_vs_WallBottom) { willBeDeleted = true; // Create small explosion DeadPlayerLaser smallExplosion = new DeadPlayerLaser(this.X, this.Y); smallExplosion.SetColor(Colors.Green); } return(willBeDeleted); }
/// <summary> /// Executes when a collison occurs with another GameObject /// </summary> /// <param name="collisonName"></param> /// <param name="other"></param> /// <returns> /// <c>true</c> if the object is to be deleted /// </returns> public override bool OnCollide(CollisionPairEvaluator.Name collisonName, GameObject other) { bool willBeDeleted = false; // Laser vs. Aliens if (collisonName == CollisionPairEvaluator.Name.PlayerLaser_vs_Alien) { willBeDeleted = true; } // Laser vs. Top Wall else if (collisonName == CollisionPairEvaluator.Name.PlayerLaser_vs_WallTop) { willBeDeleted = true; // Create small explosion DeadPlayerLaser smallExplosion = new DeadPlayerLaser(this.X, this.Y); } // Laser vs Shield else if (collisonName == CollisionPairEvaluator.Name.PlayerLaser_vs_Shield) { willBeDeleted = true; // Create small explosion DeadPlayerLaser smallExplosion = new DeadPlayerLaser(this.X, this.Y); smallExplosion.SetColor(Colors.Green); } // Laser vs. UFO else if (collisonName == CollisionPairEvaluator.Name.PlayerLaser_vs_UFO) { willBeDeleted = true; } // PlayerLaser vs AlienLaser else if (collisonName == CollisionPairEvaluator.Name.PlayerLaser_vs_AlienLaser) { willBeDeleted = true; // Create small explosion DeadPlayerLaser smallExplosion = new DeadPlayerLaser(this.X, this.Y); smallExplosion.SetColor(Colors.White); } return(willBeDeleted); }