(Old code tutorial) Adding the crosshair from Wolf Planet forum

Go down

(Old code tutorial) Adding the crosshair from Wolf Planet forum Empty (Old code tutorial) Adding the crosshair from Wolf Planet forum

Post by Officer-M. John (Admin) on Tue Nov 29, 2016 11:16 am

Here's my tutorial I wrote a little bit ago:

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

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,
   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) )

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)
    else if (Keyboard[sc_X] && gamestate.crosshair)

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

Hope that helps

Writte by Deathshead on Wed Apr 06, 2005 11:34 am
Officer-M. John (Admin)
Officer-M. John (Admin)

Posts : 422
Join date : 2015-10-02
Age : 21

View user profile http://wolf3dfanboys.forumotion.com

Back to top Go down

Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum