Example #1
0
        //the first time this is called, the jump to the destination is calculated and the jump itself is put on the action plan
        //every subsequent call then exits early until the JUMP state is exited
        private void stepJumping(float dt)
        {
            currentStateCooldown -= dt;

            //if the jump has already been set up then exit. Nothing more need be done
            if (currentlyJumping)
            {
                return;
            }

            //make sure the following code is only run once per jump
            currentlyJumping = true;

            //set the time this state will exit to be the same as the time the jump should end
            currentStateCooldown = AIPlayer.GetTotalJumpDuration(mainGraph.topLevelNode.GetNodePosition(currentNode), mainGraph.topLevelNode.GetNodePosition(destinationNode), physEng.gravity);

            //initiate the jump
            actionPlan.Add(new act_dur((int)ACTIONS.MOVE_UP, 0.0f));

            //calculate the acceleration duration and apply it
            float accelerationDuration = AIPlayer.GetJumpFromSourceToDest(mainGraph.topLevelNode.GetNodePosition(currentNode), mainGraph.topLevelNode.GetNodePosition(destinationNode), physEng.gravity);

            if (accelerationDuration < 0)
            {
                actionPlan.Add(new act_dur((int)ACTIONS.MOVE_LEFT, accelerationDuration * -1));
            }
            else
            {
                actionPlan.Add(new act_dur((int)ACTIONS.MOVE_RIGHT, accelerationDuration));
            }

            //end the jump by ceasing all player inputs
            actionPlan.Add(new act_dur((int)ACTIONS.DO_NOTHING, 0.0f));
        }