Wolf Planet Forum Index Wolf Planet
We want you here!
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Tutorial] Adding the crosshair

 
Post new topic   Reply to topic    Wolf Planet Forum Index -> Coding Alliance
View previous topic :: View next topic  
Author Message
Deathshead
Corporal


Joined: 18 Feb 2005
Posts: 87

PostPosted: Wed Apr 06, 2005 11:34 am    Post subject: [Tutorial] Adding the crosshair Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Wolf Planet Forum Index -> Coding Alliance All times are GMT
Page 1 of 1

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001 phpBB Group

Chronicles phpBB2 theme by Jakob Persson (http://www.eddingschronicles.com). Stone textures by Patty Herford.