Deathshead Corporal

Joined: 18 Feb 2005 Posts: 87
|
Posted: Wed Apr 06, 2005 11:34 am Post subject: [Tutorial] Adding the crosshair |
|
|
This tutorial creates a crosshair that triggers when you press the 'X' button. You will need a sprite editor for Wolfenstein to make the crosshair graphics. Each weapon will have a different crosshair, and the code is easy customized to allow for more crosshairs, and for weapons to share a crosshair.
Open WL_DEF.H and add the following sprite constants:
| Code: |
//
// Crosshairs
//
SPR_CROSSHAIR1,SPR_CROSSHAIR2,CROSSHAIR3,
|
Now search for "gamestate". You should encounter the gamestate structure. Add under the "int ammo" definition: "int crosshair". It should now look like:
| Code: |
//---------------
//
// gamestate structure
//
//---------------
typedef struct
{
int difficulty;
int mapon;
long oldscore,score,nextextra;
int lives;
int health;
int ammo;
int crosshair; //This is the line you added
int keys;
weapontype bestweapon,weapon,chosenweapon;
int faceframe;
int attackframe,attackcount,weaponframe;
int episode,secretcount,treasurecount,killcount,
secrettotal,treasuretotal,killtotal;
long TimeCount;
long killx,killy;
boolean victoryflag; // set during victory animations
} gametype;
|
Save and close WL_DEF.H . Now open WL_DRAW.C and find the "DrawPlayerWeapon" function. Locate this statement inside:
| Code: |
void DrawPlayerWeapon (void)
{
int shapenum;
#ifndef SPEAR
if (gamestate.victoryflag)
{
if (player->state == &s_deathcam && (TimeCount&32) )
SimpleScaleShape(viewwidth/2,SPR_DEATHCAM,viewheight+1);
return;
}
#endif
|
And add this statement underneath:
| Code: |
if (gamestate.crosshair)
{
switch (gamestate.weapon)
{
case wp_pistol:
SimpleScaleShape(viewwidth/2,SPR_CROSSHAIR1,viewheight+1); break;
case wp_machinegun:
SimpleScaleShape(viewwidth/2,SPR_CROSSHAIR1,viewheight+1); break;
case wp_chaingun:
SimpleScaleShape(viewwidth/2,SPR_CROSSHAIR1,viewheight+1); break;
}
}
|
Now, open WL_AGENT.C and locate the CheckWeaponChange function. Add the following code just before the last '}':
| Code: |
if (Keyboard[sc_X] && !gamestate.crosshair)
InClearKeysDown ();
gamestate.crosshair=1;
else if (Keyboard[sc_X] && gamestate.crosshair)
InClearKeysDown ();
gamestate.crosshair=0;
|
To make the crosshair, open up an editor like FloEdit and add the three crosshair sprites.
Now when playing, press X and a crosshair will come up, and each weapon has it's own crosshair.
There you go
-Deathshead _________________ Myspace
VampireFreaks
Music4Life
Wolfing Time |
|