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       

Adding Strafe left/right keys (one button strafing)
Page 1 of 1
DieHard Wolfers Forum Index -> Code Tutorials 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
Hair Machine
DieHard SS
DieHard SS


Joined: 24 Nov 2003
Last Visit: 22 Dec 2017

Topics: 8
Posts: 431
Location: editing my profile
uk.gif

PostPosted: Mon Apr 19, 2004 12:13 pm
   Subject: Adding Strafe left/right keys (one button strafing)
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

This code will allow the player to strafe left and right using the A and D keys. It's easy to change these keys to whatever you desire, if you happen not to like A and D. HOWEVER, this tutorial does not allow the player to specify which keys he/she would like to use. Someone could make this improvement, maybe?
Also, this is my first tutorial (eek!) so I'm aware that it might be quite poor, with lots of wasted code. But then again, it works perfectly, so why worry? But I'm sure some genius could improve it quite a bit.
Well, with that said, here goes. The red lines indicate code you should add:

First, open WL_DEF.H. Make a search for "controlx" (excluding quotes). Make these changes:

::: CODE :::

extern int   controlx,controly,strafe;




There! Save that and open up WL_PLAY.C. Once again make a search for controlx:

::: CODE :::

//
// curent user input
//
int         controlx,controly,strafe;


Now make another search for controlx:

::: CODE :::

void PollKeyboardMove (void)
{
   if (buttonstate[bt_run])
   {
      if (Keyboard[dirscan[di_north]])
         controly -= RUNMOVE*tics;
      if (Keyboard[dirscan[di_south]])
         controly += RUNMOVE*tics;
      if (Keyboard[dirscan[di_west]])
         controlx -= RUNMOVE*tics;
      if (Keyboard[dirscan[di_east]])
         controlx += RUNMOVE*tics;

      if (Keyboard[sc_A])
         strafe -= RUNMOVE*tics;
      if (Keyboard[sc_D])
         strafe += RUNMOVE*tics;

   }
   else
   {
      if (Keyboard[dirscan[di_north]])
         controly -= BASEMOVE*tics;
      if (Keyboard[dirscan[di_south]])
         controly += BASEMOVE*tics;
      if (Keyboard[dirscan[di_west]])
         controlx -= BASEMOVE*tics;
      if (Keyboard[dirscan[di_east]])
         controlx += BASEMOVE*tics;

      if (Keyboard[sc_A])
         strafe -= BASEMOVE*tics;
      if (Keyboard[sc_D])
         strafe += BASEMOVE*tics;

   }
}


Now go down to the function PollControls, another 20 or so lines down. Find this block and make these changes:

::: CODE :::

                CalcTics ();

   controlx = 0;
   controly = 0;
   strafe = 0;
   memcpy (buttonheld,buttonstate,sizeof(buttonstate));
   memset (buttonstate,0,sizeof(buttonstate));

   if (demoplayback)
   {
   //
   // read commands from demo buffer
   //
      buttonbits = *demoptr++;
      for (i=0;i<NUMBUTTONS;i++)
      {
         buttonstate[i] = buttonbits&1;
         buttonbits >>= 1;
      }

      controlx = *demoptr++;
      controly = *demoptr++;
      strafe = *demoptr++;
      
      if (demoptr == lastdemoptr)
         playstate = ex_completed;      // demo is done

      controlx *= (int)tics;
      controly *= (int)tics;
      strafe *= (int)tics;

      return;
   }


//
// get button states
//
   PollKeyboardButtons ();

   if (mouseenabled)
      PollMouseButtons ();

   if (joystickenabled)
      PollJoystickButtons ();

//
// get movements
//
   PollKeyboardMove ();

   if (mouseenabled)
      PollMouseMove ();

   if (joystickenabled)
      PollJoystickMove ();

//
// bound movement to a maximum
//
   max = 100*tics;
   min = -max;
   if (controlx > max)
      controlx = max;
   else if (controlx < min)
      controlx = min;


   if (controly > max)
      controly = max;
   else if (controly < min)
      controly = min;

   if (strafe > max)
      strafe = max;
   else if (strafe < min)
      strafe = min;


   if (demorecord)
   {
   //
   // save info out to demo buffer
   //
      controlx /= (int)tics;
      controly /= (int)tics;
      strafe /= (int)tics;

      buttonbits = 0;

      for (i=NUMBUTTONS-1;i>=0;i--)
      {
         buttonbits <<= 1;
         if (buttonstate[i])
            buttonbits |= 1;
      }

      *demoptr++ = buttonbits;
      *demoptr++ = controlx;
      *demoptr++ = controly;
      *demoptr++ = strafe;

      if (demoptr >= lastdemoptr)
         Quit ("Demo buffer overflowed!");

      controlx *= (int)tics;
      controly *= (int)tics;
      strafe *= (int)tics;
   }
}



There! Now close WL_PLAY.C and open WL_AGENT.C (aaah yes! My favourite file!)
Search for the function ControlMovement. Directly below
"oldy = player->y;" add this block:

::: CODE :::

if (Keyboard[sc_A])
   {
   //
   // strafing
   //
   //
      if (strafe > 0)
      {
         angle = ob->angle - ANGLES/4;
         if (angle < 0)
            angle += ANGLES;
         Thrust (angle,strafe*MOVESCALE);   // move to left
      }
      else if (strafe < 0)
      {
         angle = ob->angle + ANGLES/4;
         if (angle >= ANGLES)
            angle -= ANGLES;
         Thrust (angle,-strafe*MOVESCALE);   // move to right
      }
   }

   if (Keyboard[sc_D])
   {
   //
   // strafing
   //
   //
      if (strafe > 0)
      {
         angle = ob->angle - ANGLES/4;
         if (angle < 0)
            angle += ANGLES;
         Thrust (angle,strafe*MOVESCALE);   // move to left
      }
      else if (strafe < 0)
      {
         angle = ob->angle + ANGLES/4;
         if (angle >= ANGLES)
            angle -= ANGLES;
         Thrust (angle,-strafe*MOVESCALE);   // move to right
      }
   }




That looks very wasteful, but I found it very hard to get it to work with less code. Probably because I'm a retard, but anyway, this works; so if you don't care about lots of code, do the above!

That's it! Now, in game, when the A key is pressed, the player strafes left, and is able to turn normally at the same time; while when the D key is pressed, he is able to strafe right and turn normally at the same time. Enjoy! Any problems, let me know... Thanks!

REALLY EFFING LATE EDIT: There were a couple of errors where I retardedly missed brackets on a couple of bits. Thanks to lwmxynedtodth for pointing it out below.

_________________
Rar rar fiddle di dee


Last edited by Hair Machine on Fri Aug 03, 2007 9:01 am; edited 2 times in total
KyleRTCW
DieHard Officer
DieHard Officer


Joined: 30 Jul 2003
Last Visit: 02 Jun 2018

Topics: 45
Posts: 510
Location: Ohio
usa.gif

PostPosted: Mon Apr 19, 2004 12:54 pm
   Subject: Re: Adding Strafe left/right keys (one button strafing)
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I will test it! But HairMachine, one question, Could this be possible to add to the control menu to allow the player to customize the key? Cause, you know, not everyone use the same key config. Thanks for the tutorial though!

_________________
Steam: http://steamcommunity.com/id/stormx312
Hair Machine
DieHard SS
DieHard SS


Joined: 24 Nov 2003
Last Visit: 22 Dec 2017

Topics: 8
Posts: 431
Location: editing my profile
uk.gif

PostPosted: Mon Apr 19, 2004 1:00 pm
   Subject: Re: Adding Strafe left/right keys (one button strafing)
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Yes, I'm almost certain it would. But that would require editing all over the place; for example you would have to change the design of the control calibration menus - at the moment they don't have enough room to put extra keys on there. I hope that made sense... Anyway, that's the bit I'm looking into. If I manage to work it out, I'll probably do an update at some point.
Let me know if that works though!

_________________
Rar rar fiddle di dee
Adam Biser
Utility Developer
Utility Developer


Joined: 06 Jun 2003
Last Visit: 08 Aug 2018

Topics: 46
Posts: 2313
Location: USA
usa.gif

PostPosted: Mon Apr 19, 2004 1:37 pm
   Subject: Re: Adding Strafe left/right keys (one button strafing)
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Looks good Hair Machine... I've not tried it, but that looks like how I think mine would have to be changed... well somewhat similiar...
The problem with mine is that I was trying to make do without adding the global strafe variable, which didn't work 100% as expected.

You could add another menu for 'extra controls' or whatever so that you don't have to try rearranging the currently existing configuration screen.
Just a thought. I haven't looked into it much.

_________________
Orb of Dilaaria now has a Facebook page
Star Wars: Bloodlines now has a Facebook page
KyleRTCW
DieHard Officer
DieHard Officer


Joined: 30 Jul 2003
Last Visit: 02 Jun 2018

Topics: 45
Posts: 510
Location: Ohio
usa.gif

PostPosted: Mon Apr 19, 2004 1:56 pm
   Subject: Re: Adding Strafe left/right keys (one button strafing)
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Great News! It works! Thank you so much HairMachine! I will post you in my credits! Very Happy

_________________
Steam: http://steamcommunity.com/id/stormx312
Hair Machine
DieHard SS
DieHard SS


Joined: 24 Nov 2003
Last Visit: 22 Dec 2017

Topics: 8
Posts: 431
Location: editing my profile
uk.gif

PostPosted: Mon Apr 19, 2004 3:12 pm
   Subject: Re: Adding Strafe left/right keys (one button strafing)
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Glad to hear it! Pleased I could help you... Mr Green
The extra menu thing was what I had in mind too; similar to Halls of Stonehenge. Maybe one for keyboard controls and one for mouse/joystick controls? Interesting...

_________________
Rar rar fiddle di dee
TexZK
DieHard SS
DieHard SS


Joined: 07 Feb 2004
Last Visit: 19 Oct 2016

Topics: 19
Posts: 370
Location: Northern Italy
italy.gif

PostPosted: Wed Apr 21, 2004 1:17 pm
   Subject: Re: Adding Strafe left/right keys (one button strafing)
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Well, Adam, I think yours it isn't the only bug. Try to press a binded key and turn right when you're walking backward... you'll go backward without turning! This happens in some TC, even if you didn't change the priority of any key!
lwmxynedtodth
DieHard Officer
DieHard Officer


Joined: 28 May 2006
Last Visit: 24 Aug 2017

Topics: 38
Posts: 570
Location: Neverland
netherlands.gif

PostPosted: Sun Sep 03, 2006 8:48 am
   Subject: Re: Adding Strafe left/right keys (one button strafing)
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I might be a retard, but I think there are two times a ) missing.
::: CODE :::

if (Keyboard[sc_A])
   {
   //

-
::: CODE :::

if (Keyboard[sc_D])
   {
   //


However, great code! Thanks.

- lwmxynedtodth

_________________
lwmxynedtodth (portfolio, blog and more)
Killer-suit: Masterminds
On a MMORPG trip.
Zombie_Plan
DieHard Wolfer
DieHard Wolfer


Joined: 12 Oct 2004
Last Visit: 07 Jun 2016

Topics: 101
Posts: 1614
Location: A hole in the wall
australia.gif

PostPosted: Wed Sep 06, 2006 7:16 pm
   Subject: Re: Adding Strafe left/right keys (one button strafing)
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Well as long as you dont simply copy&paste it your fine Razz

_________________
Zombieskittles

Welcome to 2016, where DHW still thinks it is okay to ban the world's most popular email service provider, and I can't have an avatar over 10kb
ronwolf1705
Moderator
<B>Moderator</B>


Joined: 31 Jul 2006
Last Visit: 8:19 ago.

Topics: 72
Posts: 3762

blank.gif

PostPosted: Sat Sep 09, 2006 1:26 pm
   Subject: Re: Adding Strafe left/right keys (one button strafing)
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I want do to add something so that you can change the controls in the controls menu. How do you code this?
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 14 Aug 2018

Topics: 87
Posts: 759
Location: Wisconsin
usa.gif

PostPosted: Sun Feb 11, 2007 11:23 am
   Subject: Re: Adding Strafe left/right keys (one button strafing)
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I have attempted to place it in the Customize Controls menu, so far it doesn't work, when I move the cursor over it, it prints "Abnormal Program Termination" and "Divide Error". I am missing a lot, and I would think it would be better if someone posted a step-by-step tutorial on how to do this.

_________________
I'm back! I missed this community!
Youtube Channel: TreeSapThief

New Site: http://www.treesapthief.com
Twitter: @treesapthief
Zombie_Plan
DieHard Wolfer
DieHard Wolfer


Joined: 12 Oct 2004
Last Visit: 07 Jun 2016

Topics: 101
Posts: 1614
Location: A hole in the wall
australia.gif

PostPosted: Mon Feb 12, 2007 5:44 pm
   Subject: >.< ach i need to get back into coding NEED MORE CAFFI
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

insurrectionman wrote:
I have attempted to place it in the Customize Controls menu, so far it doesn't work, when I move the cursor over it, it prints "Abnormal Program Termination" and "Divide Error". I am missing a lot, and I would think it would be better if someone posted a step-by-step tutorial on how to do this.


of course...when you cant get it...try and get someone else to do it O_o maybe try and work Jamez's tutorial for custom menus in, pm someone for help (without asking them to do it ALL o.o), or just ask for help here about fixing the error?

_________________
Zombieskittles

Welcome to 2016, where DHW still thinks it is okay to ban the world's most popular email service provider, and I can't have an avatar over 10kb
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 14 Aug 2018

Topics: 87
Posts: 759
Location: Wisconsin
usa.gif

PostPosted: Tue Feb 13, 2007 1:35 pm
   Subject: Re: Adding Strafe left/right keys (one button strafing)
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Well, I have done what I can, and have come to a point that I cannot proceed farther, maybe there is someone who can do it. I'm not imposing that someone does all the dirty work all the time. Although, when I posted I never stopped to think about who knew how to do it, so I might take a PM into consideration.

_________________
I'm back! I missed this community!
Youtube Channel: TreeSapThief

New Site: http://www.treesapthief.com
Twitter: @treesapthief
Ultimator
Registered User
Registered User


Joined: 30 Oct 2005
Last Visit: 17 Jun 2008

Topics: 2
Posts: 22

usa.gif

PostPosted: Mon Jun 18, 2007 11:46 am
   Subject: Re: Adding Strafe left/right keys (one button strafing)
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

Sorry to bump an old thread, but I'm messing around with replacing the Gamepad controls with the strafe definitions, because I don't think anyone plays Wolf with a Gamepad anymore. I'm just now getting started; if I get it working (I'm not a code master by any means, I'm more a level designer these days), I'll post an update into this tutorial.
Display posts from previous:   
Post new topicReply to topic Time synchronized with the forum server time
DieHard Wolfers Forum Index -> Code Tutorials 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 [Code] Display Different Ammo Types on Statusbar-BrotherTank
Author: BrotherTank
1 2723 Fri Feb 11, 2005 9:18 pm
Zombie_Plan View latest post
No new posts [Code] Adding a Frames per Second Counter - Darkone
Author: BrotherTank
0 1989 Sat Mar 13, 2004 2:07 pm
BrotherTank View latest post
No new posts [Code] Changing an Enemies Attack Strength - BrotherTank
Author: BrotherTank
0 2300 Tue Jan 27, 2004 10:29 am
BrotherTank View latest post
No new posts [Info] Giving a Guard a Rocket Launcher
Author: Guest
4 194 Fri Jan 23, 2004 1:58 pm
Guest View latest post
No new posts [Code] Changing Weapons -CheckWeaponChange- BrotherTank
Author: BrotherTank
2 3088 Sun Oct 26, 2003 1:21 am
Guest 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