Dugtrio17 Code Master Joined: 12 Mar 2003 Last visit: Online
Now Posts: 137 Location: USA
Posted: Thu Apr 24, 2003 5:31 am
[1]
Post subject:
[Code] Gun Bobbing or Aminated Weapons - Dugtrio17
If you did the tutorial before May
26, 2003, look for the bold print with the edit.
Gun bobbing: a dream of many. And now you can do it! I
present you an adjustable tutorial on how to implement gun
bobbing in your TC. Quite simple really, and if you want any
change at all, just adjust a few numbers! Once again, it has
been tested from start to finish and works beautifully. If you
have any problems, gimme a yell at Dugtrio17@aol.com. And
Martin and JLB, lemme know if you want it in Kreml or
Battlestein
OK, open Wl_def.h and search for health.
Below int keys, type this:
::: CODE :::
int bobber;
int bobdir; int
bobber2; int
bobdir2;
Bobber is the up
and down bobbing, bobber2 is the left to right bobbing, and
bobdir and bobdir2 are the direction controllers. Save that
and close.
Open up Wl_draw.c and search for
DrawPlayerWeapon. Modify this:
::: CODE :::
if (gamestate.weapon != -1)
{ shapenum =
weaponscale[gamestate.weapon]+gamestate.weaponframe;
SimpleScaleShape(viewwidth/2,shapenum,viewheight+1);
}
if (demorecord || demoplayback)
SimpleScaleShape(viewwidth/2,SPR_DEMO,viewheight+1);
To this:
::: CODE :::
if (gamestate.weapon != -1)
{ shapenum =
weaponscale[gamestate.weapon]+gamestate.weaponframe;
SimpleScaleShape(viewwidth/2-10+gamestate.bobber2,shapenum,viewheight+1+gamestate.bobber);
}
if (demorecord || demoplayback)
SimpleScaleShape(viewwidth/2,SPR_DEMO,viewheight+1);}
You see the adding of the bobber and
bobber2 values. Since these values will change when you walk
(this will be applied next), the gun will bob. Also take a
look at how that 10 is subtracted. Make sure that 10 is equal
to half of whatever you have as the 20 below, or it'll look a
little lopsided. Now save and close that. Open up
Wl_agent.c and search for void Thrust. Below unsigned offset,
add this:
::: CODE :::
if (gamestate.bobdir != 2)
{gamestate.bobber++;} if
(gamestate.bobdir == 2) {gamestate.bobber--;}
if (gamestate.bobber == 10)
{gamestate.bobdir = 2;} if (gamestate.bobber == 0)
{gamestate.bobdir = 1;} if
(gamestate.bobdir2 != 2) {gamestate.bobber2++;}
if (gamestate.bobdir2 == 2)
{gamestate.bobber2--;} if (gamestate.bobber2 == 20)
{gamestate.bobdir2 = 2;} if
(gamestate.bobber2 == 0) {gamestate.bobdir2 =
1;}
EDIT! The tutorial now works on all
systems! See post below. If you did this before May 26, 2003,
take out that DrawPlayerWeapon (); that used to be there.
You'll see where it's put next. Take a close look
at that. When you walk at first, the values will go up, but
once they reach a certain number, the bobdir/bobdir2 values
change, and the gun will bob the other way. Also take a look
at that 20 and that 10. Keep that 20 twice the value of that
10, or your bobbing may look sloped.
Last thing: To
make sure you see the gun bobbing, look for the UpdateFace
function in Wl_agent.c (around 296 in the original code).
ABOVE [if (SD_SoundPlaying() == GETGATLINGSND)], put this:
::: CODE :::
DrawPlayerWeapon();
And there you go! You have a bobbing
gun now. Play around with those numbers up there if you want
(the 20 and the 10); modify them to suit your needs, though I
find those values work great. You could also modify this
tutorial to make certain guns/weapons bob more or less (or not
at all) with a few if statements.
Enjoy, and I hope to
see some people happy about this (especially Zach; when I told
him about the extremely light gun bobbing in Pikachu14's
BorgPanic demo, he got all excited and started typing in all
caps )
Last edited by Dugtrio17 on Tue May 27,
2003 8:02 am; edited 2 times in total
Dugtrio17 Code Master Joined: 12 Mar 2003 Last visit: Online
Now Posts: 137 Location: USA
Posted: Fri Apr 25, 2003 5:57 am
[2]
Post subject:
Quoting: Zach Attack
You know what we would be an excellent
follow-up to this tutorial? A tutorial on how to make it
possible to have an in-game switch to turn this off or on!
That's not that hard. All you have to
do is add a new variable as the on/off switch for the bobbing
(an int bobberswitch, or something like that. or you could add
a boolean to make a true/false switch, but I'd prefer the
variable).
Open the file wl_def.h, and search for the
'gamestate' type, and add the following line within the
structure:
::: CODE :::
int bobberswitch;
Then modify the start of the thrust
function (from the post above) to look like this:
::: CODE :::
if (gamestate.bobberswitch != 1) // see
below about that != { if (gamestate.bobdir !=
2) {gamestate.bobber++;} if
(gamestate.bobdir == 2) {gamestate.bobber--;}
if (gamestate.bobber == 10)
{gamestate.bobdir = 2;} if (gamestate.bobber == 0)
{gamestate.bobdir = 1;} if
(gamestate.bobdir2 != 2) {gamestate.bobber2++;}
if (gamestate.bobdir2 == 2)
{gamestate.bobber2--;} if (gamestate.bobber2 == 20)
{gamestate.bobdir2 = 2;} if
(gamestate.bobber2 == 0) {gamestate.bobdir2 = 1;}
DrawPlayerWeapon (); }
Of course that != should only be a !=
if you want the gun bobbing to be on automatically from the
start. otherwise, it should be == 1.
Then somewhere
appropriate in Wl_agent.c (though I always keep my "press a
key to do this" functions with the MLI cheat) [EDIT: Never
mind, go ahead and stick it in Wl_play.c], add something like
this:
[EDIT AGAIN:
Revised to set bobbing directions to 0 as well. In fact, I
made it set the variables to zero wrong, too! Cut me some
slack, I did this on the fly ] That 10 should be whatever the 10 is in the
edited ( ) line below. this way, without gun bobbing on, the
gun is drawn as if the gun bobbing never happened.
OK,
I think I got that
right. Someone let me know if I screwed that up, because I
don't have the source with me at this moment.
You
cannot post new topics in this forum You can reply to
topics in this forum You can edit your posts in this
forum You cannot delete your posts in this forum You
can vote in polls in this forum