public override void OnCollision(BasicCollisionBody bodyA, BasicCollisionBody bodyB, Vector2 depth)
        {
            var characterState = bodyA.Entity.GetComponent <CharacterState>();

            if ((string)bodyB.Tag == "Deadly")
            {
                characterState.HealthPoints = 0;
                return;
            }

            base.OnCollision(bodyA, bodyB, depth);
        }
Exemple #2
0
        public override void OnCollision(BasicCollisionBody bodyA, BasicCollisionBody bodyB, Vector2 depth)
        {
            var player = GetEntityByTag(bodyA.Entity, bodyB.Entity, Entities.Player);
            var enemy  = GetEntityByTag(bodyA.Entity, bodyB.Entity, "BadGuy");

            if (player != null && enemy != null)
            {
                enemy.GetComponent <CharacterState>().HealthPoints  = 0;
                player.GetComponent <CharacterState>().HealthPoints = 0;
            }

            base.OnCollision(bodyA, bodyB, depth);
        }
        public virtual void OnCollision(BasicCollisionBody bodyA, BasicCollisionBody bodyB, Vector2 depth)
        {
            var characterState = bodyA.Entity.GetComponent <CharacterState>();
            var absDepthX      = Math.Abs(depth.X);
            var absDepthY      = Math.Abs(depth.Y);

            if (absDepthY < absDepthX)
            {
                bodyA.Entity.Position += new Vector2(0, depth.Y); // move the player out of the ground or roof
                var isOnGround = bodyA.Velocity.Y > 0;

                if (isOnGround)
                {
                    bodyA.Velocity           = new Vector2(bodyA.Velocity.X, 0); // set y velocity to zero only if this is a ground collision
                    characterState.IsJumping = false;
                }
            }
            else
            {
                bodyA.Entity.Position += new Vector2(depth.X, 0);                                                    // move the player out of the wall
                bodyA.Velocity         = new Vector2(bodyA.Velocity.X, bodyA.Velocity.Y < 0 ? 0 : bodyA.Velocity.Y); // drop the player down if they hit a wall
            }
        }