Ejemplo n.º 1
0
    private void ProcessInputs()
    {
        Vector3 forward = new Vector3 (0, 0, 0);
        if (this.isApplicationFocus) {
            Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
            Vector3 point = ray.GetPoint (ray.origin.z / -ray.direction.z);
            forward = point - this.player.transform.position;
            forward.Normalize ();
        } else {
            forward = this.lastForward;
        }

        KeypressUpdate ku = new KeypressUpdate (Input.GetKey ("w"),
                                                Input.GetKey ("s"),
                                                Input.GetKey ("a"),
                                                Input.GetKey ("d"),
                                                Input.GetKey (KeyCode.LeftShift),
                                                Input.GetKey (KeyCode.Mouse0),
                                                Input.GetKey (KeyCode.Mouse1),
                                                Input.GetKey (KeyCode.Mouse2),
                                                Time.deltaTime,
                                                this.player.inputSequenceNumber,
                                                forward.x,
                                                forward.y,
                                                forward.z,
                                                false);

        if (!ku.up && !ku.down && !ku.left && !ku.right && !ku.shift && !ku.attack && !ku.attack2 && !ku.attack3 && forward == this.lastForward)
        {
            ku.noInput = true;
            if(!this.hasSentNoInput)
            {
                this.hasSentNoInput = true;
                this.lastForward = forward;
                this.server.SendMessage (ku);

                this.player.inputSequenceNumber++;
                this.player.ApplyInput (ku, true);
                this.player.pendingInputs.Add(ku);
            }
            return;
        }
        this.hasSentNoInput = false;
        this.lastForward = forward;
        this.server.SendMessage (ku);

        this.player.inputSequenceNumber++;
        this.player.ApplyInput (ku, true);
        this.player.pendingInputs.Add(ku);
    }
Ejemplo n.º 2
0
    public void ApplyInput(KeypressUpdate ku, bool clientSide)
    {
        this.forward = new Vector3 (ku.forwardX, ku.forwardY, ku.forwardZ);
        Vector3 myDir = new Vector3 (0, 0, 0);
        if (ku.up) {
            myDir.y += 1;
        }
        if (ku.down) {
            myDir.y -= 1;
        }
        if (ku.left) {
            myDir.x -= 1;
        }
        if (ku.right) {
            myDir.x += 1;
        }

        myDir.Normalize ();

        if (ku.shift) {
            this.speed = this.BASE_SPEED * 1.5f;
        }
        else {
            this.speed = this.BASE_SPEED;
        }

        float directionSpeed = (Vector3.Dot (myDir, this.forward) * 0.25f) + 0.75f;

        myDir *= this.speed * directionSpeed;

        this.transform.position += new Vector3 (myDir.x, myDir.y, 0) * ku.diff;

        float AngleRad = Mathf.Atan2 (this.forward.x, -this.forward.y);
        float AngleDeg = (180 / Mathf.PI) * AngleRad;
        this.transform.rotation = Quaternion.Euler (0, 0, AngleDeg);

        if (myDir.magnitude > 0.0f) {
            this.animationScript.SetRunningAnimationSpeed (myDir.magnitude / this.MAX_SPEED_ANIMATION);
            this.animationScript.Running ();
        } else {
            this.animationScript.StandingStill ();
        }

        if (clientSide) {
            if(ku.attack)
            {
                this.animationScript.AttackRightArm();
            }

            if(ku.attack2)
            {
                this.animationScript.HoldBlock();
            }
            else
            {
                this.animationScript.ReleaseBlock();
            }

            if(ku.attack3)
            {
                // Arrow animation
            }
        }

        Camera.main.transform.position = this.transform.position + new Vector3(0, 0, -10);
    }