breakout game scoring

I am also working on a breakout game and am almost done except for the scoring. Here is the code I am working on.


	{
	glRasterPos2f(4.0f,2.0f);
	glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,c);
	glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,48);
	glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,48);
	}

	if(bricks[2][3]==true)
	{
	glRasterPos2f(4.0f,2.0f);
	glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,50);
	glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,48);
	glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,48);
	}

I want when the ball hits a brick to score 100 points.

Just tell it to add the score if the ball is within the hitbox of the brick.

if(ball.getHitBox() == brick.getHitBox()){
          brick.break();
          score.add(100)
}

Something like that

can you elaborate on the score.add(100) piece of code

Well you need a class to keep track of the players score, so it would probably be something like this

public class Score{
       
/**
* Holds the players score
*/
int score;

/**
* Get the players score
* @return score
*/
public int getScore(){
return score;
}

/**
* Used for reference 
*/
public Score(){
}

/**
* This is for if you want to keep track of the players score in between levels. Otherwise use Score() to construct
*/
public Score(int a){
this.score = a;
}

public void add(int b){
this.score += b;
}

}

thanks for the code, I have stubbed it out and I am learning how it works.

No problem, hope you can figure it out. PM if you need any more help or once its done post it on the forums or send it to me.

well I have adjusted poppit’s code. I am still confused about what the “this” keyword does. here is my code.


#include <iostream>

using namespace std;

class Score
{
int score;

public: 

int getScore()
{
return score;
}
 
Score()
{

}
 
Score(int a)
{
this->score = a;
}
 
void add(int b)
{
this->score += b;
}
 
};

int main()
{
	Score score;
	score.getScore();
	score.add(100);
	
	system("pause");
	return 0;
}

I’m sorry, I confused you. this is used for java, which I thought you were programming in. You can get rid of it.

actually I am using c++

is there anyway to erase a glutBitmapCharacter character?

I am trying to draw numbers to the screen, I want to erase the 1 in 100 to 2 in 200 for game scoring. Here is the code I am working on.


void drawBitmapText(char *string,float x,float y,float z) 
{  
char *c;
glRasterPos3f(x, y,z);
for (c=string; *c != '\0'; c++) 
{
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *c);
}
}

void brick_collision()
{
	if(bricks[2][4]==true)
	{
	drawBitmapText("100",4.0f,2.0f,0.0f);	
	}

	if(bricks[2][3]==true)
	{
	drawBitmapText("200",4.0f,2.0f,0.0f);	
	}


I am still stuck on how to print a blank character to the screen using glutBitmapCharacter command.

well I have almost solved my problem here is the code I am using.


	if(bricks[1][4]==true)
	{
	n+=200;
	str=itoa(n,buffer,10);
	glRasterPos3f(4.0f,2.0f,0.0f);
	glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 32);
	drawBitmapText(str,4.0f,2.0f,0.0f);	
	}

	if(bricks[1][3]==true)
	{
	n+=200;
	str=itoa(n,buffer,10);
	glRasterPos3f(4.0f,2.0f,0.0f);
	glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 32);
	drawBitmapText(str,4.0f,2.0f,0.0f);	
	}

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

	if(bricks[1][1]==true)
	{
	n+=200;
	str=itoa(n,buffer,10);
	glRasterPos3f(4.0f,2.0f,0.0f);
	glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 32);
	drawBitmapText(str,4.0f,2.0f,0.0f);	
	}

	if(bricks[1][0]==true)
	{
	n+=200;
	str=itoa(n,buffer,10);
	glRasterPos3f(4.0f,2.0f,0.0f);
	glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 32);
	drawBitmapText(str,4.0f,2.0f,0.0f);	
	}

I am so close I need only a little bit of help.

I want to erase the 1 in 100 to 2 in 200 for game scoring.

You don’t normally erase anything - since you are redrawing the frame each time click; when you draw the text they is only the new image underneath.

Likewise a space can be “drawn” by just incrementing your x position by how ever many pixels you want a space to be.

so is there anyway to draw a blank character over a regular character.