Wolf3d Haven Forum

Please log in or register. Smile

Join the forum, it's quick and easy

Wolf3d Haven Forum

Please log in or register. Smile

Wolf3d Haven Forum

Would you like to react to this message? Create an account in a few clicks or log in to continue.
Wolf3d Haven Forum

A friendly Wolfenstein 3D community, about Wolfenstein 3D, the game that gave birth to first person shooters...


2 posters

    [SDL code]Adding compass

    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [SDL code]Adding compass Empty [SDL code]Adding compass

    Post by WLHack Thu Jan 21, 2010 2:12 am

    Here is a small piece of code to make compass (8 dirs) appear in-game when you press 'C'
    (Remember to credit Chris for showing easier way to detect compass direction).

    First add this line to the end of wl_def.h:
    Code:
    extern bool compass;

    Then in the same file - define the sprites for the compass:
    Code:

        SPR_CHAINREADY,SPR_CHAINATK1 ,SPR_CHAINATK2 ,SPR_CHAINATK3,
    SPR_CHAINATK4, //Might differ from your code:

      //Add these lines:
        SPR_DIR_E,SPR_DIR_NE,SPR_DIR_N,SPR_DIR_NW, //Directions E-NW
        SPR_DIR_W,SPR_DIR_SW,SPR_DIR_S,SPR_DIR_SE, //Directions W-SE

    Then in wl_play.c - just add this line under "global variables":
    Code:
    bool compass;

    Then scroll down to CheckKeys() in the same file and add this to it
    (for example - just before the MLI):
    Code:
    //------------------

    // Compass

      if (Keyboard[sc_C])

      {  compass ^= true;

          Keyboard[ sc_C ] = false;

          return;

      }

    Then open up wl_draw.c and go down to DrawPlayerWeapon()...
    Add this line to the beginning of the function:
    Code:
    short compass_dir = ((player->angle*2 + 45) / 90) % 8;  //by Chris
    // short compass_dir=((player->angle*4+45)/90)%16:   
    (The commented out line is for making the compass to have 16 different positions
    but you have to add more sprites for the compass if you decide to enable it)
    And then in the end of the function this line:
    Code:
    if(compass) { SimpleScaleShape(viewwidth-100,SPR_DIR_E+compass_dir,(viewheight+64)/2) }; //by Chris



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    jayngo26
    jayngo26
    Spear of Destiny
    Spear of Destiny


    Male
    Number of posts : 643
    Age : 144
    Location : Random
    Job : Partime Evil Semi-Genius Plotting To Take Over Half The World. Partime Undead Charged With Keeping the Darkness Dark
    Hobbie : Staying Out Of Sunlight
    Message : Wolfenstein:Umbrella Beginnings Episode 2 released! Download now!

    Registration date : 2008-08-09

    [SDL code]Adding compass Empty Re: [SDL code]Adding compass

    Post by jayngo26 Thu Jan 21, 2010 12:53 pm

    Now this is a cool feature. Looks like it doesn't take up too much memory either. Although, I have some questions..

    1. Will this code work for normal dos version of coding Wolf?
    2. I noticed you defined some sprites in wl_def.h. Do I need to add actual sprites to the engine? If so, how many? 8? Do they go in the VGAGraph?
    3. Also, from what I see, the compass will show up where the weapon normally is in the HUD. If so, does it stay there until you press "C" again?

    Thanks! And, nice work WLHack! [SDL code]Adding compass Icon_cool



    http://jayngoware.com/
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [SDL code]Adding compass Empty Re: [SDL code]Adding compass

    Post by WLHack Thu Jan 21, 2010 2:35 pm

    1. It should work as there isn't much difference.
    2. Nope they're normal sprites (8 in total and after Chaingun in VSWap)...
    Sprites in VGAGraph (better known as chuncks) are added to GFXV_* files.
    3. Here is a small screenshot showing the feature:
    [SDL code]Adding compass Send

    If I remember right - SimpleScaleShapes parameters are these:
    x-position, shapenum (sprite), scale
    So basically the line for drawing the compass says something like this:
    Position the compass to current views width - 100px,
    draw as first compass sprite + direction and then scale it
    to a half of the screens height + 64px...



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...

    Sponsored content


    [SDL code]Adding compass Empty Re: [SDL code]Adding compass

    Post by Sponsored content


      Current date/time is Fri Nov 08, 2024 11:23 am