Templates step by step

Top  Previous  Next

This month we will continue to play with the xml files that come with the templates; we will use last month's "customkeys" project as a base. Let's start by deleting the UserInput.xml file from our \customkeys folder (not from the \templates\xml folder!); this will revert the movement keys to the standard WSAD keys. Run the project - you should see something like this:

 

aum74_templates1

 

Ok, you've caught me: I have replaced the terrain and I have added a hollowed cube, texturing it with a sky texture, but apart from that everything has remained the same.

Now press the "space" key; if your template version is identical with mine (or you are just an unlucky guy) you will see an error message popping up:

 

aum74_templates2

 

This happens because the sound file that is played while the player is jumping (jump.wav) has a weird sample rate, which can't be played by the engine. If this is the case for you as well, overwrite the jump.wav file from inside the GStudio7\templates\sounds with the sound file that comes with this month's resources. I have created the entire folder structure for you, so you'll only have to overwrite your GStudio7 folder with the one that can be found inside aum74code.zip.

 

We are going to play with the animation speed, but let's alter the template code a bit, making sure that it runs our project in full screen mode at all times, without having to use the Alt + Enter keys combination. Open myProj.c from inside the \customkeys folder, and then add this tiny function at its bottom:

 

// keep the game at 1024x768 pixels in full screen mode at all times

function fullscreen_startup()

{

       while (1)

       {

               video_switch(8, 0, 1);

               wait (1);

       }

}

 

The result should look like this:

 

aum74_templates3

 

The function will set the resolution to 1024x768 pixels in full screen mode, making the switch every time when a parasite function ;) tries to take over the control.

Now that we have this thing covered (using brute force methods), run the project and then press the F7 key to switch to a 3rd person camera.

 

aum74_templates4

 

Press the movement keys; you can see that this lady could benefit from some animation optimizations, so let's copy the Animations.xml file from inside the \templates\xml folder to our \customkeys folder. For those of you that were too tired to read last month's article, we do this because we don't want to change the behavior of all our past and future template-based projects.

 

Fire up Sed and load the Animations.xml file or, if Sed is your default xml editor, simply double click the xml file - you will see something that looks like this:

 

aum74_templates5

 

Don't be scared by the long xml file; everything inside it is quite simple and repetitive. The first line that looks interesting is this:

 

<Default name="stand" tick="90" cycle="true" />

 

This line sets the animation speed for our "stand" cycle. Since our lady moves her head a bit too fast, more like a robot, let's change the "tick" value from 90 to 190. Save the xml file, and then run the demo again - this time, the model will "stand" in a more realistic way.

 

The following sections deal with the sideway animations; since our model doesn't include these animations, let's skip until we meed the normal walking (not backward walking!) xml section:

 

</Animation>

<Animation name="walk" dist="80" cycle="true">

       <Doc>Normal walking.</Doc>

       <Condition flag="forward" />

       <Event sound="step.wav" vol="65" per="33" />

       <Event sound="step.wav" vol="65" per="66" />

 

 

Let's change "dist" from 80 to 100 - it will make the walking animation look more realistic. Also, let's change the walking sound frequency ("per") to 100 and 50. This is how the edited section of the xml file should look like:

 

               </Animation>

               <Animation name="walk" dist="100" cycle="true">

                       <Doc>Normal walking.</Doc>

                       <Condition flag="forward" />

                       <Event sound="step.wav" vol="65" per="100" />

                       <Event sound="step.wav" vol="65" per="50" />

 

If you have followed these steps you now have a nice walking animation and sound, adapted to the sf_woman.mdl lady model. The xml file contains sections for running, jumping, attacking and dieing but you shouldn't have any problems with them; they are very similar to the ones that we have just discussed.