File: game_timer.cpp

package info (click to toggle)
epiphany 0.7.0+0-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 7,532 kB
  • sloc: cpp: 6,404; ansic: 141; makefile: 78; sh: 7
file content (119 lines) | stat: -rw-r--r-- 2,112 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/***************************************************************************
                          game_time.cpp  -  description
                             -------------------
    begin                : Mon Aug 12 2002
    copyright            : (C) 2002 by Giuseppe D'Aqui'
    email                : kumber@tiscalinet.it
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License, Version 2, as published by  *
 *   the Free Software Foundation.                                   *
 *                                                                         *
 ***************************************************************************/

#include "dephine.h"
#include "SDL/SDL.h"
#include <cstdlib>
#include <cstdio>
#include "game_timer.h"



Game_Timer::Game_Timer(Uint32 total_time)
{
	
	m_total_time=total_time;
	m_last_time=0;
}




void Game_Timer::set_total_time(Uint32 total_time)
{
	m_total_time=total_time;
}




void Game_Timer::update()
{
	if(SDL_GetTicks()-m_last_time>1000)
	{
		m_last_time=SDL_GetTicks();
		m_total_time--;
	}
	
}




bool Game_Timer::is_zero()
{
	return(m_total_time==0);
}




void Game_Timer::start()
{
	m_last_time=SDL_GetTicks();
}



const char* Game_Timer::get_time_string()
{
	char*  time_string = new char[6];
	
	Sint32 minutes=m_total_time/60;
	
	Sint32 seconds=m_total_time%60;
	
	char minutes_string[3];
		
	if(minutes<10)
	{
		
		sprintf(minutes_string, "%d%d", 0,minutes);
		
	}
	else
	{
	
		sprintf(minutes_string, "%d", minutes);
	}
	
	char seconds_string[3];
	
	if(seconds<10)
	{
		
		sprintf(seconds_string, "%d%d", 0,seconds);
		
	}
	else
	{
	
		sprintf(seconds_string, "%d", seconds);
	}
	
	sprintf(time_string, "%s:%s", minutes_string,seconds_string);
		
	return time_string;
	
}

Uint32 Game_Timer::get_time()
{
	
	return m_total_time;
	
}