コード例 #1
0
ファイル: WorldsController.cs プロジェクト: libben/the-ocean
        bool SwitchPlayerWorld(bool CheckForCollision)
        {
            if (CheckForCollision && CollidingInOtherWorld())
            {
                return(false);
            }

            Source.Play();

            PlayerCurrentWorld *= -1;

            if (PlayerCurrentWorld > 0)
            {
                PlayerObject.layer = (int)Layers.PLAYERW1;
                // Need to inform the movement controller script that the ground is now world 1's ground
                Player.GroundLayer = LayersManager.GetLayerMaskWorld1();

                var currentBox = Player.GetGrabbedBox();
                if (currentBox)
                {
                    if (currentBox.gameObject.layer != (int)Layers.OBJECTS_PERSISTENT)
                    {
                        currentBox.gameObject.layer = (int)Layers.OBJECTS1;
                        currentBox.gameObject.GetComponent <Renderer>().sortingLayerName = "Objects1";
                        currentBox.SetCurrentWorld(PlayerCurrentWorld);
                    }
                }
            }
            // 1->2
            else
            {
                PlayerObject.layer = (int)Layers.PLAYERW2;
                Player.GroundLayer = LayersManager.GetLayerMaskWorld2();

                var currentBox = Player.GetGrabbedBox();
                if (currentBox)
                {
                    if (currentBox.gameObject.layer != (int)Layers.OBJECTS_PERSISTENT)
                    {
                        currentBox.gameObject.layer = (int)Layers.OBJECTS2;
                        currentBox.gameObject.GetComponent <Renderer>().sortingLayerName = "Objects2";
                        currentBox.SetCurrentWorld(PlayerCurrentWorld);
                    }
                }
            }

            return(true);
        }
コード例 #2
0
        void Start()
        {
            //Get a reference to the required components
            input        = GetComponent <PlayerInput>();
            rigidBody    = GetComponent <Rigidbody2D>();
            Anim         = GetComponent <Animator>();
            SpriteRend   = GetComponent <SpriteRenderer>();
            NormalSprite = SpriteRend.sprite;

            var allPlayerColliders = gameObject.GetComponents <BoxCollider2D>();

            foreach (BoxCollider2D collider in allPlayerColliders)
            {
                if (!collider.isTrigger)
                {
                    bodyCollider = collider;
                }
            }

            //Record the original x scale of the player
            originalXScale = transform.localScale.x;

            GroundLayer = LayersManager.GetLayerMaskWorld1();
        }
コード例 #3
0
ファイル: BoxController.cs プロジェクト: libben/the-ocean
        void FixedUpdate()
        {
            IsGrounded = false;

            var CheckAbove = Raycast(new Vector2(0, Collider.size.y / 2 + 0.05f), Vector2.up, CloseDistance, LayersManager.GetLayerMaskObjects(CurrentWorld));
            var CheckBelow = Raycast(new Vector2(0, -Collider.size.y / 2 - 0.01f), Vector2.down, CloseDistance, LayersManager.GetLayerMaskWorld(CurrentWorld));
            var CheckLeft  = Raycast(new Vector2(-Collider.size.x / 2 - 0.001f, 0), Vector2.left, CloseDistance, LayersManager.GetLayerMaskWorld(CurrentWorld));
            var CheckRight = Raycast(new Vector2(Collider.size.x / 2 + 0.001f, 0), Vector2.right, CloseDistance, LayersManager.GetLayerMaskWorld(CurrentWorld));

            if (CheckLeft)
            {
                TouchingLeft = true;
            }
            else
            {
                TouchingLeft = false;
            }
            if (CheckRight)
            {
                TouchingRight = true;
            }
            else
            {
                TouchingRight = false;
            }
            if (CheckBelow)
            {
                IsGrounded = true;
            }


            if (CheckAbove)
            {
                IsGrabbable = false;
            }
            else
            {
                IsGrabbable = true;
            }

            // If this box is being grabbed, we want it to stop the player if it hits a ceiling/wall
            if (BeingGrabbed)
            {
                CheckAbove = Raycast(new Vector2(0, Collider.size.y / 2 + 0.05f), Vector2.up,
                                     CloseDistance, LayersManager.GetLayerMaskWorld(CurrentWorld));
                if (CheckAbove)
                {
                    PlayerObject.GetComponent <PlayerController>().HaltPlayerJump();
                }

                /*if (IsGrounded && !PlayerObject.GetComponent<PlayerController>().IsGrounded)
                 * {
                 *      PlayerObject.GetComponent<PlayerController>().HaltPlayerJump();
                 * }*/
            }
        }
コード例 #4
0
        void GravityGunOn()
        {
            // Check if box is in front of us.
            var boxInRange = Raycast(new Vector2(Direction * 0.5f, 0), Direction * Vector2.right, GravityGunRange, LayersManager.GetLayerMaskObjects(WorldsController.PlayerCurrentWorld));

            if (boxInRange && boxInRange.transform.gameObject.tag == "Box")
            {
                GunNoiseSource?.Play();
                GravityGunActive  = true;
                SpriteRend.sprite = GravityGunSprite;

                // Grab box, turn off its colliders, save its position relative to player, expand player collider
                GrabbedBox = boxInRange.transform.gameObject.GetComponent <BoxController>();
                GrabbedBox.ToggleGrabbed();
                BoxHitbox = GrabbedBox.gameObject.GetComponent <BoxCollider2D>();

                if (GrabbedBox.transform.position.x - gameObject.transform.position.x < 0)
                {
                    BoxOffset = new Vector2(GrabbedBox.transform.position.x - gameObject.transform.position.x - MinDistance, GrabbedBox.transform.position.y - gameObject.transform.position.y);
                }
                else
                {
                    BoxOffset = new Vector2(GrabbedBox.transform.position.x - gameObject.transform.position.x + MinDistance, GrabbedBox.transform.position.y - gameObject.transform.position.y);
                }

                // If player grabs a box but isn't on the ground OR has something over it, they can't pull it
                if (!IsGrounded && GrabbedBox.IsGrounded)
                {
                    rigidBody.velocity     = new Vector2(0, 0);
                    rigidBody.gravityScale = 0;
                    CanMove = false;
                }
                if (!GrabbedBox.IsGrabbable)
                {
                    CanMove = false;
                }

                Debug.Log("Gravity gun on");
            }
        }
コード例 #5
0
        void FixedUpdate()
        {
            //Check the environment to determine status
            PhysicsCheck();

            //Process ground and air movements
            if (CanMove)
            {
                GroundMovement();
                MidAirMovement();
            }

            if (GravityGunAcquired)
            {
                GravityGunControl();
            }


            // TESTING PURPOSES:
            // See the ray that determines whether a box is within gravity gun range.
            Raycast(new Vector2(Direction * 0.5f, 0), Direction * Vector2.right, GravityGunRange, LayersManager.GetLayerMaskObjects(WorldsController.PlayerCurrentWorld));
        }