PDA

View Full Version : breakout game scoring



pbivens
01-21-2013, 03:01 PM
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.

Poppit
01-21-2013, 03:39 PM
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

pbivens
01-21-2013, 03:45 PM
can you elaborate on the score.add(100) piece of code

Poppit
01-21-2013, 03:55 PM
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;
}

}

pbivens
01-21-2013, 04:36 PM
thanks for the code, I have stubbed it out and I am learning how it works.

Poppit
01-21-2013, 04:40 PM
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.

pbivens
01-21-2013, 06:54 PM
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;
}

Poppit
01-21-2013, 07:21 PM
I'm sorry, I confused you. this is used for java, which I thought you were programming in. You can get rid of it.

pbivens
01-21-2013, 10:08 PM
actually I am using c++

pbivens
01-22-2013, 02:45 PM
is there anyway to erase a glutBitmapCharacter character?

pbivens
01-26-2013, 01:40 PM
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);
}

pbivens
01-29-2013, 09:27 PM
I am still stuck on how to print a blank character to the screen using glutBitmapCharacter command.

pbivens
01-30-2013, 10:12 PM
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.

tonyo_au
01-30-2013, 10:58 PM
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.

pbivens
01-31-2013, 01:50 PM
so is there anyway to draw a blank character over a regular character.