
|
|
Author |
Message |
Barry
DieHard Officer


Joined: 27 Aug 2008
Last Visit: 14 Dec 2018
Topics: 64
Posts: 566

|
|
 |
AlumiuN
DieHard Wolfer

Joined: 29 Nov 2007
Last Visit: 5:17 ago.
Topics: 38
Posts: 2537
Location: Christchurch, New Zealand

|
Posted: Wed Dec 28, 2016 2:24 pm
Subject: Re: Adding countdown timer to screen in one level
[ IP : Logged ]
|

  
|
|
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


Joined: 27 Aug 2008
Last Visit: 14 Dec 2018
Topics: 64
Posts: 566

|
|
 |
AlumiuN
DieHard Wolfer

Joined: 29 Nov 2007
Last Visit: 5:17 ago.
Topics: 38
Posts: 2537
Location: Christchurch, New Zealand

|
Posted: Wed Dec 28, 2016 8:51 pm
Subject: Re: Adding countdown timer to screen in one level
[ IP : Logged ]
|

  
|
|
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


Joined: 27 Aug 2008
Last Visit: 14 Dec 2018
Topics: 64
Posts: 566

|
Posted: Thu Dec 29, 2016 11:34 am
Subject: Re: Adding countdown timer to screen in one level
[ IP : Logged ]
|

  
|
|
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: https://www.moddb.com/mods/atomprojekt
Passage to Hollenteufel Download: https://www.moddb.com/mods/passage-to-hollenteufel
|
|
 |
AlumiuN
DieHard Wolfer

Joined: 29 Nov 2007
Last Visit: 5:17 ago.
Topics: 38
Posts: 2537
Location: Christchurch, New Zealand

|
|
 |
Barry
DieHard Officer


Joined: 27 Aug 2008
Last Visit: 14 Dec 2018
Topics: 64
Posts: 566

|
Posted: Fri Dec 30, 2016 7:24 am
Subject: Re: Adding countdown timer to screen in one level
[ IP : Logged ]
|

  
|
|
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: https://www.moddb.com/mods/atomprojekt
Passage to Hollenteufel Download: https://www.moddb.com/mods/passage-to-hollenteufel
Last edited by Barry on Fri Dec 30, 2016 8:09 am; edited 1 time in total
|
|
 |
Barry
DieHard Officer


Joined: 27 Aug 2008
Last Visit: 14 Dec 2018
Topics: 64
Posts: 566

|
Posted: Fri Dec 30, 2016 8:08 am
Subject: Adding countdown timer to screen in one level
[ IP : Logged ]
|

  
|
|
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: https://www.moddb.com/mods/atomprojekt
Passage to Hollenteufel Download: https://www.moddb.com/mods/passage-to-hollenteufel
|
|
 |
AlumiuN
DieHard Wolfer

Joined: 29 Nov 2007
Last Visit: 5:17 ago.
Topics: 38
Posts: 2537
Location: Christchurch, New Zealand

|
|
 |
|
|
|
|
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
|