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 countdown timer to screen in one level
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
Barry
DieHard Officer
DieHard Officer


Joined: 27 Aug 2008
Last Visit: 28 Oct 2017

Topics: 64
Posts: 565

blank.gif

PostPosted: Wed Dec 28, 2016 1:40 pm
   Subject: Adding countdown timer to screen in one level
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

I am going to use the below tutorial to make one of my levels a timed level.

http://diehardwolfers.areyep.com/viewtopic.php?t=2989&start=0&postdays=0&postorder=asc&highlight=

However, I want to add a clock that will count down so the player knows how much time they have left. Has anybody done this and if so, how do you do it?

_________________
Atomprojekt Download: http://www.wolfenvault.com/files/barry/ATOM.3.zip
Passage to Hollenteufel Download: http://www.wolfenvault.com/files/barry/PTH.2.zip
AlumiuN
DieHard Wolfer
DieHard Wolfer


Joined: 29 Nov 2007
Last Visit: 0:36 ago.

Topics: 37
Posts: 2401
Location: Christchurch, New Zealand
newzealand.gif

PostPosted: Wed Dec 28, 2016 2:24 pm
   Subject: Re: Adding countdown timer to screen in one level
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Well, first you'll need to define a limit somewhere that both the code to measure the time and the code to display the time can see; I'd recommend using a gamestate variable. After that, it depends on how you want to display it, but you could simply draw it as text. If you want to do that, here's something that should work reasonably and will provide a shadow under it to make it more readable too.

::: CODE :::
int timeLeft = gamestate.TimeCount - gamestate.timelimit;
int min = timeLeft / 60;
int sec = timeLeft % 60;

snprintf(buf, 99, "%d:%d", min, sec);
USL_MeasureString(buf, &w, &h);
PrintX = 310 - w;
PrintY = 190 - STATUSLINES - h - 3;
fontcolor = TIMESHADOWCOL;
US_Print(buf);
PrintX = 311 - w;
PrintY += 1;
fontcolor = TIMETEXTCOL;
US_Print(buf);


Then replace TIMESHADOWCOL and TIMETEXTCOL with the colours you want. You can modify the PrintX and PrintY values to have it print where you want, for optimal results the first set should be one pixel up and to the left than the second (as the shadow is drawn first). Note that this may interfere with the screen border if present, so it might need refreshing.
Barry
DieHard Officer
DieHard Officer


Joined: 27 Aug 2008
Last Visit: 28 Oct 2017

Topics: 64
Posts: 565

blank.gif

PostPosted: Wed Dec 28, 2016 2:29 pm
   Subject: Re: Adding countdown timer to screen in one level
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Thanks!

Do I add this in WL_PLAY.CPP within the IF statement that initiates the timer on the floor I want (in my case 33)? Also, do I declare gamestate.timelimit as short?

Also, I am guessing I would hard-code the value for gamestate.timelimit in wl_game.cpp in the code that handles when happens when you start a new level or die. Something like..

::: CODE :::

if (gamestate.mapon == 32)
      gamestate.timelimit = 360*70  //Six minute time limit


I also want the timer to stop if gamestate.reactor == 6. For the in-game timer, that should be pretty easy (add an if prior to the playstate = ex_died call so that it doesn't happen if gamestate.reactor == 6).

How would I stop the on-screen timer though? If it's easier just to put the code above into an if statement so the timer disappears from the screen when gamestate.reactor == 6, I am okay with that.

_________________
Atomprojekt Download: http://www.wolfenvault.com/files/barry/ATOM.3.zip
Passage to Hollenteufel Download: http://www.wolfenvault.com/files/barry/PTH.2.zip
AlumiuN
DieHard Wolfer
DieHard Wolfer


Joined: 29 Nov 2007
Last Visit: 0:36 ago.

Topics: 37
Posts: 2401
Location: Christchurch, New Zealand
newzealand.gif

PostPosted: Wed Dec 28, 2016 8:51 pm
   Subject: Re: Adding countdown timer to screen in one level
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

gamestate.timelimit should probably be the same type as TimeCount, which is an int IIRC. Hard-coding the time limit is probably fine. Otherwise, I'd just have timelimit be set to -1 and have it not draw to the screen when it is -1.

As for the code I posted, put it anywhere that's called any frame before the screen update in ThreeDRefresh. I'd put it in a function in WL_DRAW and then call it after drawing everything else in ThreeDRefresh.
Barry
DieHard Officer
DieHard Officer


Joined: 27 Aug 2008
Last Visit: 28 Oct 2017

Topics: 64
Posts: 565

blank.gif

PostPosted: Thu Dec 29, 2016 11:34 am
   Subject: Re: Adding countdown timer to screen in one level
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

AlumiuN wrote:
gamestate.timelimit should probably be the same type as TimeCount, which is an int IIRC. Hard-coding the time limit is probably fine. Otherwise, I'd just have timelimit be set to -1 and have it not draw to the screen when it is -1.

As for the code I posted, put it anywhere that's called any frame before the screen update in ThreeDRefresh. I'd put it in a function in WL_DRAW and then call it after drawing everything else in ThreeDRefresh.


Thanks.

I am attempting to implement this. I have added this to the end of WL_DRAW.cpp

::: CODE :::
/*
========================
=
= DisplayTimer
=
========================
*/

void DisplayTimer (void)
{
    int timeLeft = gamestate.TimeCount - gamestate.timelimit;
    int min = timeLeft / 60;
    int sec = timeLeft % 60;

    snprintf(buf, 99, "%d:%d", min, sec);
    USL_MeasureString(buf, &w, &h);
    PrintX = 310 - w;
    PrintY = 190 - STATUSLINES - h - 3;
    fontcolor = 1e;
    US_Print(buf);
    PrintX = 311 - w;
    PrintY += 1;
    fontcolor = 11;
    US_Print(buf);
}


The code won't compile though because "buf", "w", and "h" have not been declared. Do I need to declare these variables somewhere else?

Also, I have added the call to DisplayTimer at the very end of ThreeDRefresh (here is my entire ThreeDRefresh)

::: CODE :::

/*
========================
=
= ThreeDRefresh
=
========================
*/

void    ThreeDRefresh (void)
{
//
// clear out the traced array
//
    memset(spotvis,0,maparea);
    spotvis[player->tilex][player->tiley] = 1;       // Detect all sprites over player fix

    vbuf = VL_LockSurface(screenBuffer);
    if(vbuf == NULL) return;

    vbuf += screenofs;
    vbufPitch = bufferPitch;

    CalcViewVariables();

//
// follow the walls from there to the right, drawing as we go
//
    VGAClearScreen ();
#if defined(USE_FEATUREFLAGS) && defined(USE_STARSKY)
    if(GetFeatureFlags() & FF_STARSKY)
        DrawStarSky(vbuf, vbufPitch);
#endif

    WallRefresh ();

#if defined(USE_FEATUREFLAGS) && defined(USE_PARALLAX)
    if(GetFeatureFlags() & FF_PARALLAXSKY)
        DrawParallax(vbuf, vbufPitch);
#endif
#if defined(USE_FEATUREFLAGS) && defined(USE_CLOUDSKY)
    if(GetFeatureFlags() & FF_CLOUDSKY)
        DrawClouds(vbuf, vbufPitch, min_wallheight);
#endif
#ifdef USE_FLOORCEILINGTEX
    DrawFloorAndCeiling(vbuf, vbufPitch, min_wallheight);
#endif

//
// draw all the scaled images
//
    DrawScaleds();                  // draw scaled stuff

#if defined(USE_FEATUREFLAGS) && defined(USE_RAIN)
    if(GetFeatureFlags() & FF_RAIN)
        DrawRain(vbuf, vbufPitch);
#endif
#if defined(USE_FEATUREFLAGS) && defined(USE_SNOW)
    if(GetFeatureFlags() & FF_SNOW)
        DrawSnow(vbuf, vbufPitch);
#endif

    DrawPlayerWeapon ();    // draw player's hands

    if(Keyboard[sc_Tab] && viewsize == 21 && gamestate.weapon != -1)
        ShowActStatus();

    VL_UnlockSurface(screenBuffer);
    vbuf = NULL;

//
// show screen and time last cycle
//

    if (fizzlein)
    {
        FizzleFade(screenBuffer, 0, 0, screenWidth, screenHeight, 20, false);
        fizzlein = false;

        lasttimecount = GetTimeCount();          // don't make a big tic count
    }
    else
    {
#ifndef REMDEBUG
        if (fpscounter)
        {
            fontnumber = 0;
            SETFONTCOLOR(7,127);
            PrintX=4; PrintY=1;
            VWB_Bar(0,0,50,10,bordercol);
            US_PrintSigned(fps);
            US_Print(" fps");
        }
#endif
        SDL_BlitSurface(screenBuffer, NULL, screen, NULL);
        SDL_Flip(screen);
    }

//frameon++;

#ifndef REMDEBUG
    if (fpscounter)
    {
        fps_frames++;
        fps_time+=tics;

        if(fps_time>35)
        {
            fps_time-=35;
            fps=fps_frames<<1;
            fps_frames=0;
        }
    }

    if (gamestate.mapon == 32 && gamestate.reactor != 6)
    {
        DisplayTimer();
    }

#endif
}


Should this accomplish what I am trying to do?

_________________
Atomprojekt Download: http://www.wolfenvault.com/files/barry/ATOM.3.zip
Passage to Hollenteufel Download: http://www.wolfenvault.com/files/barry/PTH.2.zip
AlumiuN
DieHard Wolfer
DieHard Wolfer


Joined: 29 Nov 2007
Last Visit: 0:36 ago.

Topics: 37
Posts: 2401
Location: Christchurch, New Zealand
newzealand.gif

PostPosted: Thu Dec 29, 2016 1:29 pm
   Subject: Re: Adding countdown timer to screen in one level
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

For the buf, w, and h, I forgot to add those definitions, so stick this at the very start of DisplayTimer:

::: CODE :::
    char buf[100];
    uint16_t w, h;
    fontnumber = 0;


You can change fontnumber to 1 if you want to use the larger font.

As for where it is called, place that segment above the line "VL_UnlockSurface(screenBuffer);".
Barry
DieHard Officer
DieHard Officer


Joined: 27 Aug 2008
Last Visit: 28 Oct 2017

Topics: 64
Posts: 565

blank.gif

PostPosted: Fri Dec 30, 2016 7:24 am
   Subject: Re: Adding countdown timer to screen in one level
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Thanks!

I am very close to having this working. However, I have one more issue and one more question.

EDIT: Figured out the first issue.

Secondly, where would be the best place to hard code my value for gamestate.timelimit? The compiler doesn't like it when I do it wl.def.h in the global variables section. If works if I do it in my "if" statement in ThreeDRefresh but that is probably not the most efficient way to do it because it refreshes the value every frame.

_________________
Atomprojekt Download: http://www.wolfenvault.com/files/barry/ATOM.3.zip
Passage to Hollenteufel Download: http://www.wolfenvault.com/files/barry/PTH.2.zip


Last edited by Barry on Fri Dec 30, 2016 8:09 am; edited 1 time in total
Barry
DieHard Officer
DieHard Officer


Joined: 27 Aug 2008
Last Visit: 28 Oct 2017

Topics: 64
Posts: 565

blank.gif

PostPosted: Fri Dec 30, 2016 8:08 am
   Subject: Adding countdown timer to screen in one level
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Alright, so I figured out how to get the clock to work correctly. I changed the code to this and it now displays correctly.

Am I okay to assign the value to gamestate.timelimit in ThreeDRefresh or should I assign it elsewhere?

::: CODE :::

/*
========================
=
= DisplayTimer
=
========================
*/

void DisplayTimer (void)
{
    char buf[100];
    uint16_t w, h;
    fontnumber = 0;
    int sec, min;
    int timeLeft = (gamestate.TimeCount - gamestate.timelimit)/70;
    min = timeLeft / 60;
    sec = timeLeft % 60;

    snprintf(buf, 99, "%d:%02d",  abs(min), abs(sec));
    USL_MeasureString(buf, &w, &h);
    PrintX = 310 - w;
    PrintY = 190 - STATUSLINES - h - 3;
    fontcolor = 0x1e;
    US_Print(buf);
    PrintX = 311 - w;
    PrintY += 1;
    fontcolor = 0x39;
    US_Print(buf);
}

_________________
Atomprojekt Download: http://www.wolfenvault.com/files/barry/ATOM.3.zip
Passage to Hollenteufel Download: http://www.wolfenvault.com/files/barry/PTH.2.zip
AlumiuN
DieHard Wolfer
DieHard Wolfer


Joined: 29 Nov 2007
Last Visit: 0:36 ago.

Topics: 37
Posts: 2401
Location: Christchurch, New Zealand
newzealand.gif

PostPosted: Fri Dec 30, 2016 12:24 pm
   Subject: Re: Adding countdown timer to screen in one level
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

Honestly, I'd put a check in SetupGameLevel, something like:

::: CODE :::
if (gamestate.mapon == 32)
    gamestate.timelimit = SECONDS_TO_LIMIT * 70;


Where SECONDS_TO_LIMIT is the number of seconds long the limit is.
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 Sticky: [Tutorial] Compiling Wolf4SDL with Code::Blocks
Author: dcbasic
90 17489 Wed May 24, 2017 7:53 pm
Falcon*93 View latest post
No new posts [help] Adding teleporters in wolf4sdl
Author: Mortimer
35 7360 Fri May 26, 2017 8:19 am
Military View latest post
No new posts [Help] Disabling "Full Screen" Mode
Author: WSJ
4 1021 Sat Aug 02, 2008 6:42 pm
Tricob View latest post
No new posts [CODE] Health Shown as a message with full screen view
Author: Raziel
13 2097 Thu Jul 31, 2008 8:07 pm
Raziel View latest post
No new posts [Help] Adding a weapon problem
Author: Zombie_Plan
10 1441 Thu Jul 24, 2008 4:26 pm
RichterBelmont12 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