2 registered members (AndrewAMD, Lapsa),
1,268
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Show minutes and seconds
[Re: Minamato]
#350767
12/19/10 00:06
12/19/10 00:06
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
You can have a var called "seconds" or something like this. Every frame you add the delta time of the frame (that is time_frame / 16). Once you need to display the minutes and seconds, its pretty simple math:
var passedMinutes = seconds / 60;
var passedSeconds = seconds % 60;
Edit: Just found "total_secs" in the manual. You can use this variable instead of counting your own variable up. However, if you want to be able to restart the game, you need to use your own variable so you can set it back any time.
Last edited by JustSid; 12/19/10 00:09.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Show minutes and seconds
[Re: Minamato]
#350966
12/20/10 17:26
12/20/10 17:26
|
Joined: Feb 2009
Posts: 80 STRING* location = "Germany";
Minamato
OP
Junior Member
|
OP
Junior Member
Joined: Feb 2009
Posts: 80
STRING* location = "Germany";
|
I think, I'm too stupid =D If I use "total_secs" in my own var and want to show it in a panel:
var seconds = total_secs;
PANEL* zeit_pan =
{
layer = 2;
pos_x = 50;
red = 0; green = 0; blue = 0;
digits = 0,0," %5.0f",fnt_score, 1, seconds;
flags = SHOW;
}
it doesn't work - but if I use "total_secs" directly in the panel, it works fine... and I also don't want to just show the seconds (because it isn't really nice to see that you have played 326 seconds since the game started), I want to show minutes : seconds. need some help here...=D
|
|
|
Re: Show minutes and seconds
[Re: Minamato]
#350984
12/20/10 18:59
12/20/10 18:59
|
Joined: Oct 2004
Posts: 900 Lgh
rojart
User
|
User
Joined: Oct 2004
Posts: 900
Lgh
|
Try my example:
#include <default.c>
#define PRAGMA_PATH "%EXE_DIR%\samples"
var seconds, minutes = -1;
FONT* A20b = "Arial#20b";
PANEL* pInfo;
function main()
{
fps_max = 60;
level_load ("small.hmp");
vec_set(camera.x, vector(0,0,150));
pInfo = pan_create(NULL,0);
pan_setdigits(pInfo,0,10,10,"SECONDS = %.0f", A20b, 1, seconds);
pan_setdigits(pInfo,0,10,30,"MINUTES = %.0f", A20b, 1, minutes);
set(pInfo, OUTLINE|SHOW);
while(level_ent)
{
if ((total_frames % 60) == 1) seconds++;
if ((total_frames % (60*60)) == 1) minutes++;
wait(1);
}
}
|
|
|
Re: Show minutes and seconds
[Re: Minamato]
#351002
12/20/10 22:56
12/20/10 22:56
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Rojart, thats evil because you assume that the user always has 60 frames per seconds. This is a much nicer approach:
var passedSeconds = 0;
// ...
while(level_ent)
{
passedSeconds += time_frame / 16;
minutes = passedSeconds / 60;
seconds = passedSeconds % 60;
wait(1);
}
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
|