Wolf3d Haven Forum

Please log in or register. Smile
Wolf3d Haven Forum

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


    [SDL code]Adding compass

    Share

    WLHack
    Senior Member
    Senior Member

    Male
    Number of posts : 798
    Age : 28
    Location : Finland
    Registration date : 2007-03-26

    [SDL code]Adding compass

    Post by WLHack on 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
    Spear of Destiny
    Spear of Destiny

    Male
    Number of posts : 643
    Age : 136
    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

    Re: [SDL code]Adding compass

    Post by jayngo26 on 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!



    http://jayngoware.com/

    WLHack
    Senior Member
    Senior Member

    Male
    Number of posts : 798
    Age : 28
    Location : Finland
    Registration date : 2007-03-26

    Re: [SDL code]Adding compass

    Post by WLHack on 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:


    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

    Re: [SDL code]Adding compass

    Post by Sponsored content Today at 12:20 pm


      Current date/time is Thu Dec 08, 2016 12:20 pm