breakout lives

Started by
20 comments, last by phil67rpg 11 years ago
I am trying to print out the number of lives left to the screen,

void drawBitmapText(char *string,float x,float y,float z) 
{  
char *c;
glPushAttrib(GL_CURRENT_BIT);
glClear(GL_COLOR_BUFFER_BIT);
brick();
paddle();
ball();
glColor3f(1.0f,1.0f,1.0f);
glRasterPos3f(x, y, z);
for (c=string; *c != '\0'; c++) 
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *c);
}
glPopAttrib();
}

void lives()
{
	num--;
	strng=itoa(num,buffer_two,10);
	drawBitmapText(strng,0.0f,2.0f,0.0f);	
}

void Timer(int value)
{
	if(x > windowWidth) 
	{
	xstep = -xstep;
	}

	if( x < -windowWidth)
	{
	xstep=-xstep;
	}

	if(y > windowHeight)
	{
	ystep=-ystep;
	}

	if(y < -windowHeight)
	{
	x=0.0f;
	y=0.0f;
	lives();
	ball();
	}
Advertisement
It would help if we could know what the problem actually was
what
well I am trying to print to the screen the number of lives left in my game. I am using the lives() function to print out to the screen but I don't get anything. When the ball goes off the bottom of the screen I want the lives counter to decrement by one. Let me know if you need any more code or information.
I'm not particularly familiar with OpenGL, but here are some good questions to consider. Are you sure (0, 2, 0) is actually within the window? Is your window background white (you're printing white text)? Does the current raster position refer to the bottom left or top left of a character? Try outputting the text at (100, 100, 0) and see what happens.
what
my background is black and outputting the text as (100,100,0) does not work either.
try setting all your matrices to identity matrices right before you draw the text. You might be translating the text without your knowing.

EDIT: Also, it appears as if glColor and glRasterPos are not OpenGL 4 compliant. They may have been deprecated because I can't seem to find them here.

EDIT2: Lighting and texturing may also effect the color of your text because it seems when lighting is on, a lighting equation is used to compute a new primary color for the rasterized pixel.
what
I am using glut 3.7.6 which works with glColor and glRasterPos. Actually this piece of code works.

void brick_collision()
{
	GLint n=0;
	
	if(bricks[2][4]==true)
	{
	n+=100;
	str=itoa(n,buffer,10);
	drawBitmapText(str,4.0f,2.0f,0.0f);
	}

	if(bricks[2][3]==true)
	{
	n+=100;
	str=itoa(n,buffer,10);
	drawBitmapText(str,4.0f,2.0f,0.0f);	
	}

	if(bricks[2][2]==true)
	{
	n+=100;
	str=itoa(n,buffer,10);
	drawBitmapText(str,4.0f,2.0f,0.0f);	
	}

	if(bricks[2][1]==true)
	{
	n+=100;
	str=itoa(n,buffer,10);
	drawBitmapText(str,4.0f,2.0f,0.0f);	
	}

	if(bricks[2][0]==true)
	{
	n+=100;
	str=itoa(n,buffer,10);
	drawBitmapText(str,4.0f,2.0f,0.0f);	
	}

I am still stuck, my code looks right but for some reason it does not work properly. I just need a little hint.

Can you explain why you are calling:

brick();

paddle();

ball();

inside your drawBitmapText function.

Also can you explain what brick_collision() does?


Though my guess is that you are clearing the screen every frame, however you are only drawing the "num" for one frame when the "y" leaves the screen.

lives() is incorrect. Every time you call lives() to draw, num is decremented.

You clearly haven't bothered to read the many numerous posts that people have posted in your other threads to try to help you understand how to correctly construct a game loop.

Drawing code and collision code do not belong in the same method together.

Drawing code and state/data altering code (such as num--) do not belong in the same method together.

Drawing code does not belong in any kind of Timer method.

phil67rpg, before you post any more questions on this board, please go back through and read the many useful posts I can see in your posting history. You are still encountering the same problems, stemming from the same mistakes, that you have been for months without any evidence that you have even attempted to understand or even read the posted advice.

To reiterate:

At the heart of a game (any game, from breakout to Call of Duty) lies a loop. In this loop, many basic tasks are repeated over and over and over at a very high rate of speed. These tasks may vary somewhat in detail from game to game, but essentially are basically the same for each game. The basic tasks are:

Handle input from the user (and input from the network, if multiplayer)
Advance timers based on frame time or some other means of calculating time
Advance animations, update physics, move objects, update AI etc... based on elapsed time
Detect, handle, respond to and resolve collisions and other object interactions
Clear the screen
Draw the scene
Draw the UI elements
Swap buffers to present the view to the screen

The exact implementation details of this loop may vary. Some loops, for example, might fix physics/logic updates to a specific fixed rate. However, the basic gist of it is the same. Repeat that loop over and over and over until the game exits.

If you find yourself blurring the line between the basic tasks of the game loop, you are probably making an error. ie, if you are calling drawing code from a collision routine, or from a timer routine, then you are doing it wrong. This is where your errors and problems are coming from. You just don't have a clear idea of the core game loop, and until you do you are going to continue having problems.

This topic is closed to new replies.

Advertisement