/// <summary> /// This method gets called when a collision occurs /// that this object observes (subscribes to) /// </summary> /// <param name="collisionName"></param> public void OnCollisionNotified(CollisionPairEvaluator.Name collisionName) { // Assuming Wall_vs_UFO or PlayerLaser_vs_UFO (either way, the UFO died) // It no longer has a UFO reference this.ufoReference = null; if (collisionName == CollisionPairEvaluator.Name.PlayerLaser_vs_UFO) { // Award points GameSessionData.Active.AddScore(this.ChooseRandomScore()); } }
// // Constructors // public UFOCoordinator() : base() { this.SetName(Name.UFOCoordinator); this.Collider.Color = Colors.Yellow; this.SetPosition(-30.0f, UFOCoordinator.SpawnY); this.ufoLaunchEvent = null; this.ufoReference = null; // Load the UFO sounds this.sndUfo = AudioSourceManager.Self.Find(AudioSource.Name.UFOBeep); this.sndUfoDeath = AudioSourceManager.Self.Find(AudioSource.Name.DeathUFO); // Initialize possible points table this.possiblePoints = new int[NUM_POINT_ENTIRES]; this.possiblePoints[0] = 50; this.possiblePoints[1] = 100; this.possiblePoints[2] = 150; this.possiblePoints[3] = 300; }
/// <summary> /// Create a new UFO, does NOT schedule anything /// </summary> private void SpawnNewUFO() { // Decide randomly whether to spawn the UFO left or right HorizontalDirection.Name leftOrRight = HorizontalDirection.ConvertFromInt(Randomizer.RandomRange(0, 2)); float xSpawn = 0.0f; if (leftOrRight == HorizontalDirection.Name.Left) { xSpawn = UFOCoordinator.SpawnLeftX; } else { xSpawn = UFOCoordinator.SpawnRightX; } // Create the UFO UFO ufo = new UFO(xSpawn, UFOCoordinator.SpawnY, leftOrRight, this.sndUfo, this.sndUfoDeath); this.AddChild(ufo); GameObjectManager.Active.Attach(ufo); // Keep a reference ufoReference = ufo; }