Exemplo n.º 1
0
        private void OnCollisionExit(BoxCollider other)
        {
            Console.WriteLine("chell left " + other.GameObject.Name);

            if (LeftAndRightCollisions.Contains(other))
            {
                if (correction.X != 0)
                {
                    correction.X = 0f;
                }
                LeftAndRightCollisions.Remove(other);
                if (LeftAndRightCollisions.Count == 0)
                {
                    canMoveLeft  = true;
                    canMoveRight = true;
                }
            }

            if (!other.IsTrigger)
            {
                if ((Collider.Bottom < other.Top) || (!(Collider.Right < other.Left) || !(Collider.Left > other.Right)))
                {
                    isGrounded = false;
                }
            }

            if (other.GameObject is WeightedCompanionCube)
            {
                if (heldCube == null && cubeInReach != null)
                {
                    cubeInReach.OnToggleHoldState -= ToggleHoldState;
                }
                cubeInReach = null;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// If you collide with a cube, you
        /// can use this method to pick it up.
        /// If you picked up a cube, you can also put it
        /// down again with this method.
        /// </summary>
        private void ToggleHoldState()
        {
            if (heldCube != null)
            {
                heldCube.OnToggleHoldState -= ToggleHoldState;
                heldCube.Collider.IsActive  = true;
                heldCube = null;
            }
            else if (cubeInReach != null)
            {
                heldCube = cubeInReach;

                cubeInReach.OnToggleHoldState -= ToggleHoldState;
                heldCube.OnToggleHoldState    += ToggleHoldState;
            }

            AdjustCollider();
        }
Exemplo n.º 3
0
        private void OnCollisionEnter(BoxCollider other)
        {
            Console.WriteLine("chell hit " + other.GameObject.Name);

            if (!other.IsTrigger)
            {
                //colliding from above
                if (!(Collider.Bottom < other.Top) && lastPosition.Y + Collider.Height <= other.Top)
                {
                    isGrounded            = true;
                    isJumping             = false;
                    state                 = States.Idle;
                    accelerationMultipier = 0;
                    if (Position.Y != other.GameObject.Position.Y - Collider.Height)
                    {
                        Position.Y = other.GameObject.Position.Y - Collider.Height;
                    }
                    velocity.Y = 0f;
                }
                // colliding from beneigh
                else if (!(Collider.Top >= other.Bottom) && lastPosition.Y > other.Bottom)
                {
                    velocity.Y = 0f;
                    Position.Y = other.Bottom + 1;
                }
                // colliding from left or right
                else if (Collider.CollidesWithLeftOf(other) || Collider.CollidesWithRightOf(other))
                #region
                /*if (!(Collider.Right < other.Left) || !(Collider.Left > other.Right))*/
                #endregion
                {
                    velocity.X   = 0f;
                    correction.X = lastPosition.X - Position.X;
                    if (correction.X < 0)
                    {
                        canMoveRight = false;
                    }
                    else if (correction.X > 0)
                    {
                        canMoveLeft = false;
                    }
                    LeftAndRightCollisions.Add(other);
                }
            }

            if (other.GameObject is Portal)
            {
                Portal destinationportal = Teleport(other, viewDirection, velocity);
                if (destinationportal != null)
                {
                    viewDirection = destinationportal.ViewDirection;
                    if (!Collider.AutoPositionUpdateIsEnabled)
                    {
                        if (viewDirection == SideDirections.Right)
                        {
                            Collider.X = (int)Position.X;
                        }
                        else if (viewDirection == SideDirections.Left)
                        {
                            Collider.X = (int)Position.X - colliderExtension;
                        }
                    }
                }
            }

            if (other.GameObject is WeightedCompanionCube)
            {
                cubeInReach = (WeightedCompanionCube)other.GameObject;
                cubeInReach.OnToggleHoldState += ToggleHoldState;
            }
        }