Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: breakout game scoring

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    26

    Question 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.
    Code :
    	{
    	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.

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    10
    Just tell it to add the score if the ball is within the hitbox of the brick.

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

    Something like that

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    26
    can you elaborate on the score.add(100) piece of code

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    10
    Well you need a class to keep track of the players score, so it would probably be something like this
    Code :
    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;
    }
     
    }

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    26
    thanks for the code, I have stubbed it out and I am learning how it works.

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    10
    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.

  7. #7
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    26
    well I have adjusted poppit's code. I am still confused about what the "this" keyword does. here is my code.
    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;
    }

  8. #8
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    10
    I'm sorry, I confused you. this is used for java, which I thought you were programming in. You can get rid of it.

  9. #9
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    26
    actually I am using c++

  10. #10
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    26
    is there anyway to erase a glutBitmapCharacter character?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •