Пример #1
0
 public override void ExitCollision(GameObject other)
 {
     if (other is Player)
     {
         Player temp = other as Player;
         if (temp.IsFirstPlayer)
             collidedWithPlayer1 = false;
         else if (!temp.IsFirstPlayer)
             collidedWithPlayer2 = false;
     }
 }
Пример #2
0
 public override void OnCollision(GameObject other)
 {            
     if (other is Obstacles)
     {
         if (position.Y <= 20)
         {
             position.Y = 20;
         }
         else if (position.Y + CollisionRect.Height > other.Position.Y)
         {
             position.Y = other.Position.Y - CollisionRect.Height;
         }
     }
 }
Пример #3
0
 public override void OnCollision(GameObject other)
 {
 }
Пример #4
0
        public void HandlePickUp(GameObject pickUp)
        {
            if (pickUp is PickUp)
            {
                PickUp tempPick = pickUp as PickUp;
                #region PickUp's
                if ((pickUp as PickUp).PickUpPowerUp == PickUpType.BigPlayer)
                {
                    hasPowerUp = true;
                    PlayAnimation("BigPlayer");
                    currentPickUp = PickUpType.BigPlayer;
                    powerUpEnd = DateTime.Now.AddSeconds(tempPick.EffectTime);
                }
                if ((pickUp as PickUp).PickUpPowerUp == PickUpType.ColorChange)
                {
                    this.Color = new Color(
                         (byte)RandomPicker.Rnd.Next(0, 255),
                         (byte)RandomPicker.Rnd.Next(0, 255),
                         (byte)RandomPicker.Rnd.Next(0, 255));
                }
                if ((pickUp as PickUp).PickUpPowerUp == PickUpType.FastPlayer)
                {
                    hasPowerUp = true;
                    this.Speed += 300.0f;
                    currentPickUp = PickUpType.FastPlayer;
                    powerUpEnd = DateTime.Now.AddSeconds(tempPick.EffectTime);
                }
                if ((pickUp as PickUp).PickUpPowerUp == PickUpType.InverseControl)
                {
                    hasPowerUp = true;
                    inverseControl = true;
                    currentPickUp = PickUpType.InverseControl;
                    powerUpEnd = DateTime.Now.AddSeconds(tempPick.EffectTime);
                }
                if ((pickUp as PickUp).PickUpPowerUp == PickUpType.SlowPlayer)
                {
                    hasPowerUp = true;
                    this.Speed -= 250.0f;
                    currentPickUp = PickUpType.SlowPlayer;
                    powerUpEnd = DateTime.Now.AddSeconds(tempPick.EffectTime);
                }
                if ((pickUp as PickUp).PickUpPowerUp == PickUpType.SmallPlayer)
                {
                    hasPowerUp = true;
                    PlayAnimation("SmallPlayer");
                    currentPickUp = PickUpType.SmallPlayer;
                    powerUpEnd = DateTime.Now.AddSeconds(tempPick.EffectTime);

                }
                if ((pickUp as PickUp).PickUpPowerUp == PickUpType.xScore)
                {
                    if (this.isFirstPlayer)
                        GameWorld.Player1Score += 2;
                    else if (!this.isFirstPlayer)
                        GameWorld.Player2Score += 2;
                }
                #endregion
            }
        }
Пример #5
0
 public abstract void OnCollision(GameObject other);
Пример #6
0
        public override void OnCollision(GameObject other)
        {
            if (other is Obstacles)
            {
                Obstacles tempObstacle = other as Obstacles;
                if (!tempObstacle.IsMiddleLine)
                    this.velocity.Y *= -1;
            }
            if (other is Player && !collidedWithPlayer1 && !collidedWithPlayer2)
            {
                lastHitPlayer = other as Player;
                lastHitPlayer.Velocity = new Vector2(0, 0);
                if (lastHitPlayer.IsFirstPlayer)
                    collidedWithPlayer1 = true;
                else if (!lastHitPlayer.IsFirstPlayer)
                    collidedWithPlayer2 = true;

                float midBall = (this.CollisionRect.Y + this.CollisionRect.Height) - (this.CollisionRect.Height / 2);
                float midPlayer = (lastHitPlayer.CollisionRect.Y + lastHitPlayer.CollisionRect.Height) - (lastHitPlayer.CollisionRect.Height / 2);

                float deltaY = midBall - midPlayer;
                float lastDir = this.velocity.X;

                this.velocity = new Vector2(lastDir * -1, (deltaY) * 10);
            }
            if (other is PickUp)
            {
                HandlePickUp(other as PickUp);
            }
        }