コード例 #1
0
ファイル: Player.cs プロジェクト: JDrocks450/KrabbyQuestEmu
    // Update is called once per frame
    void Update()
    {
        if (dying)
        {
            float deathTime = 2.5f;
            dyingTimer += Time.deltaTime;
            if (dyingTimer >= deathTime)
            {
                LevelObjectManager.ReloadLevel(); // reset the level
                dying      = false;
                dyingTimer = 0f;
            }
            return;         // prevent player control when dying.
        }
        _ = TileMoveScript; // force update of component
        PlayerEnum updatingPlayer = PlayerName == "spongebob" ? PlayerEnum.SPONGEBOB : PlayerEnum.PATRICK;
        bool       currentPlayer  = (PlayerName == "spongebob" && CurrentPlayer == PlayerEnum.SPONGEBOB) ||
                                    (PlayerName == "patrick" && CurrentPlayer == PlayerEnum.PATRICK);

        if (updatingPlayer == swappingPlayer && playerSwapping) // this frame is the update frame after swapping
        {
            playerSwapping = false;
        }
        if (currentPlayer)
        {
            Current = this;
            if (!IsMoving)
            {
                if (Input.GetKey(KeyCode.W)) // forward
                {
                    WalkToTile(TileX, TileY - 1);
                    rotator.Rotate(SRotation.NORTH);
                }
                else if (Input.GetKey(KeyCode.S)) // backward
                {
                    WalkToTile(TileX, TileY + 1);
                    rotator.Rotate(SRotation.SOUTH);
                }
                else if (Input.GetKey(KeyCode.A)) // left
                {
                    WalkToTile(TileX - 1, TileY);
                    rotator.Rotate(SRotation.WEST);
                }
                else if (Input.GetKey(KeyCode.D)) // right
                {
                    WalkToTile(TileX + 1, TileY);
                    rotator.Rotate(SRotation.EAST);
                }
                if (Input.GetKeyDown(KeyCode.Q))
                {
                    TileMoveScript.NoClip = !TileMoveScript.NoClip; // no clip toggle
                }
                if (Input.GetKeyDown(KeyCode.K))
                {
                    KillAllPlayers(); // kill me now
                }
            }
            if (Input.GetKeyDown(KeyCode.Space) && !playerSwapping)
            {
                swappingPlayer = CurrentPlayer;
                switch (CurrentPlayer) // switch current player
                {
                case PlayerEnum.SPONGEBOB:
                    CurrentPlayer = PlayerEnum.PATRICK;     // patrick
                    break;

                case PlayerEnum.PATRICK:
                    CurrentPlayer = PlayerEnum.SPONGEBOB;     // spongebob
                    break;
                }
                SoundLoader.Play("teleport.wav", false);
                playerSwapping = true;
            }
        }
    }
コード例 #2
0
 void FaceDirection(SRotation Direction) => Rotator.Rotate(Direction);