Beispiel #1
0
 /// <summary>
 /// Save test results.
 /// </summary>
 /// <param name="collider"> The entity an entity collided with.</param>
 /// <param name="penetration"> The depth of the collision.</param>
 /// <param name="side"> The collision side.</param>
 /// <param name="oppositeSide"> The opposite collision side.</param>
 public void Write(Entity collider, int penetration, CollisionTester.CollisionSide side, CollisionTester.CollisionSide oppositeSide)
 {
     Collider     = collider;
     Penetration  = penetration;
     Side         = side;
     OppositeSide = oppositeSide;
 }
Beispiel #2
0
        /// <summary>
        /// Function gets called when a collision with this object occurs.
        /// </summary>
        /// <param name="ent"> Entity this object collides with.</param>
        /// <param name="penetration"> Amount of penetration.</param>
        /// <param name="side"> The side the objects collide on.</param>
        /// <param name="axis"> The axis that is being checked.</param>
        /// <param name="fromBounds"> Where the colliding entity came from.</param>
        public override void OnCollision(Entity ent, int penetration, CollisionTester.CollisionSide side, CollisionTester.Axis axis, Rectangle fromBounds)
        {
            // Check if the entity colliding is player and came from the bottom.
            if (ent is Player && side == CollisionTester.CollisionSide.BOTTOM && axis == CollisionTester.Axis.Y)
            {
                // Check if there is a powerup inside.
                if (_item != null)
                {
                    // Get the powerup.
                    PowerUp item = _item;

                    // Set the position of the powerup.
                    item.Position = Position;

                    // Call the spawn of the powerup.
                    item.OnSpawn();

                    // Add the powerup to the level.
                    Parent.AddEntity(item);

                    // Play wood animation.
                    Animations.Play((int)GiftBlockAnimation.WOOD);

                    // Remove item.
                    _item = null;
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Function gets called when a collision with this object occurs.
        /// </summary>
        /// <param name="ent"> Entity this object collides with.</param>
        /// <param name="penetration"> Amount of penetration.</param>
        /// <param name="side"> The side the objects collide on.</param>
        /// <param name="axis"> The axis that is being checked.</param>
        /// <param name="fromBounds"> Where the colliding entity came from.</param>
        public override void OnCollision(Entity ent, int penetration, CollisionTester.CollisionSide side, CollisionTester.Axis axis, Rectangle fromBounds)
        {
            // Check if the collider is a player.
            if (ent is Player)
            {
                // Get the player.
                Player _ent = (Player)ent;

                // Disable collision for this mushroom.
                Collidable = false;
                // Make mushroom none solid.
                Solid = false;

                // Add score.
                Parent.Score.IncreaseScore(1000);

                // If player is small make the player grow.
                if (_ent.PowerState == Player.SizeState.SMALL)
                {
                    _ent.Grow();
                }
                // If the player is big.
                else
                {
                    // Add the mushroom to the HUD.
                    Parent.Display.AddPowerUp(new Mushroom(Vector2.Zero, Width, Height, _content, Parent));
                }

                Destroy();
            }

            // Call base collision.
            base.OnCollision(ent, penetration, side, axis, fromBounds);
        }
Beispiel #4
0
        /// <summary>
        /// Function gets called when a collision with this object occurs.
        /// </summary>
        /// <param name="ent"> Entity this object collides with.</param>
        /// <param name="penetration"> Amount of penetration.</param>
        /// <param name="side"> The side the objects collide on.</param>
        /// <param name="axis"> The axis that is being checked.</param>
        /// <param name="fromBounds"> Where the colliding entity came from.</param>
        public override void OnCollision(Entity ent, int penetration, CollisionTester.CollisionSide side, CollisionTester.Axis axis, Rectangle fromBounds)
        {
            // Check if collision is a player and came from the bottom.
            if (ent is Player && side == CollisionTester.CollisionSide.BOTTOM && axis == CollisionTester.Axis.Y)
            {
                // Check if there are any coins left.
                if (_coins > 0)
                {
                    // Remove a coin.
                    _coins--;

                    int halfHeight = (Height / 2);

                    // Create a new coin.
                    Coin coin = new Coin(new Vector2(Position.X + 2, Position.Y - halfHeight), _content, Parent);

                    // Coin should perform on free action.
                    coin.OnFree();

                    // Add coin to the level.
                    Parent.AddEntity(coin);

                    // Set the state to BUMP_START.
                    State = TileState.BUMP_START;
                }
            }
        }
Beispiel #5
0
 /// <summary>
 /// Function gets called when a collision with this object occurs.
 /// </summary>
 /// <param name="ent"> Entity this object collides with.</param>
 /// <param name="penetration"> Amount of penetration.</param>
 /// <param name="side"> The side the objects collide on.</param>
 /// <param name="axis"> The axis that is being checked.</param>
 /// <param name="fromBounds"> Where the colliding entity came from.</param>
 public override void OnCollision(Entity ent, int penetration, CollisionTester.CollisionSide side, CollisionTester.Axis axis, Rectangle fromBounds)
 {
     // Dont allow player from side to kill it.
     if (ent is Player)
     {
         ((Player)ent).OnEnemyCollision();
     }
 }
Beispiel #6
0
 /// <summary>
 /// Function gets called when a collision with this object occurs.
 /// </summary>
 /// <param name="ent"> Entity this object collides with.</param>
 /// <param name="penetration"> Amount of penetration.</param>
 /// <param name="side"> The side the objects collide on.</param>
 /// <param name="axis"> The axis that is being checked.</param>
 /// <param name="fromBounds"> Where the colliding entity came from.</param>
 public override void OnCollision(Entity ent, int penetration, CollisionTester.CollisionSide side, CollisionTester.Axis axis, Rectangle fromBounds)
 {
     // Check if collider is player.
     if (ent is Player)
     {
         // Call on enemy collision function of player.
         ((Player)ent).OnEnemyCollision();
     }
 }
Beispiel #7
0
        /// <summary>
        /// Function gets called when a collision with this object occurs.
        /// </summary>
        /// <param name="ent"> Entity this object collides with.</param>
        /// <param name="penetration"> Amount of penetration.</param>
        /// <param name="side"> The side the objects collide on.</param>
        /// <param name="axis"> The axis that is being checked.</param>
        /// <param name="fromBounds"> Where the colliding entity came from.</param>
        public override void OnCollision(Entity ent, int penetration, CollisionTester.CollisionSide side, CollisionTester.Axis axis, Rectangle fromBounds)
        {
            if (ent is Player && _state == FinishState.OPEN)
            {
                _state = FinishState.CLOSED;

                Animations.Play((int)_state);
                OnClosed?.Invoke(this, new EventArgs());
            }
        }
Beispiel #8
0
        /// <summary>
        /// Function gets called when a collision with this object occurs.
        /// </summary>
        /// <param name="ent"> Entity this object collides with.</param>
        /// <param name="penetration"> Amount of penetration.</param>
        /// <param name="side"> The side the objects collide on.</param>
        /// <param name="axis"> The axis that is being checked.</param>
        /// <param name="fromBounds"> Where the colliding entity came from.</param>
        public override void OnCollision(Entity ent, int penetration, CollisionTester.CollisionSide side, CollisionTester.Axis axis, Rectangle fromBounds)
        {
            // If player clollides with coin, pick it up and destroy the coin.
            if (ent is Player)
            {
                OnPickUp();

                Destroy();
            }
        }
Beispiel #9
0
        /// <summary>
        /// Function gets called when a collision with this object occurs.
        /// </summary>
        /// <param name="ent"> Entity this object collides with.</param>
        /// <param name="penetration"> Amount of penetration.</param>
        /// <param name="side"> The side the objects collide on.</param>
        /// <param name="axis"> The axis that is being checked.</param>
        /// <param name="fromBounds"> Where the colliding entity came from.</param>
        public override void OnCollision(Entity ent, int penetration, CollisionTester.CollisionSide side, CollisionTester.Axis axis, Rectangle fromBounds)
        {
            if (!(ent is Enemy))
            {
                ResolveCollision(ent, penetration, side);

                if (ent.Solid && axis == CollisionTester.Axis.X)
                {
                    TurnAround();
                    State = PowerUpState.MOVING;
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Function gets called when a collision with this object occurs.
        /// </summary>
        /// <param name="ent"> Entity this object collides with.</param>
        /// <param name="penetration"> Amount of penetration.</param>
        /// <param name="side"> The side the objects collide on.</param>
        /// <param name="axis"> The axis that is being checked.</param>
        /// <param name="fromBounds"> Where the colliding entity came from.</param>
        public override void OnCollision(Entity ent, int penetration, CollisionTester.CollisionSide side, CollisionTester.Axis axis, Rectangle fromBounds)
        {
            // Check if collider is player.
            if (ent is Player)
            {
                // Check if player came from top.
                bool fromTop = (side == CollisionTester.CollisionSide.TOP && (fromBounds.Bottom - Bounds.Top) <= 0 && axis == CollisionTester.Axis.Y);

                // Get player.
                Player player = (Player)ent;

                // If player came from top and player is not invulnerable.
                if (fromTop && !player.Invulnerable)
                {
                    // Call enemy on death.
                    OnDeath(player);

                    EnableDeathTimer();

                    // Make the player jump.
                    player.Jump();
                }
                else // Player is not comming from top.
                {
                    // Check if enemy is solid.
                    if (Solid)
                    {
                        // Call in player the on enemy collision function.
                        player.OnEnemyCollision();
                    }
                }
            }
            // If colliding with solid but not with player.
            else if (ent.Solid && axis == CollisionTester.Axis.X)
            {
                // Turn enemy around.
                TurnAround();
            }

            // If enemy is not colliding with power up resolve collision.
            if (!(ent is PowerUp))
            {
                ResolveCollision(ent, penetration, side);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Resolve an occured collision
        /// </summary>
        /// <param name="ent"> The collider.</param>
        /// <param name="penetration"> Depth of the collision.</param>
        /// <param name="side"> Collided side.</param>
        protected void ResolveCollision(Entity ent, int penetration, CollisionTester.CollisionSide side)
        {
            if (ent.Solid)
            {
                Vector2 position = Position;

                if (side == CollisionTester.CollisionSide.TOP)
                {
                    position.Y += penetration;
                    velocity.Y  = 0;
                }

                if (side == CollisionTester.CollisionSide.RIGHT)
                {
                    position.X -= penetration;
                    velocity.X  = 0;
                }

                if (side == CollisionTester.CollisionSide.BOTTOM)
                {
                    position.Y -= penetration;
                    velocity.Y  = 0;
                    Grounded    = true;
                }

                if (side == CollisionTester.CollisionSide.LEFT)
                {
                    position.X += penetration;
                    velocity.X  = 0;
                }

                Position = position;

                SyncBoundingBox();
            }
        }
Beispiel #12
0
 /// <summary>
 /// Function gets called when a collision with this object occurs.
 /// </summary>
 /// <param name="ent"> Entity this object collides with.</param>
 /// <param name="penetration"> Amount of penetration.</param>
 /// <param name="side"> The side the objects collide on.</param>
 /// <param name="axis"> The axis that is being checked.</param>
 /// <param name="fromBounds"> Where the colliding entity came from.</param>
 public virtual void OnCollision(Entity ent, int penetration, CollisionTester.CollisionSide side, CollisionTester.Axis axis, Rectangle fromBounds)
 {
     //
 }
Beispiel #13
0
 /// <summary>
 /// Function gets called when a collision with this object occurs.
 /// </summary>
 /// <param name="ent"> Entity this object collides with.</param>
 /// <param name="penetration"> Amount of penetration.</param>
 /// <param name="side"> The side the objects collide on.</param>
 /// <param name="axis"> The axis that is being checked.</param>
 /// <param name="fromBounds"> Where the colliding entity came from.</param>
 public override void OnCollision(Entity ent, int penetration, CollisionTester.CollisionSide side, CollisionTester.Axis axis, Rectangle fromBounds)
 {
     ResolveCollision(ent, penetration, side);
 }
Beispiel #14
0
        /// <summary>
        /// Function gets called when a collision with this object occurs.
        /// </summary>
        /// <param name="ent"> Entity this object collides with.</param>
        /// <param name="penetration"> Amount of penetration.</param>
        /// <param name="side"> The side the objects collide on.</param>
        /// <param name="axis"> The axis that is being checked.</param>
        /// <param name="fromBounds"> Where the colliding entity came from.</param>
        public override void OnCollision(Entity ent, int penetration, CollisionTester.CollisionSide side, CollisionTester.Axis axis, Rectangle fromBounds)
        {
            // Check if collider is player.
            if (ent is Player)
            {
                // Check if player comes from top.
                bool fromTop = (side == CollisionTester.CollisionSide.TOP && (fromBounds.Bottom - Bounds.Top) <= 0 && axis == CollisionTester.Axis.Y);

                // Get player.
                Player player = (Player)ent;

                // If player comes top and player is not invulnerable.
                if (fromTop && !player.Invulnerable)
                {
                    // If shell is moving make it idle, if it is idle make it moving.
                    AllowMovement = !AllowMovement;

                    // Start in opposite direction where it came from.
                    TurnAround();

                    // Play sound.
                    if (_startMovingSound != null)
                    {
                        _startMovingSound.Play();
                    }

                    // Make the palyer jump.
                    player.Jump();
                }
                // If player is not from top and shell is moving and player is not invurnelable.
                else if (Math.Abs(velocity.X) > 0 && !player.Invulnerable)
                {
                    // Call in player the on enemy collision function
                    ((Player)ent).OnEnemyCollision();
                }

                // If the player walks to it from the side and the shell is not moving.
                if ((int)velocity.X == 0 && axis == CollisionTester.Axis.X)
                {
                    // Make the shell move.
                    AllowMovement = true;

                    // Play sound.
                    if (_startMovingSound != null)
                    {
                        _startMovingSound.Play();
                    }

                    // Make shell move away from player.
                    if (player.Position.X < Position.X)
                    {
                        // If player is to the left make shell go to right.
                        FacingDirection = Facing.RIGHT;
                    }
                    else
                    {
                        // If player is to the right make shell go to left.
                        FacingDirection = Facing.LEFT;
                    }
                }
            }
            else
            {
                // Resolve collision.
                ResolveCollision(ent, penetration, side);
            }

            // Check if collision axis is X axis.
            if (axis == CollisionTester.Axis.X && ent.Solid)
            {
                // If ent is enemy and shell is moving.
                if (ent is Enemy && !(ent is EggEnemy) && AllowMovement)
                {
                    // Get enemy.
                    Enemy enemy = (Enemy)ent;

                    // If enemy is not invulnerable.
                    if (!enemy.Invulnerable)
                    {
                        // Kill enemy.
                        enemy.OnDeath(this);
                    }
                    else
                    {
                        TurnAround();
                    }
                }
                // If entity is not player turn around.
                else if (!(ent is Player))
                {
                    TurnAround();
                }
            }

            // Check if shell is moving.
            if (AllowMovement)
            {
                // Play moving animation.
                Animations.Play((int)EggEnemyAnimation.MOVING);
            }
            else
            {
                // Play idle animation.
                Animations.Play((int)EggEnemyAnimation.IDLE);
            }
        }