Exemple #1
0
        public override void OnCollision(GameObject other)
        {
            if (other is Ball || other is Player || other is Turret) // If the obj is Ball or Player
            {
                if (this.position == other.Position)
                {
                    Random r = new Random();
                    this.position = this.position + new Vector2(r.Next(-9, 10), r.Next(-9, 10));
                }
                //x og y difference between ball and object
                float xDiff = (this.Position.X + this.CollisionCircle.Radius) - (other.Position.X + other.CollisionCircle.Radius);
                float yDiff = (this.Position.Y + this.CollisionCircle.Radius) - (other.Position.Y + other.CollisionCircle.Radius);

                float tempXDiff = xDiff;
                float tempYDiff = yDiff;

                //to work with positive numbers
                if (xDiff < 0)
                {
                    tempXDiff = -xDiff;
                }
                if (yDiff < 0)
                {
                    tempYDiff = -yDiff;
                }

                //a^2 + b^2
                double tempTotalDiff = tempXDiff * tempXDiff + tempYDiff * tempYDiff;

                //lenght of the hyp
                float hyp = (float)Math.Sqrt(tempTotalDiff);

                //Scale
                float sizeFactor = 6 / hyp;

                //ajusts the x and y speed to the ball
                this.xSpeed = xDiff * sizeFactor;
                this.ySpeed = yDiff * sizeFactor;
                this.xSpeed = xSpeed + 0.15f;
                this.ySpeed = ySpeed + 0.15f;
            }
        }
Exemple #2
0
        public override void OnCollision(GameObject other)
        {
            if (other is Player) // If the colliding GameObject is of the type, Player
            {

                switch (powerType) //Switch-case, for the different powerTypes
                {
                    case PowerType.Speed:
                        {
                            Player tempPlayer = (Player)other;
                            tempPlayer.PowerOn = true; // Sets the player's bool (powerOn) to true.
                            tempPlayer.PowerUp = this.powerType; // Sets this powerType to the Player
                            tempPlayer.Duration = 50f; // Sets the duration of the powerUp, to the player
                        }
                        break;
                    case PowerType.StickyBall:
                        {
                            Player tempPlayer = (Player)other;
                            tempPlayer.PowerOn = true; // Sets the player's bool (powerOn) to true.
                            tempPlayer.PowerUp = this.powerType; // Sets this powerType to the Player
                            tempPlayer.Duration = 50f; // Sets the duration of the powerUp, to the player
                        }
                        break;
                    case PowerType.MultiBall:
                        {
                            Player tempPlayer = (Player)other;
                            tempPlayer.PowerOn = true; // Sets the player's bool (powerOn) to true.
                            tempPlayer.PowerUp = this.powerType; // Sets this powerType to the Player
                            tempPlayer.Duration = 50f; // Sets the duration of the powerUp, to the player
                        }
                        break;
                    default:
                        break;
                }
                Game1.RemoveObjects.Add(this); // Removes the PowerUp, which is collected from the field
                InGame.PowerUpSpawned = false; // Resets the PowerUpSpawned, so it can spawn a new PowerUp
            }
        }
Exemple #3
0
 public override void OnCollision(GameObject other)
 {
 }
Exemple #4
0
 public abstract void OnCollision(GameObject other);
Exemple #5
0
 /// <summary>
 /// Returns true, if the GameObject is colliding with the other GameObject
 /// </summary>
 /// <param name="other">GameObject to check collising with</param>
 /// <returns></returns>
 public bool IsCollidingWith(GameObject other)
 {
     return CollisionCircle.IntersectsWith(other.CollisionCircle);
 }
Exemple #6
0
 public override void OnCollision(GameObject other)
 {
     if (other is PowerUp)
     {
         powerOn = true;
     }
     if (other is Turret)
     {
         this.position = lastPosition;
     }
     if (other is Ball)
     {
         lastBallToHit = (Ball)other; // Finds which ball was last hit
     }
 }