Ejemplo n.º 1
0
    void InitDirectionalButtons()
    {
        GUI.Box(new Rect(0.028947368f * Screen.width, 0.78f * Screen.height, 0.068947368f * 1.5f * Screen.width, 0.146153846f * 1.5f * Screen.height), "", directionalPadStyle);

        // Button Up
        //if (GUI.Button( new Rect(25 + space + 45, (Screen.height - height_offset + 47/2) + 10, 38, 25), "", button_direction_up))
        if (GUI.RepeatButton(new Rect(0.062f * Screen.width, 0.78f * Screen.height, 0.02f * 2f * Screen.width, 0.027472527f * 2f * Screen.height), "", button_direction_up))
        {
            /*Debug.Log ("SCREEN.WIDTH 1900"+ Screen.width );
             * Debug.Log ("SCREEN.HEIGHT 910"+ Screen.height );
             * Debug.Log ("X: "+ (25 + space*3 + 131 + 131 + 200) );
             * Debug.Log ("Y: "+ ( (Screen.height - height_offset) + 20) );*/

            soundManager.PlayHUDClickSound(transform.position);
            if (playerController)
            {
                playerController.MoveUp(0.0f, 0.0f, true);
            }
            else if (cameraScript)
            {
                cameraScript.MoveUp();
            }
        }

        //Button Left
        //if (GUI.Button( new Rect(25 + space + 12, (Screen.height - height_offset + 47/2) + 45, 26, 40), "", button_direction_left))
        if (GUI.RepeatButton(new Rect(0.035f * Screen.width, 0.845f * Screen.height, 0.01368421f * 2f * Screen.width, 0.043956043f * 2f * Screen.height), "", button_direction_left))
        {
            soundManager.PlayHUDClickSound(transform.position);
            if (playerController)
            {
                playerController.MoveLeft(0.0f, 0.0f, true);
            }
            else if (cameraScript)
            {
                cameraScript.MoveLeft();
            }
        }

        //Button Down
        //if (GUI.Button( new Rect(25 + space + 45, (Screen.height - height_offset + 47/2) + 100, 38, 25), "", button_direction_down))
        if (GUI.RepeatButton(new Rect(0.062f * Screen.width, 0.937362637f * Screen.height, 0.02f * 2f * Screen.width, 0.027472527f * 2f * Screen.height), "", button_direction_down))
        {
            soundManager.PlayHUDClickSound(transform.position);
            if (playerController)
            {
                playerController.MoveDown(0.0f, 0.0f, true);
            }
            else if (cameraScript)
            {
                cameraScript.MoveDown();
            }
        }

        //Button Right
        //if (GUI.Button( new Rect(25 + space + 100, (Screen.height - height_offset + 47/2) + 45, 24, 40), "", button_direction_right))
        if (GUI.RepeatButton(new Rect(0.105f * Screen.width, 0.845f * Screen.height, 0.012631578f * 2f * Screen.width, 0.043956043f * 2f * Screen.height), "", button_direction_right))
        {
            soundManager.PlayHUDClickSound(transform.position);
            if (playerController)
            {
                playerController.MoveRight(0.0f, 0.0f, true);
            }
            else if (cameraScript)
            {
                cameraScript.MoveRight();
            }
        }
    }
Ejemplo n.º 2
0
    public void UpdatePosition(long serverPlayerID, float cellX, float cellY, string direction, float moveSpeed, float timeDifference, float serverDelay)
    {
        GameObject characterObject = GameObject.Find("" + serverPlayerID);

        // If player already been destroyed (e.g. dead)
        if (characterObject == null)
        {
            return;
        }

        float bufferTime = 0.05f;

        // If it is the enemy, add a local buffer time to handle jitter

        /*if(serverPlayerID != PlayerID)
         * {
         *      timeDifference += bufferTime;
         * }*/


        // If it is a player, add a local lag
        if (serverPlayerID == PlayerID)
        {
            timeDifference = 2 * serverDelay / 1000.0f;
        }

        timeDifference += bufferTime;

        CharacterAnimController movementController = characterObject.GetComponent <CharacterAnimController>();
        float defaultSpeed = moveSpeed;                 // movement speed from the server

        if (timeDifference < 0)
        {
            timeDifference *= -1;
        }

        // Delayed time here can be faster or slower
        float delayedTime = (ZooMap.cellWidth / defaultSpeed) + timeDifference;

        Debug.Log("DELAYED TIME!!!: " + delayedTime);
        Debug.Log("SERVER SEND SPEED!!!: " + moveSpeed);

        movementController.PlayerSpeed = ZooMap.cellWidth / delayedTime;

        Debug.Log("Time Difference: " + timeDifference);
        Debug.Log("LPF Speed is : " + movementController.PlayerSpeed);

        // If it is the player

        /*if(serverPlayerID == PlayerID)
         * {
         *      // set the local lag delay and player will move by it's own
         *      movementController.LOCAL_LAG_DELAY = (float) 2 * serverDelay/1000.0f;
         *      movementController.PlayerSpeed = moveSpeed;
         *
         *      //Debug.Log ("PLAYER LOCAL LAG DELAY IS: "+movementController.LOCAL_LAG_DELAY );
         * }
         */


        // If enemy, do LocalPerceptionFilter
        if (serverPlayerID != PlayerID)
        {
            switch (direction)
            {
            case "UP":
                movementController.MoveUp(cellX, cellY, false);
                break;

            case "DOWN":
                movementController.MoveDown(cellX, cellY, false);
                break;

            case "LEFT":
                movementController.MoveLeft(cellX, cellY, false);
                break;

            case "RIGHT":
                movementController.MoveRight(cellX, cellY, false);
                break;
            }
        }
    }