DieHard Wolfers Forum Index DieHard Wolfers
A Wolfenstein 3d Fan Community


  Hosted by: MCS & Areyep.com - Designed by: BrotherTank

Original Yahoo Forum - Die Hard Archives

AReyeP HomepageAreyep Homepage DieHard Wolfenstein BunkerDieHard Wolfenstein Bunker Log inLog in RegisterRegister Banlist FAQFAQ Search ForumsSearch

  Username:    Password:      Remember me       

[code] Adding compass
Page 1 of 1
DieHard Wolfers Forum Index -> SDL Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page BottomView Next Topic
Post new topicReply to topic
Author Message
WLHack
DieHard Wolfer
DieHard Wolfer


Joined: 10 Jul 2005
Last Visit: 18 Jan 2018

Topics: 66
Posts: 1241
Location: Loppi - Finland
finland.gif

PostPosted: Sat Dec 26, 2009 3:43 pm
   Subject: [code] Adding compass
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

There is better ways to do this but as always - I post my version here...
First add this line to the end of wl_def.h:
::: CODE :::

extern bool compass;

Also in the same file, lets define sprites for compass:
::: CODE :::

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

    SPR_DIR_N,SPR_DIR_NE,SPR_DIR_E,SPR_DIR_SE,      //Directions N-SE
    SPR_DIR_S,SPR_DIR_SW,SPR_DIR_W,SPR_DIR_NW,      //Directions S-NW



Then in wl_play.c, just under the "Global variables" in the top of the file:
::: CODE :::

bool compass;


Then in wl_play.c scroll down to CheckKeys() and add this to it:
::: CODE :::

//------------------
// Compass
   if (Keyboard[sc_C])
   {   compass ^= true;
       Keyboard[ sc_C ] = false;
       return;
   }


Then open wl_draw.c and go to the DrawPlayerWeapon() and add this
to the end of the function:

::: CODE :::

//
// Check direction and draw compass (if enabled)
// Scale the compass as half of the normal size
// and place it to the right (top of everything)...
// 
if(compass){
  if (player->angle<110 && player->angle>=70)      //NORTH:      70 - 110 deg
  {   SimpleScaleShape(viewwidth-100,SPR_DIR_N,(viewheight+64)/2);}
  else if(player->angle<70 && player->angle>=20)   //NORTHEAST:  20 - 70 deg
  {   SimpleScaleShape(viewwidth-100,SPR_DIR_NE,(viewheight+64)/2);}
  else if(player->angle<340 && player->angle>=290) //SOUTHEAST:  290 - 340 deg
  {   SimpleScaleShape(viewwidth-100,SPR_DIR_SE,(viewheight+64)/2);}
  else if(player->angle<290 && player->angle>=250) //SOUTH:      250 - 290 deg
  {   SimpleScaleShape(viewwidth-100,SPR_DIR_S,(viewheight+64)/2);} 
  else if(player->angle<250 && player->angle>=200) //SOUTHWEST:  200 - 250 deg
  {   SimpleScaleShape(viewwidth-100,SPR_DIR_SW,(viewheight+64)/2);}
  else if(player->angle<160 && player->angle>=110)  //NORTHWEST: 110 - 160 deg
  {   SimpleScaleShape(viewwidth-100,SPR_DIR_NW,(viewheight+64)/2);}   
  else if(player->angle<200 && player->angle>=160) //WEST:       160 - 200 deg
  {   SimpleScaleShape(viewwidth-100,SPR_DIR_W,(viewheight+64)/2);}
  else                                             //EAST:       0 - 20 & 340 - 360 deg
  {   SimpleScaleShape(viewwidth-100,SPR_DIR_E,(viewheight+64)/2);}
  }
//---


This block checks players angle and according to it changes the needles position...
If you want you can add more needle positions and adjust the sectors to
make it look smoother... Pressing C in game will show the compass and pressing C
again will hide it...

Now to finish this feature - add this line:
::: CODE :::
compass = false;        //No compass

to the died-function in wl_game.c underneath "gamestate.keys = 0;",
also add it to the GameLoop underneath "case ex_completed:" in the
same file... And remember to add it NewGame in wl_main.c if you
don't want it to be visible right from the beginning...

_________________
False Spear download
False Spear SDL download
Wolfenstein-blog
Chris
DieHard Wolfer
DieHard Wolfer


Joined: 11 Mar 2003
Last Visit: 14 Nov 2018

Topics: 55
Posts: 2145
Location: Canada
blank.gif

PostPosted: Sat Dec 26, 2009 4:34 pm
   Subject: Re: [code] Adding compass
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Sweet. I think you could use a calculation for angles too, if you wanted:

::: CODE :::
short compass_dir = ((player->angle*2 + 45) / 90) % 8;

Where:
- 0 would be E (337.5 to 22.5 degrees)
- 1 would be NE (22.5 to 67.5 degrees)
- 2 would be N (67.5 to 112.5 degrees)
- 3 would be NW (112.5 to 157.5 degrees)
- 4 would be W (157.5 to 202.5 degrees)
- 5 would be SW (202.5 to 247.5 degrees)
- 6 would be S (247.5 to 292.5 degrees)
- 7 would be SE (292.5 to 337.5 degrees)

Then you could just rearrange the pictures into that order, and change the entire compass section to something like this:

::: CODE :::
if(compass) { SimpleScaleShape(viewwidth-100,SPR_DIR_E+compass_dir,(viewheight+64)/2) };

I think ID used something similar for the guards. Just a random idea, if you're really bored... and don't want all those if statements. Beer
WLHack
DieHard Wolfer
DieHard Wolfer


Joined: 10 Jul 2005
Last Visit: 18 Jan 2018

Topics: 66
Posts: 1241
Location: Loppi - Finland
finland.gif

PostPosted: Sun Dec 27, 2009 1:52 am
   Subject: [code] Adding compass
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Hehe... I knew there were a simplier way to do this.
Talk about the small code Chris.

_________________
False Spear download
False Spear SDL download
Wolfenstein-blog
AlumiuN
DieHard Wolfer
DieHard Wolfer


Joined: 29 Nov 2007
Last Visit: 8:53 ago.

Topics: 38
Posts: 2507
Location: Christchurch, New Zealand
newzealand.gif

PostPosted: Wed Dec 30, 2009 9:01 pm
   Subject: Re: [code] Adding compass
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

Actually, Ken's Labyrinth had exactly this compass (eight images on HUD). Smile
Display posts from previous:   
Post new topicReply to topic Time synchronized with the forum server time
DieHard Wolfers Forum Index -> SDL Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page TopView Next Topic
Page 1 of 1
Jump to:  

Related topics
 Topics   Replies   Views   Last Post 
No new posts Announcement: Wolf3d & Spear of Destiny Shareware SDL Downloads
Author: BrotherTank
10 16021 Tue Aug 24, 2010 10:18 am
dcbasic View latest post
No new posts Sticky: [Tutorial] Compiling Wolf4SDL with Code::Blocks
Author: dcbasic
90 27517 Wed May 24, 2017 7:53 pm
Falcon*93 View latest post
No new posts [help] Adding teleporters in wolf4sdl
Author: Mortimer
35 11726 Fri May 26, 2017 8:19 am
Military View latest post
No new posts [Help] Adding a weapon problem
Author: Zombie_Plan
10 2266 Thu Jul 24, 2008 4:26 pm
RichterBelmont12 View latest post
No new posts [Help] Problem with Checkweaponchange function (wolf4sdl)
Author: Mortimer
4 3375 Sat May 17, 2008 11:26 am
Mortimer View latest post
 
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


Copyright ©2003-2008 DieHard Wolfers
A Modified subBunker Theme by BrotherTank
Powered by phpBB © 2001, 2005 phpBB Group