Example #1
0
        override public void update()
        {
            PlayerIndex pi;

            updateFramesSinceLeftFloor();

            if (FlxG.debug)
            {
                if (FlxGlobal.cheatString.StartsWith("slowdown"))
                {
                    runSpeed = 22;
                }
                if (FlxGlobal.cheatString == "control" + GetType().ToString().Split('.')[1])
                {
                    control = Controls.player;
                    FlxG.follow(this, 11.0f);
                }
                if (FlxGlobal.cheatString == "controlFile" + GetType().ToString().Split('.')[1])
                {
                    control = Controls.file;
                    FlxG.follow(this, 11.0f);
                    startPlayingBack();
                }
            }

            if (control == Controls.player && this.dead != true)
            {
                if (FlxG.keys.A || FlxG.keys.LEFT)
                {
                    leftPressed();
                }
                if (FlxG.gamepads.isButtonDown(Buttons.DPadLeft, ControllingPlayer, out pi))
                {
                    leftPressed();
                }
                if (FlxG.gamepads.isButtonDown(Buttons.LeftThumbstickLeft, ControllingPlayer, out pi))
                {
                    leftPressed();
                }

                if (FlxG.keys.D || FlxG.keys.RIGHT)
                {
                    rightPressed();
                }
                if (FlxG.gamepads.isButtonDown(Buttons.DPadRight, ControllingPlayer, out pi))
                {
                    rightPressed();
                }
                if (FlxG.gamepads.isButtonDown(Buttons.LeftThumbstickRight, ControllingPlayer, out pi))
                {
                    rightPressed();
                }

                if (FlxG.keys.B || FlxG.gamepads.isButtonDown(Buttons.RightTrigger))
                {
                    maxVelocity.X = _runningMax * 2;
                }
                else
                {
                    maxVelocity.X = _runningMax;
                }

                if (FlxG.keys.W || FlxG.keys.SPACE || FlxG.keys.X || FlxG.gamepads.isButtonDown(Buttons.A, ControllingPlayer, out pi))
                {
                    jump();
                }
                else
                {
                    if (_jumpCounter < numberOfJumps)
                    {
                        _jump = 0.0f;
                    }
                    else
                    {
                        _jump = -1;
                    }
                }

                if (FlxG.keys.N || FlxG.gamepads.isButtonDown(Buttons.LeftTrigger))
                {
                    action = Actions.talk;
                }
                else
                {
                    action = Actions.idle;
                }
            }
            else if (control == Controls.file)
            {
                if (frameCount > _history.Count - 2)
                {
                    frameCount = 0;
                    return;
                }

                frameCount++;

                int left  = 3;
                int right = 1;

                if (reverseControls)
                {
                    left  = 1;
                    right = 3;
                }

                if (_history[frameCount][left])
                {
                    leftPressed();
                }
                if (_history[frameCount][right])
                {
                    rightPressed();
                }

                if (_history[frameCount][4])
                {
                    jump();
                }

                if (_history[frameCount][10])
                {
                    action = Actions.talk;
                }
                else
                {
                    action = Actions.idle;
                }
            }


            updateAnims();



            base.update();
        }