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

View previous topic View next topic Go down

(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:

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

Hope that helps

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

Posts : 323
Join date : 2015-10-02
Age : 19

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

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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