Download Trog Tutorial
Transcript
bool
CharacterControls::ShouldProcess()
{
if ((CharState.state == characterBe::TrogStateType::Jumping) ||
(CharState.state == characterBe::TrogStateType::ThrowingBomb) ||
(CharState.health <= 0) || !CharState.isPlaying ||
(CharState.gem_score >= 5000))
return false;
else
return true;
}
The code above returns false if Trog is jumping or throwing a bomb, since we don’t want to
interrupt those animations if they’re currently playing, if his health reaches zero (he’s dead) or if
isPlaying is false. This means if we’re in our intro/directions state, then we won’t process input
either. Additionally, we won’t process input if the gem_score is at least 5000 (the total score to
win). Otherwise, the function returns true, meaning we can process the user’s input.
41. Create a new VSL function called ShouldProcessPhysics. We’ll use this function to determine
with slightly different, more relaxed constraints whether we should apply the physics of moving
Trog forward. The code for this function should be:
// Definition of the function ShouldProcessPhysics
bool
CharacterControls::ShouldProcessPhysics()
{
if (CharState.state == characterBe::TrogStateType::ThrowingBomb)
return false;
else
return true;
}
This code ensures that we don’t apply physics (i.e. don’t allow Trog to move forward or backward)
when he’s throwing a bomb. This is a stylistic constraint you might want to change, but for our
design, we’ll ensure Trog is stationary when he throws a bomb.
Now that we have these functions, we need to utilize them by improving the Movement schematic,
placing these blocks before the processing of keyboard input from the user.
42. In the Movement schematic, you have two IsKeyPressed blocks that appear immediately after the
Keyboard block. We want to insert the ShouldProcess block between these lines of execution and
make all the return lines that go into these IsKeyPressed blocks return into the ShouldProcess
block.
a. Add the ShouldProcess block and position it between the Keyboard and IsKeyPressed
blocks.
b. The false/bottom out line from the ShouldProcess block should loop back on itself.
c. Make the out from Keyboard go to the in of ShouldProcess.
d. Make the return out lines from the various Identity (there are three) blocks return to the
ShouldProcess block.
e. Make the return out lines from the Add and Subtract and the bottom/false out of the
lowest IsKeyPressed block (in the lower area of the schematic) return to the in of
ShouldProcess.
f. Make the top/true out from the ShouldProcess connect in parallel to the two
IsKeyPressed blocks that had been connected to the Keyboard.
g. Remove all of the old lines that we’ve now replaced.
Your schematic should now partially include what you see in the following figure. Notice that there should
be eight inputs into ShouldProcess.
© Dassault Systèmes. All rights reserved