Skip to content

Commit d68e876

Browse files
authored
Merge pull request #39 from DianaVasiliu/diana
Added score
2 parents 5830e7a + 4edda07 commit d68e876

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

OpenRocket/OpenRocket/Game.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Game* Game::getInstance() {
5050

5151
Game::Game(int initial_pos_x, int initial_pos_y) :
5252
nrOfStars(Constants::nrOfStars),
53+
score(0),
5354
width(Constants::maxX),
5455
height(Constants::maxY),
5556
maxX(Constants::maxX),
@@ -241,10 +242,13 @@ void Game::RenderFunction(void) {
241242
glBindVertexArray(asteroidVao);
242243
glDrawArrays(GL_POLYGON, 0, Constants::nrOfVerticesPerCircle);
243244
}
245+
244246
glDisable(GL_TEXTURE_2D);
245247
glUseProgram(ProgramId);
246248
myMatrixLocation = glGetUniformLocation(ProgramId, "myMatrix");
249+
247250
Game::UpdateBullets();
251+
248252
for (auto& bullet : bullets) {
249253
glm::mat4 bulletMatrix = glm::scale(glm::mat4(1.0f), glm::vec3(bullet->getRadius(), bullet->getRadius(), 1.0f));
250254
glm::mat4 animateMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0, bullet->getY(), 0.0));
@@ -586,8 +590,7 @@ double distance(glm::vec4 p1, glm::vec4 p2) {
586590
}
587591

588592
void Game::BulletAsteroidCollision() {
589-
vector<int> eraseAsteroids;
590-
vector<int> eraseBullets;
593+
591594
for (int i = 0; i < int(bullets.size()); i++) {
592595
for (int j = 0; j < int(asteroids.size()); j++) {
593596
glm::vec4 currentBulletCenter = bullets[i]->bulletMatrix * Bullet::bulletCenter;
@@ -602,6 +605,7 @@ void Game::BulletAsteroidCollision() {
602605
if (distance(currentAsteroidCenter, currentBulletCenter) < currentBulletRadius + currentAsteroidRadius) {
603606
bullets[i]->setToBeDeleted(true);
604607
asteroids[j]->setToBeDeleted(true);
608+
score++;
605609
}
606610
}
607611
}

OpenRocket/OpenRocket/Game.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Game {
8080
GLuint TextureProgramId;
8181

8282
int nrOfStars;
83+
int score;
8384

8485
int colorCode;
8586
int initPosX;
@@ -116,6 +117,7 @@ class Game {
116117
int getWidth() const { return width; }
117118
int getInitPosX() const { return initPosX; }
118119
int getInitPosY() const { return initPosY; }
120+
int getScore() const { return score; }
119121

120122
void CreateBackgroundBuffers();
121123
void CreateRocketBuffers();

OpenRocket/OpenRocket/Rocket.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ void Rocket::RocketAsteroidsCollision(vector<Asteroid*> asteroids)
234234

235235
if (remainingLives == 0) {
236236
isDead = true;
237+
238+
Game* game = Game::getInstance();
239+
std::cout << "Your score is: " << game->getScore() / 2 << "\n";
237240
}
238241
}
239242

0 commit comments

Comments
 (0)