Countdown timer D3D - problem

Hi guys,its my first time posting here and i found a lot of useful info here so far so i decided to join.

I am using D3D for my school project. I used two mesh files to represent space and a space ship that i can move around.

Problem: I created a count down timer for the fuel level so as the program loads it displays 100L and drops down every 3 seconds. When i run the program, different characters start appearing each second at the end of the line...

ex:

Fuel level: 100L # and then that changes to "...$...%...1...2...3...and so on and then eventually it just stops....


Thanks in advance!


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
int seconds;
int fuel=100;

time_t rawtime;
	struct tm * timeinfo;
	time ( &rawtime );
	timeinfo = localtime ( &rawtime );

//Fuel Level

		if(seconds == 0){
		seconds = timeinfo->tm_sec;
		}
			else{
			int tm_now = timeinfo->tm_sec;

		if(tm_now - seconds >= 2){
			if(fuel > 0){
				fuel--;
		   		seconds = timeinfo->tm_sec;
			}
		}
		}

	char str1[100];
	ostrstream sout(str1,100);
        sout<<"Earth time:"<<"   "<<asctime (timeinfo)<<endl;
	sout<<"Fuel level = "<<fuel<<endl;
// text_xy places 2D text at pixel location (x,y)
	text_xy(str1,15,15); 

//Taken from Professor 
void text_xy(char *str, double x, double y, int size)
// place 2D text at pixel location (x,y)
// str - text string
// x - x pixel location of text
// y - y pixel location of text
// size = font size of the text
{
    static TCHAR m_strFont[100];
    static DWORD m_dwFontSize = -77; // current font size

	// check to see if font size is changed from last call
	// this part was added to avoid a memory leak with m_pFont
	// and to improve efficiency when font size is not changed
	if( size != (int)m_dwFontSize ) {
		SAFE_DELETE( m_pFont ); // delete previous font
	    // Create a new font
		lstrcpy( m_strFont, _T("Arial") );
		m_dwFontSize = size;
		m_pFont = new CD3DFont( m_strFont, m_dwFontSize );
		m_pFont->InitDeviceObjects( g_pd3dDevice );
		m_pFont->RestoreDeviceObjects();		
	}
	

	// Draw 2D text
	m_pFont->DrawText( (float)x, (float)y, 0xffffffff, _T(str) );
}



Last edited on
Topic archived. No new replies allowed.