예제 #1
0
    // --------------------
    public void ControlByTouch(TouchController ctrl, DemoRpgGameCS game)
    {
        TouchStick
        stickWalk 	= ctrl.GetStick(DemoRpgGameCS.STICK_WALK);
        TouchZone
        zoneScreen	= ctrl.GetZone(DemoRpgGameCS.ZONE_SCREEN),
        zoneAction	= ctrl.GetZone(DemoRpgGameCS.ZONE_ACTION),
        zoneFire	= ctrl.GetZone(DemoRpgGameCS.ZONE_FIRE);

        // Get stick's normalized direction in world space relative to camera's angle...

        Vector3 moveWorldDir	= stickWalk.GetVec3d(TouchStick.Vec3DMode.XZ, true, game.camOrbitalAngle);

        // Get stick's angle in world space by adding it to camera's angle..

        float	stickWorldAngle	= stickWalk.GetAngle() + game.camOrbitalAngle;

        // Get walking speed from stick's current tilt...

        float 	speed 			= stickWalk.GetTilt();

        // Get gun's trigger state by checking Fire zone's state (including mid-frame press)

        bool	gunTriggerState	= zoneFire.UniPressed(true, false);

        // Check if Action should be performed - either by pressing the Action button or
        // by tapping on the right side of the screen...

        bool	performAction	=
        zoneAction.JustUniPressed(true, true) ||
        zoneScreen.JustTapped();

        if ((this.charaState == CharaState.IDLE) ||
        (this.charaState == CharaState.WALK) ||
        (this.charaState == CharaState.RUN))
        {
        if (speed > this.walkStickThreshold)
            {
            float moveSpeed = 0;

            // Walk...

            if (speed < this.runStickThreshold)
                {
                moveSpeed = this.walkSpeed;

                if (this.charaState != CharaState.WALK)
                    this.StartWalking();

                // Set animation speed...

                this.charaAnim[this.ANIM_WALK_F].speed = this.walkAnimSpeed;
                }

            // Run!

            else
                {
                moveSpeed = this.runSpeed;

                if (this.charaState != CharaState.RUN)
                    this.StartRunning();

                // Set animation speed...

                this.charaAnim[this.ANIM_RUN_F].speed = this.runAnimSpeed;
                }

            // Update player's angle...

            this.angle = DampAngle(this.angle, stickWorldAngle, this.angleSmoothingTime, this.turnMaxSpeed, Time.deltaTime);

            // Move player's collider...

            this.charaCtrl.Move(moveWorldDir * moveSpeed * Time.deltaTime);
            }

        else if ((this.charaState == CharaState.WALK) || (this.charaState == CharaState.RUN))
            {
            // Stop...

            this.StartIdle();
            }

        // Perform Action...

        if (performAction)
            this.PerformUseAction();

        }

        // Every other state than USE...

        if (this.charaState != CharaState.USE)
        {
        if (this.gun != null)
            this.gun.SetTriggerState(gunTriggerState);

        if (performAction)
            this.PerformUseAction();
        }

        // USE state updates...

        else
        {
        if (this.gun != null)
            this.gun.SetTriggerState(false);

        this.useElapsed += Time.deltaTime;
        if (this.useElapsed > this.useAnimDuration)
            this.StartIdle();
        }
    }
예제 #2
0
// --------------------
    public void ControlByTouch(TouchController ctrl, DemoRpgGameCS game)
    {
        TouchStick
            stickWalk = ctrl.GetStick(DemoRpgGameCS.STICK_WALK);
        TouchZone
            zoneScreen = ctrl.GetZone(DemoRpgGameCS.ZONE_SCREEN),
            zoneAction = ctrl.GetZone(DemoRpgGameCS.ZONE_ACTION),
            zoneFire   = ctrl.GetZone(DemoRpgGameCS.ZONE_FIRE);



        // Get stick's normalized direction in world space relative to camera's angle...

        Vector3 moveWorldDir = stickWalk.GetVec3d(TouchStick.Vec3DMode.XZ, true, game.camOrbitalAngle);


        // Get stick's angle in world space by adding it to camera's angle..

        float stickWorldAngle = stickWalk.GetAngle() + game.camOrbitalAngle;


        // Get walking speed from stick's current tilt...

        float speed = stickWalk.GetTilt();


        // Get gun's trigger state by checking Fire zone's state (including mid-frame press)

        bool gunTriggerState = zoneFire.UniPressed(true, false);


        // Check if Action should be performed - either by pressing the Action button or
        // by tapping on the right side of the screen...

        bool performAction =
            zoneAction.JustUniPressed(true, true) ||
            zoneScreen.JustTapped();



        if ((this.charaState == CharaState.IDLE) ||
            (this.charaState == CharaState.WALK) ||
            (this.charaState == CharaState.RUN))
        {
            if (speed > this.walkStickThreshold)
            {
                float moveSpeed = 0;

                // Walk...

                if (speed < this.runStickThreshold)
                {
                    moveSpeed = this.walkSpeed;

                    if (this.charaState != CharaState.WALK)
                    {
                        this.StartWalking();
                    }

                    // Set animation speed...

                    this.charaAnim[this.ANIM_WALK_F].speed = this.walkAnimSpeed;
                }

                // Run!

                else
                {
                    moveSpeed = this.runSpeed;

                    if (this.charaState != CharaState.RUN)
                    {
                        this.StartRunning();
                    }

                    // Set animation speed...

                    this.charaAnim[this.ANIM_RUN_F].speed = this.runAnimSpeed;
                }



                // Update player's angle...

                this.angle = DampAngle(this.angle, stickWorldAngle, this.angleSmoothingTime, this.turnMaxSpeed, Time.deltaTime);

                // Move player's collider...

                this.charaCtrl.Move(moveWorldDir * moveSpeed * Time.deltaTime);
            }

            else if ((this.charaState == CharaState.WALK) || (this.charaState == CharaState.RUN))
            {
                // Stop...

                this.StartIdle();
            }


            // Perform Action...

            if (performAction)
            {
                this.PerformUseAction();
            }
        }


        // Every other state than USE...

        if (this.charaState != CharaState.USE)
        {
            if (this.gun != null)
            {
                this.gun.SetTriggerState(gunTriggerState);
            }

            if (performAction)
            {
                this.PerformUseAction();
            }
        }

        // USE state updates...

        else
        {
            if (this.gun != null)
            {
                this.gun.SetTriggerState(false);
            }

            this.useElapsed += Time.deltaTime;
            if (this.useElapsed > this.useAnimDuration)
            {
                this.StartIdle();
            }
        }
    }