Ejemplo n.º 1
0
        public override void OnHandleCollision(ActorBase other)
        {
            base.OnHandleCollision(other);

            if (state != StateDead)
            {
                // It can only die by collision with spring in the air
                Spring spring = other as Spring;
                if (spring != null)
                {
                    // Collide only with hitbox
                    if (AABB.TestOverlap(ref spring.AABBInner, ref AABBInner))
                    {
                        Vector2 force = spring.Activate();
                        int     sign  = ((force.X + force.Y) > float.Epsilon ? 1 : -1);
                        if (Math.Abs(force.X) > float.Epsilon)
                        {
                            speedX         = (4 + Math.Abs(force.X)) * sign;
                            externalForceX = force.X;
                        }
                        else if (Math.Abs(force.Y) > float.Epsilon)
                        {
                            speedY         = (4 + Math.Abs(force.Y)) * sign;
                            externalForceY = -force.Y;
                        }
                        else
                        {
                            return;
                        }
                        canJump = false;

                        SetAnimation(AnimState.Fall);
                        PlaySound(Transform.Pos, "Spring");

                        levelHandler.BroadcastLevelText(levelHandler.GetLevelText(endText));

                        state     = StateDead;
                        stateTime = 50f;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override void OnHandleCollision(ActorBase other)
        {
            base.OnHandleCollision(other);

            if (!canJump && state != StateDead)
            {
                // It can only die by collision with spring in the air
                Spring spring = other as Spring;
                if (spring != null)
                {
                    // Collide only with hitbox
                    if (spring.Hitbox.Intersects(ref currentHitbox))
                    {
                        Vector2 force = spring.Activate();
                        int     sign  = ((force.X + force.Y) > float.Epsilon ? 1 : -1);
                        if (Math.Abs(force.X) > float.Epsilon)
                        {
                            speedX         = (4 + Math.Abs(force.X)) * sign;
                            externalForceX = force.X;
                        }
                        else if (Math.Abs(force.Y) > float.Epsilon)
                        {
                            speedY         = (4 + Math.Abs(force.Y)) * sign;
                            externalForceY = -force.Y;
                        }
                        else
                        {
                            return;
                        }
                        canJump = false;

                        SetAnimation(AnimState.Fall);
                        PlaySound("Spring");

                        api.BroadcastLevelText(endText);

                        state     = StateDead;
                        stateTime = 50f;
                    }
                }
            }
        }