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       

[Tutorial] Creating HUD-based Actors
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
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 5:37 ago.

Topics: 163
Posts: 8152
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Sun May 08, 2011 6:28 pm
   Subject: [Tutorial] Creating HUD-based Actors
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

So what is a HUD-based Actor? Well, it's an Actor that's displayed - not on the map - but drawn on the screen like the Deathcam sprite, Demo sprite, and the player's weapons. With this feature, you can simulate blood being splattered on the monitor when you're hurt by an enemy, or you might want to spawn a graphical, animated message when you begin the level.

In this example, the HUD-based Actor is spawned in the start of the level.

First, open WL_DEF.H, and do a seach for "chainready". You should see this code:
::: CODE :::
    SPR_CHAINREADY,SPR_CHAINATK1,SPR_CHAINATK2,SPR_CHAINATK3,
    SPR_CHAINATK4,

Insert this just below it:
::: CODE :::
    SPR_HUD_ANIM1,SPR_HUD_ANIM2,SPR_HUD_ANIM3,SPR_HUD_ANIM4,SPR_HUD_ANIM5,
    SPR_HUD_ANIM6,SPR_HUD_ANIM7,
That's the frames for the HUD-based actor.

Next, add the new Actor type in WL_DEF.H. Do a search for "rocketobj". You should see this:
::: CODE :::
    giftobj,
    fatobj,
    rocketobj,

Insert this line of code just below it:
::: CODE :::
    hudactorobj,
You've just added a new Actor type called "hudactorobj".

Now do a search for "grddie1". You should see this code:
::: CODE :::
extern  statetype s_grddie1;
extern  statetype s_dogdie1;
extern  statetype s_ofcdie1;

Insert this line of code just above it:
::: CODE :::
extern  statetype s_hudanim1;
This tells the code to "remember" the HUD Actor's first statetype in all the files of source code.

Now do a search for "spawndeadguard". You should see this:
::: CODE :::
void SpawnDeadGuard (int tilex, int tiley);

Insert this line of code above it:
::: CODE :::
void SpawnHUDActor (statetype *state);
This lets you spawn the HUD Actor from WL_GAME.CPP.

That's it for WL_DEF.H. Now go into WL_ACT2.CPP. Do a search for "A_DeathScream". You should see this:
::: CODE :::
void A_DeathScream (objtype *ob);

Insert this code below it:
::: CODE :::
extern  statetype s_hudanim1;
extern  statetype s_hudanim2;
extern  statetype s_hudanim3;
extern  statetype s_hudanim4;
extern  statetype s_hudanim5;
extern  statetype s_hudanim6;
extern  statetype s_hudanim7;

statetype s_hudanim1             = {false,SPR_HUD_ANIM1,6,NULL,NULL,&s_hudanim2};
statetype s_hudanim2             = {false,SPR_HUD_ANIM2,6,NULL,NULL,&s_hudanim3};
statetype s_hudanim3             = {false,SPR_HUD_ANIM3,6,NULL,NULL,&s_hudanim4};
statetype s_hudanim4             = {false,SPR_HUD_ANIM4,6,NULL,NULL,&s_hudanim5};
statetype s_hudanim5             = {false,SPR_HUD_ANIM5,6,NULL,NULL,&s_hudanim6};
statetype s_hudanim6             = {false,SPR_HUD_ANIM6,6,NULL,NULL,&s_hudanim7};
statetype s_hudanim7             = {false,SPR_HUD_ANIM7,6,NULL,NULL,NULL};
This gives statetetypes to the new HUD Actor.

Now do a search for "SpawnDeadGuard". You should see this:
::: CODE :::
/*
===============
=
= SpawnDeadGuard
=
===============

Insert this code above it:
::: CODE :::
/*
===============
=
= SpawnHUDActor
=
===============
*/

void SpawnHUDActor (statetype *state)
{
    SpawnNewObj (0,0,state,false);
    newobj->flags = FL_NEVERMARK;
    newobj->obclass = hudactorobj;
    newobj->active = ac_yes;

}
This is the code that "spawns" the HUD Actor. The Actor is spawned on square (0,0) of the map, where it can't be seen.

Note the line of code with the parameter "ac_yes". This tells the code to keep updating the Actor's statetype whether or not he's on the same floorcode as you. This "HUD Actor" shouldn't be visible to the player as long as the HUD Actor is spawned in square (0,0) of the map, as I've already done here.

That should do it for WL_ACT2.CPP. Now for WL_GAME.CPP. Here's where my code gets sloppy (and not for the first time, either). Search for "SpawnPlayer". You should see this:
::: CODE :::
                    SpawnPlayer(x,y,NORTH+tile-19);

Insert this line of code just below it:
::: CODE :::
                    SpawnHUDActor(&s_hudanim00);

That's it for WL_GAME.CPP. Now let's go into WL_DRAW.CPP. Do a search for the misspelled word "!numvisable". You should see this:
::: CODE :::
    if (!numvisable)
        return;                                                                 // no visable objects

Just delete these lines. This is my way of telling the code: "I don't care whether there's any sprites visible on the map. Go through the drawing routine anyway!" Smile

Now do a search for "= DrawPlayerWeapon". You should see this:
::: CODE :::
//==========================================================================

/*
==============
=
= DrawPlayerWeapon

Insert this just above it:
::: CODE :::
    for (obj = player->next;obj;obj=obj->next)
    {
    if (obj->obclass == hudactorobj)
        {
            SimpleScaleShape(viewwidth/2,obj->state->shapenum,viewheight+1);
        }
    }

This tells the code to draw the HUD-based Actors in the same manner as the weapon sprites, Demo sprite, and Deathcam sprite.

Finally, go into WL_PLAY.CPP. Do a search for "DoActor". You should see this:
::: CODE :::
void DoActor (objtype * ob)
{
    void (*think) (objtype *);

    if (!ob->active && !areabyplayer[ob->areanumber])
        return;

Change it to this:
::: CODE :::
void DoActor (objtype * ob)
{
    void (*think) (objtype *);

#ifdef USEHUDACTORS
    if (!ob->active && !areabyplayer[ob->areanumber]
       && ob->obclass != hudactorobj)
#else
    if (!ob->active && !areabyplayer[ob->areanumber])
#endif
        return;
This tells the code to keep working with the HUD Actor whether or not the player is in the same room, and even if the door of that room closes.

Now just slap seven sprites right after the chaingun animations in the VSWAP, and I think you're good to go. Thumbs Up

I've probably made some silly mistakes in this tutorial somewhere, so please feel free to post corrections. Thanks. Smile

Edit: Fixed a bug where the animation "froze" if the player walked outside the floorcode he started from. Also, the code is more compact, less stupid, and is overall easier and more practical to work with.

Edit 2: Another bug is fixed where the animation would freeze if you entered a room and closed the door behind you.


Last edited by Tricob on Sun Jul 03, 2016 2:03 pm; edited 3 times in total
RichterBelmont12
DieHard Wolfer
DieHard Wolfer


Joined: 14 Aug 2004
Last Visit: 21:19 ago.

Topics: 97
Posts: 1508
Location: New Jersey
usa.gif

PostPosted: Sun May 08, 2011 7:37 pm
   Subject: Re: [Tutorial] Creating HUD-based Actors
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Soo seeing this..I can have Blood Appear when you get hit (like in Doom)?

I'm a little confused at this.

_________________
http://www.youtube.com/RichterBelmont12

https://www.facebook.com/RichterBelmont123

https://twitter.com/Richterbelmont6
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 5:37 ago.

Topics: 163
Posts: 8152
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Sun May 08, 2011 10:20 pm
   Subject: Re: [Tutorial] Creating HUD-based Actors
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Richter Belmont wrote:
Soo seeing this..I can have Blood Appear when you get hit (like in Doom)?
I don't recall Doom having such a feature; the enemies bled when you shot them, but no blood appeared when you were hit.

The HUD Actors feature is more modern, like the "blood splattered on the screen" effect you see in Black Ops.
RichterBelmont12
DieHard Wolfer
DieHard Wolfer


Joined: 14 Aug 2004
Last Visit: 21:19 ago.

Topics: 97
Posts: 1508
Location: New Jersey
usa.gif

PostPosted: Mon May 09, 2011 5:44 am
   Subject: Re: [Tutorial] Creating HUD-based Actors
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

hmmm interresting

_________________
http://www.youtube.com/RichterBelmont12

https://www.facebook.com/RichterBelmont123

https://twitter.com/Richterbelmont6
RichterBelmont12
DieHard Wolfer
DieHard Wolfer


Joined: 14 Aug 2004
Last Visit: 21:19 ago.

Topics: 97
Posts: 1508
Location: New Jersey
usa.gif

PostPosted: Mon May 09, 2011 6:12 am
   Subject: Re: [Tutorial] Creating HUD-based Actors
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

ok I'm trying to do when the player gets hit the Blood will Appear...Just like in DeathTRigger

Soo i've added the

::: CODE :::
SpawnHUDActor(x,y);


in the TakeDamage Routine

But it get this

772 C:\Wolf4SDL-1.6-src\wl_agent.cpp `x' was not declared in this scope
772 C:\Wolf4SDL-1.6-src\wl_agent.cpp `y' was not declared in this scope

_________________
http://www.youtube.com/RichterBelmont12

https://www.facebook.com/RichterBelmont123

https://twitter.com/Richterbelmont6
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 5:37 ago.

Topics: 163
Posts: 8152
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Mon May 09, 2011 5:08 pm
   Subject: Re: [Tutorial] Creating HUD-based Actors
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Try using "player->x" instead of "x", and the same change for "y".

I haven't tried using this routine outside of WL_ACT2.CPP yet, so you may need to spoon-feed WL_AGENT.CPP some extra data, like the statetypes for the blood splatter. If you do copy the statetype data to WL_AGENT though, I think you'll have to comment out the same statetype stuff in WL_ACT2.CPP,
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 5:37 ago.

Topics: 163
Posts: 8152
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Sun Mar 24, 2013 2:01 pm
   Subject: Re: [Tutorial] Creating HUD-based Actors
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

(sighs) Really?! It looks I accidentally unveiled a bug in this routine ... nearly two years after posting it. It turns out that if you exit the room you start in, close the door, and you're in a different "floorcode" then where you started out, the "HUD Actor" will be "frozen" until that door is opened up again. I haven't sought out a solution to the problem yet, as my complier isn't working right. But I do intend to fix this bug in the future.

Just thought you folks should know about the bug! Smile
gerolf
DieHard Wolfer
DieHard Wolfer


Joined: 28 Jan 2010
Last Visit: 20 Jun 2018

Topics: 162
Posts: 1083
Location: Alabama
usa.gif

PostPosted: Thu Mar 28, 2013 7:32 pm
   Subject: Re: [Tutorial] Creating HUD-based Actors
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

HEY! So, this could be used to create an effect similar to that strange ghost face that randomly appeared on screen to scare the player in Witchaven?

_________________
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 5:37 ago.

Topics: 163
Posts: 8152
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Fri Mar 29, 2013 8:54 am
   Subject: Re: [Tutorial] Creating HUD-based Actors
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

gerolf wrote:
HEY! So, this could be used to create an effect similar to that strange ghost face that randomly appeared on screen to scare the player in Witchaven?
I'm not familiar with Witchaven. Do you have a video link where this "ghost face" sequence happens? Thanks. Smile
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 5:37 ago.

Topics: 163
Posts: 8152
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Sun Jun 30, 2013 5:37 am
   Subject: Re: [Tutorial] Creating HUD-based Actors
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

The floorcode-related bug is now fixed. Check the first post to see the new code. This newer version is smaller and easier to work with.
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 5:37 ago.

Topics: 163
Posts: 8152
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Sun Jul 03, 2016 2:06 pm
   Subject: Re: [Tutorial] Creating HUD-based Actors
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

At long last, I've finally fixed all the bugs in this code! The newest patch is found in the first post of this topic. Sorry it took so long to get this fixed! 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 14640 Tue Aug 24, 2010 10:18 am
dcbasic View latest post
No new posts Sticky: [Tutorial] Compiling Wolf4SDL with Code::Blocks
Author: dcbasic
90 22956 Wed May 24, 2017 7:53 pm
Falcon*93 View latest post
No new posts [HELP] Weird Bug
Author: Raziel
6 1457 Sun Jul 20, 2008 7:22 am
Raziel View latest post
No new posts Problem with new Wolf4SDL Demo Releases
Author: BrotherTank
4 1688 Sun Jul 20, 2008 3:57 am
Ripper View latest post
No new posts [HELP WOLF4SDL] High-Res Weapons.
Author: Raziel
9 1877 Sun Jul 13, 2008 5:04 pm
Ripper 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