// // Constructors // public CollisionSubscription() : base() { this.listOfSubscribers = new ContainerList(); this.collisionName = CollisionPairEvaluator.Name.UNINITIALIZED; }
// // Methods // /// <summary> /// Sets the name of this collison subscription /// </summary> /// <param name="newName"></param> public void SetName(CollisionPairEvaluator.Name newName) { this.collisionName = newName; }
/// <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; return(willBeDeleted); }
/// <summary> /// Set the name of this collision pair /// </summary> /// <param name="newName"></param> public void SetName(CollisionPairEvaluator.Name newName) { this.name = newName; this.subscription.SetName(newName); }
// // Methods // /// <summary> /// Notifies the subscriber that a collison happened /// </summary> /// <param name="collisonName"></param> public void NotifySubscriber(CollisionPairEvaluator.Name collisonName) { this.subscriber.OnCollisionNotified(collisonName); }
/// <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) { // Walls vs Aliens if (collisionName == CollisionPairEvaluator.Name.Wall_vs_Alien) { if (this.isGoingDown == false) { // Prepare the aliens to move downward // But only if the coordinator is moving right toward the right wall bool approachingRightWall = this.progressionSteps > 0.0f && this.Collider.X > Constants.SCREEN_CENTER_X; // Or if the coordinator is moving left toward the left wall bool approachingLeftWall = this.progressionSteps < 0.0f && this.Collider.X < Constants.SCREEN_CENTER_X; if (approachingLeftWall || approachingRightWall) { this.MoveDownward(); } } } // PlayerLaser vs Alien else if (collisionName == CollisionPairEvaluator.Name.PlayerLaser_vs_Alien) { // An alien died this.numberOfAliens--; // Get the new progression time this.progressionTime = this.SpeedUpFormula(this.TotalAliens - this.numberOfAliens); if (this.progressionTime < 0.0f) { this.progressionTime = 0.1f; } this.Animator.AssignNewIntervalTime(this.progressionTime); // Get new progression step float newProgressionDelta = this.ProgressionIncreaseFormula(this.TotalAliens - this.numberOfAliens); if (progressionSteps > 0.0f) // positive { this.progressionSteps += newProgressionDelta; } else // negative { this.progressionSteps -= newProgressionDelta; } if (this.isGoingDown == false) { this.Animator.AssignNewXChange(this.progressionSteps); } // Sync the movement with the sprite animations this.AnimatorSquid.AssignNewIntervalTime(this.progressionTime); this.AnimatorCrab.AssignNewIntervalTime(this.progressionTime); this.AnimatorOctopus.AssignNewIntervalTime(this.progressionTime); } // Player vs Alien else if (collisionName == CollisionPairEvaluator.Name.Player_vs_Alien) { // Player just died. Stop moving. this.StopMoving(); } // For AlienLaser vs anything else if (collisionName == CollisionPairEvaluator.Name.PlayerLaser_vs_AlienLaser || collisionName == CollisionPairEvaluator.Name.Player_vs_AlienLaser || collisionName == CollisionPairEvaluator.Name.AlienLaser_vs_Shield || collisionName == CollisionPairEvaluator.Name.AlienLaser_vs_WallBottom) { // A laser died. Allow more laser in the future. this.numberOfLasers--; if (this.numberOfLasers < 0) { this.numberOfLasers = 0; } // If specifically Player vs. AlienLaser if (collisionName == CollisionPairEvaluator.Name.Player_vs_AlienLaser) { // Player just died. Stop moving. this.StopMoving(); } } }
/// <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> abstract public bool OnCollide(CollisionPairEvaluator.Name collisonName, GameObject other);