View Full Version: [Tutorial] Adding the crosshair

wolfers >>Coding Alliance >>[Tutorial] Adding the crosshair


<< Prev | Next >>

Deathshead- 04-06-2005
[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: // // 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: //--------------- // // 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: 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: 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 '}': 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


Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.