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] Creating Animated Static Objects Tutorial
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
WSJ
Guest



Last Visit:





PostPosted: Thu Aug 28, 2003 2:43 pm
   Subject: [Code] Creating Animated Static Objects Tutorial
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

After screwing around with the Wolfenstein source code, I've finally discovered a method to make animated static objects which are still "static objects" and NOT "actor objects." In other words, taking non-animated scenery (ceiling lights, barrels, etc.) and giving them multiple animation frames instead of just one frame (again, I'd like to thank DarkOne for giving me the idea from his "animated walls" tutorial). Using this method, it's possible to create animated objects which are stationary, such as flaming torches, bubbling acid, etc.

Now, I know there are already tutorials out there which tell how to turn the Pacman Ghosts into animated scenery. So why is this way better? Here are some benefits you get from it:

* you don't have to make the animated objects shootable in order to be blockable

* you don't have to mess around with all the actor code in order to add new animated objects

* adding new animated static objects takes up less memory than adding stationary "actors"

* since we're using static objects, they don't count towards the "MAXACTORS" limit the way stationary ghosts do (ie, you can have up to 400 of them per level)

For those of you who haven't figured it out before, this is how it's done (at least I think so.)

CAUTION: This code might be a little tricky, and I'm not the greatest person to explain things... but I try.

-----------

Now to start, open WL_DEF.H. Look for this:
::: CODE :::

// object flag values

#define FL_SHOOTABLE   1
#define FL_BONUS      2
#define FL_NEVERMARK   4
#define FL_VISABLE      8
#define FL_ATTACKMODE   16
#define FL_FIRSTATTACK   32
#define FL_AMBUSH      64
#define FL_NONMARK      128


Below that, add this:
::: CODE :::

#define FL_ANIMATED   1


Next, scroll down to where it looks like this:
::: CODE :::

typedef enum {
   dressing,
   block,
   bo_gibs,
   bo_alpo,
   bo_firstaid,
   bo_key1,
   bo_key2,
   bo_key3,
   bo_key4,
   bo_cross,
   bo_chalice,
   bo_bible,
   bo_crown,
   bo_clip,
   bo_clip2,
   bo_machinegun,
   bo_chaingun,
   bo_food,
   bo_fullheal,
   bo_25clip,
   bo_spear
} stat_t;


Add the two marked in blue:

bo_machinegun,
bo_chaingun,
bo_food,
bo_fullheal,
bo_25clip,
bo_spear,
anim,
anim_block

} stat_t;


I've added two different flags, one for a normal animated object, and one for a blocking animated object.

Save WL_DEF.H. Now, open WL_DRAW.C. In the "DrawScaleds" function, look for this part of the code:
::: CODE :::

//
// place static objects
//
   for (statptr = &statobjlist[0] ; statptr !=laststatobj ; statptr++)
   {
      if ((visptr->shapenum = statptr->shapenum) == -1)
         continue;                  // object has been deleted

      if (!*statptr->visspot)
         continue;                  // not visable


Beneath that, add this:
::: CODE :::

      if (statptr->flags & FL_ANIMATED)
      {
         visptr->shapenum+=(frameon>>3)%2;
      }


In this example, I'm giving the object 2 animation frames. You can adjust this by changing the "%2" to something else (ex: "%3" draws an animation of 3 frames). You can also change how much time a frame is displayed in the animation by adjusting the "(frameon>>3)" to something like "(frameon>>4)" or whatever.

Save WL_DRAW.C. Next, open WL_ACT1.C. Go down until you see this:
::: CODE :::

case   bo_food:
   case   bo_alpo:
   case   bo_gibs:
   case   bo_spear:
      laststatobj->flags = FL_BONUS;
      laststatobj->itemnumber = statinfo[type].type;
      break;


Right beneath that, add this:
::: CODE :::

   case   anim_block:
      (unsigned)actorat[tilex][tiley] = 1;
   case   anim:
      laststatobj->flags = FL_ANIMATED;
                break;


(Make sure you add this within the closing "}" brace at the end of the list.)

You now have 2 new static object flags which trigger animation in whichever static object you place them in. For example, if you wanted to make the pool of water an animated blocking object, you would look for this:
::: CODE :::

{SPR_STAT_0},               // puddle          spr1v


...and change it to this:

{SPR_STAT_0,anim_block}, // animated object


(Of course, you'll need to replace the green barrel with your second animation frame.)

Save and compile everything. Then test it in your game. If all went well, your object will be animated!

-----------

From what I've seen, it works... but I haven't fully tested this feature, so I'd appreciate it if someone would try it out.
Ripper
Code Master - Developer
Code Master - Developer


Joined: 15 Mar 2003
Last Visit: 30 Sep 2008

Topics: 21
Posts: 527
Location: Germany
blank.gif

PostPosted: Sun Aug 31, 2003 5:38 am
   Subject: Re: Animated Static Objects Tutorial
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Sounds nice and easy to understand Wink

Good work!
WSJ
Guest



Last Visit:





PostPosted: Sun Aug 31, 2003 6:56 am
   Subject: Re: Animated Static Objects Tutorial
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Thanks, Ripper. Smile
KyleRTCW
DieHard Officer
DieHard Officer


Joined: 30 Jul 2003
Last Visit: 09 Nov 2017

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

PostPosted: Wed Jan 14, 2004 4:37 pm
   Subject: Animated Objects
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I wanted to add some animated objects to my TC, without doing as using an enemy, becuase there are some annoying bugs with that.

Is there a way to creat animated objects that are not enemy type objs, (i.e. NOT ghosts)

Like in Spear Ressurection, the torch (and breakable column) are not "enemy" types.

Can some one help me with it?
Thanks

_________________
Steam: http://steamcommunity.com/id/stormx312
Loki
I am Death Incarnate
I am Death Incarnate


Joined: 07 Dec 2003
Last Visit: 12 Apr 2014

Topics: 3
Posts: 170
Location: Paris
france.gif

PostPosted: Wed Jan 14, 2004 5:00 pm
   Subject: Re: Animated Objects
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Maybe this link can help you Mr Green :

http://diehardwolfers.areyep.com/viewtopic.php?t=868

It's a tutorial by Wolf Skevos Jones for create animateds statics objects or something like that. Wink
KyleRTCW
DieHard Officer
DieHard Officer


Joined: 30 Jul 2003
Last Visit: 09 Nov 2017

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

PostPosted: Wed Jan 14, 2004 5:02 pm
   Subject: Re: Animated Objects
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Thanks Loki!

oui!

_________________
Steam: http://steamcommunity.com/id/stormx312
Anonymous
Guest



Last Visit:





PostPosted: Thu Feb 01, 2007 4:35 am
   Subject: Re: [Code] Creating Animated Static Objects Tutorial
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Really nice Smile
Just what I was looking for.


But is it also possible by this code, to make objects like treasures and guns animated?
ronwolf1705
Moderator
<B>Moderator</B>


Joined: 31 Jul 2006
Last Visit: 9:46 ago.

Topics: 69
Posts: 3673

blank.gif

PostPosted: Thu Feb 01, 2007 5:16 am
   Subject: Re: [Code] Creating Animated Static Objects Tutorial
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I think it is. There's also a much easier version of this code somewhere in the Code Tutorials section. (BTW is that Skate in your avatar?)
the_fish
Bring 'em On
Bring 'em On


Joined: 18 Nov 2006
Last Visit: 07 Nov 2008

Topics: 12
Posts: 133
Location: England
uk.gif

PostPosted: Thu Feb 01, 2007 5:50 am
   Subject: Re: [Code] Creating Animated Static Objects Tutorial
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I don't think so...not by that method, anyway.

Easiest way I found to make animated sprites for anything (even bo_objects/weapons) is to add a 'long timer_anim;' to the gametype structure in WL_DEF.h, and plop the following function in WL_SCALE.c, above the sprite drawing functions:

::: CODE :::

// ANIMATED SPRITES
int GiveAnimationOffset(int shapenum)
{
    // returns an offset to the base shapenum based on time
    switch (shapenum)
    {
       case SPR_ANIM_0: // or whatever
            return ((gamestate.timer_anim/70)%2); // 2 frames/70 tics per frame (1 second)
        default:
            return 0;
    }
}


And in the PlayLoop in WL_PLAY, just after the "Funny Face" block, add
::: CODE :::

    gamestate.timer_anim+=tics;
    gamestate.timer_anim%=140;
    /* remember 70 tics/second, so this will support total cycle time of 2 seconds tops.  Just increase the 140 if you want*/


In the offset code, ((gamestate.timer_anim/a)%b) means it's looking for 'b' animation frames, and the 'a' controls the speed of the animation (new frame every 'a' tics, provided a*b <= (cycle time) and also neatly divides it).

Now in WL_SCALE, in ScaleShape and SimpleScaleShape, just after the initial declarations and before the sprite is loaded from memory (the PM_GetSpritePage bit), add
::: CODE :::
shapenum+=GiveAnimationOffset(shapenum);


-----------------

Now all you have to do to have animated sprites is add sprites to the VSWAP as you would normally, but with consecutive frames in consecutive slots (remember to put ALL the frames in WL_DEF, even though you'll only reference the first one). Then create a new object/use an old one/leave weapons as they are, but add the animation sprites immediately after the one you want to animate in the vswap, referencing the FIRST ANIMATION FRAME as the sprite used. It should now animate, regardless of what it is or where it's found.

Actually, I guess it's not THAT simple but it's versatile. It bypasses all the code that makes the object do whatever it is it does, and just concentrates on the graphics, so animated treasure is now easy!

---------

Example: Animated pistol (idle) anim, 4 frames, 0.5 seconds per frame (with the cycle length being 140 as above)

1) Add this to the GiveAnimationOffset switch statement, before the default: case.
::: CODE :::

case SPR_PISTOLREADY:
    return ((gamestate.timer_anim/35)%4);


2) Add three more pistol animation frames to your VSWAP using an editor, between the 'ready' sprite and the first attack frame.

3) Add "SPR_PISTOL_RANIM1, SPR_PISTOL_RANIM2, SPR_PISTOL_RANIM3," to the big list of sprites in WL_DEF, immediately after "SPR_PISTOLREADY,"

and we're done!

-----------

DISCLAIMER: this has been tested in Wolf4GW, but not Borland. I think it'll still work, but it might not (could be some syntax problems or whatever. try it and PM/reply/whatever, and I'll try to fix)

Smile

EDIT: might not be clear how to have cycle lengths less than 2 secs with this code: use "((gamestate.timer_anim/14)%5);" for example to get 5 frames each lasting 14 tics (0.2 seconds), looping every second. Play around with numbers, see what happens.
Anonymous
Guest



Last Visit:





PostPosted: Thu Feb 01, 2007 11:18 pm
   Subject: Re: [Code] Creating Animated Static Objects Tutorial
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Wow, thanks for the help Smile

I hope I will get this working, since I'm not that experienced. Wink
I learned the coding with Borland. Is the Wolf4GW any different from that?
the_fish
Bring 'em On
Bring 'em On


Joined: 18 Nov 2006
Last Visit: 07 Nov 2008

Topics: 12
Posts: 133
Location: England
uk.gif

PostPosted: Fri Feb 02, 2007 3:13 am
   Subject: Re: [Code] Creating Animated Static Objects Tutorial
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Yes, in some ways...but not in any that should stop the above working. There *might* be a few syntax problems that aren't allowed in Borland, but the actual code should all work fine (it's just dealing with offsets and a switch statement, really).

I think the above is reasonably clear, though I guess I didn't explain the first step too thoroughly: open WL_DEF.h, search for "gametype", then add the line
::: CODE :::
long timer_anim;
in the structure above it, say, below 'health' or something. Oh, and my code doesn't require any of the changes mentioned in the first post in this tutorial.

Wolf4GW is a port by Ripper from DOS to DOS4GW, which basically increases the memory limit hugely. This tends to stop 'abnormal program termination' errors - it allows you to have loads more sounds and graphics (hi-res too), and load everything into main memory instead of messing about with near and far memory so the engine runs a bit smoother. On the flipside, a few routines work differently so *most* tutorials (mainly the graphical ones) won't transfer across perfectly. Having said that I've appended some 4GW fixes to the end of a few graphics tutorial threads, but they're not cut and paste ready so I recommend you know what you're doing first.

_________________
Mostly away: revising for finals (argh!)
BrotherTank
Forum Administrator
<B>Forum Administrator</B>


Joined: 01 Mar 2003
Last Visit: 13 Sep 2017

Topics: 153
Posts: 2256
Location: Ontario
canada.gif

PostPosted: Wed Mar 21, 2007 5:12 pm
   Subject: [Code] Creating Animated Static Objects Tutorial
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Actually Fish... I found something while digging through Darkone's source that made this even simpler.

In WL_Def.H file add:

byte anim;

to the statstruct structure (search: // trivial actor structure

Next in wl_act1.c file add:

#define MAKEANIM(spd, frames) (((spd)<<4)+(frames))

at the top of the file before the 'statinfo_t;' type define. In the "statinfo_t;" type define add:

byte anim;

Also in wl_act1.c add to the SpawnStatic & PlaceStaticItem routines the line:

laststatobj->anim = statinfo[type].anim;


Then in wl_draw.c file add this line in the DrawScaleds function:

if(statptr->anim) visptr->shapenum+=(gamestate.TimeCount/(statptr->anim>>4))%(statptr->anim&15);

That line should be added after the line:

if(!visptr->viewheight) continue; // to close to the object

or if you have Ripper's 3d Directional Sprites Tutorial added, it goes after the line:

if(statptr->flags & (FL_DIRSOUTH | FL_DIREAST))
visptr->transsprite=statptr;
else
visptr->transsprite=NULL;


Using it now is really simple... When you add a sprite to the game and want it animated you change in wl_act1.c file like this:

// To make a sprite animated enable the define in the version.h file and
// then add this third option to the sprites that you have defined like this:
// {Spritename,Spritetype,MAKEANIM(speed,frames)},
// Spritename = Name of Sprite you added into SPRITES.H file
// Spritetype = type be it block, nothing, bo_whatever bonus
// speed is the rate to change frames from 0 to 15 (Maximum 15) Lower Number = Faster Speed
// and frames is the number of pictures for the animation (Maximum 15).

So lets say you wanted the very first static sprite (the puddle) to be animated... all you do is change the original define of:
{SPR_STAT_0}

to

{SPR_STAT_0,dressing,MAKEANIM(15,2)}

That's about it....

Greg
BrotherTank

Edit PS: dressing is basically "0" or zero... That is the value that is given to sprites when there is no second value in the original defines. And for what it is worth, this routine gives a fantastic animation. Especially with things like a torch... Smile

BT Tank
WSJ
DieHard Officer
DieHard Officer


Joined: 17 Apr 2004
Last Visit: 08 May 2017

Topics: 24
Posts: 521

blank.gif

PostPosted: Tue May 15, 2007 5:36 am
   Subject: [Code] Creating Animated Static Objects Tutorial
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Don't mean to resurrect old threads, but I just wanted to remind people of the "newer" version I wrote, which doesn't require the object flag, and makes it much easier to animate bonus items: http://diehardwolfers.areyep.com/viewtopic.php?t=2709
Codetech84
Code Master
Code Master


Joined: 12 Mar 2003
Last Visit: 15 Oct 2017

Topics: 22
Posts: 1281
Location: Rauma - Finland
finland.gif

PostPosted: Wed Aug 01, 2007 5:06 am
   Subject: Re: [Code] Creating Animated Static Objects Tutorial
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

::: CODE :::

    gamestate.timer_anim+=tics;
    gamestate.timer_anim%=140;

::: CODE :::

case SPR_PISTOLREADY:
    return ((gamestate.timer_anim/35)%4);


Looks like a division by zero error, waiting to happen. This could happen everytime the %140 returns 0, which is basically every two seconds.

You could fix it by returning a zero offset when timer has just been reset:

::: CODE :::

// ANIMATED SPRITES
int GiveAnimationOffset(int shapenum)
{
     if (gamestate.timer_anim <= 0) // <= 0 for failsafe
       return 0;


    // returns an offset to the base shapenum based on time
    switch (shapenum)
    {
       case SPR_ANIM_0: // or whatever
            return ((gamestate.timer_anim/70)%2); // 2 frames/70 tics per frame (1 second)
        default:
            return 0;
    }
}

_________________
Click here to visit KFH Games website!
*UPDATED* Spear of Destiny Reloaded
KFH Games on Facebook
MCS
Site Administrator
<B>Site Administrator</B>


Joined: 01 Mar 2003
Last Visit: 15 Jul 2013

Topics: 20
Posts: 243
Location: Amsterdam, the Netherlands
netherlands.gif

PostPosted: Wed Aug 01, 2007 11:59 am
   Subject: Re: [Code] Creating Animated Static Objects Tutorial
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Me no see a division by zero, just a division by 35?

_________________
-= Fortune awaits those who search =-
Codetech84
Code Master
Code Master


Joined: 12 Mar 2003
Last Visit: 15 Oct 2017

Topics: 22
Posts: 1281
Location: Rauma - Finland
finland.gif

PostPosted: Wed Aug 01, 2007 12:06 pm
   Subject: Re: [Code] Creating Animated Static Objects Tutorial
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

MCS wrote:
Me no see a division by zero, just a division by 35?


Embarassed Oops...

_________________
Click here to visit KFH Games website!
*UPDATED* Spear of Destiny Reloaded
KFH Games on Facebook
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 2381 Fri Feb 11, 2005 9:18 pm
Zombie_Plan View latest post
No new posts [Code] Changing an Enemies Attack Strength - BrotherTank
Author: BrotherTank
0 1969 Tue Jan 27, 2004 10:29 am
BrotherTank View latest post
No new posts [Info] Giving a Guard a Rocket Launcher
Author: Guest
4 193 Fri Jan 23, 2004 1:58 pm
Guest View latest post
No new posts [Code] Changing Weapons -CheckWeaponChange- BrotherTank
Author: BrotherTank
2 2700 Sun Oct 26, 2003 1:21 am
Guest View latest post
No new posts [Help] Different Enemy Dying Frames/Views
Author: Guest
7 607 Tue Jul 29, 2003 3:00 pm
Codetech84 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