|
9 | 9 | #include <GL/freeglut.h> |
10 | 10 | #include <GLFW/glfw3.h> |
11 | 11 |
|
12 | | - |
13 | | -void displayMatrix(glm::mat4 matrix) { |
14 | | - for (int ii = 0; ii < 4; ii++) |
15 | | - { |
16 | | - for (int jj = 0; jj < 4; jj++) |
17 | | - cout << matrix[ii][jj] << " "; |
18 | | - cout << endl; |
19 | | - }; |
20 | | - cout << "\n"; |
21 | | - |
22 | | -}; |
23 | | - |
24 | 12 | void Game::move(void) { |
25 | 13 | for (auto& asteroid : asteroids) { |
26 | 14 | float translatedDistance = asteroid->getTranslatedDistance(); |
@@ -71,29 +59,8 @@ Game::Game(int initial_pos_x, int initial_pos_y) : |
71 | 59 | maxX = width / 2; |
72 | 60 | maxY = height / 2; |
73 | 61 |
|
74 | | - //// Triunghiul de sus |
75 | | - //775.f, 160.f, 0.f, 1.f, |
76 | | - //825.f, 160.f, 0.f, 1.f, |
77 | | - //800.f, 185.f, 0.f, 1.f, |
78 | | - |
79 | | - //// Triunghiul de jos |
80 | | - //775.f, 100.f, 0.f, 1.f, |
81 | | - //825.f, 100.f, 0.f, 1.f, |
82 | | - //800.f, 165.f, 0.f, 1.f, |
83 | | - |
84 | | - //// Deptunghiul |
85 | | - //790.f, 100.f, 0.f, 1.f, // stanga jos |
86 | | - //810.f, 100.f, 0.f, 1.f, // dr jos |
87 | | - //810.f, 175.f, 0.f, 1.f, |
88 | | - //790.f, 175.f, 0.f, 1.f, |
89 | | - |
90 | | - //// Triunghiul din varf |
91 | | - //790.f, 175.f, 0.f, 1.f, |
92 | | - //810.f, 175.f, 0.f, 1.f, |
93 | | - //800.f, 210.f, 0.f, 1.f, |
94 | | - |
95 | | - |
96 | 62 | InitializeGlew(); |
| 63 | + CreateHeartBuffers(); |
97 | 64 | CreateBackgroundBuffers(); |
98 | 65 | CreateRocketBuffers(); |
99 | 66 | CreateAsteroidBuffers(); |
@@ -195,11 +162,15 @@ void Game::FireAnimation() { |
195 | 162 |
|
196 | 163 | void Game::RenderFunction(void) { |
197 | 164 | Rocket* rocket = Rocket::getInstance(); |
| 165 | + |
| 166 | + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
| 167 | + glClear(GL_COLOR_BUFFER_BIT); |
| 168 | + |
198 | 169 | if (rocket->getIsDead()) { |
| 170 | + // TODO: render a png with the text GAME OVER |
| 171 | + //glutSwapBuffers(); |
199 | 172 | return; |
200 | 173 | } |
201 | | - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
202 | | - glClear(GL_COLOR_BUFFER_BIT); |
203 | 174 |
|
204 | 175 | if (rotationAngle > 360.f) { |
205 | 176 | rotationAngle = 0.0f; |
@@ -271,26 +242,25 @@ void Game::RenderFunction(void) { |
271 | 242 | glDrawArrays(GL_POLYGON, 0, Constants::nrOfVerticesPerCircle); |
272 | 243 | } |
273 | 244 |
|
274 | | - /*glBindVertexArray(squareVao); |
275 | | - matrix = scaleMatrix * translateMatrix; |
276 | | - myMatrixLocation = glGetUniformLocation(ProgramId, "myMatrix"); |
277 | | - glUniformMatrix4fv(myMatrixLocation, 1, GL_FALSE, &matrix[0][0]); |
278 | | -
|
279 | | - glDrawArrays(GL_POLYGON, 0, 4);*/ |
280 | | - |
281 | 245 | rocket->RocketAsteroidsCollision(asteroids); |
| 246 | + |
| 247 | + glm::mat4 heartMatrix = glm::scale(glm::mat4(1.0f), glm::vec3(4.7f, 4.7f, 1.0f)); |
| 248 | + heartMatrix = backgroundMatrix * heartMatrix; |
| 249 | + |
| 250 | + glm::mat4 heartTranslateMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(10.0f, 0.0f, 0.0f)); |
| 251 | + for (int i = 0; i < rocket->getRemainingLives(); i++) { |
| 252 | + if (i != 0) { |
| 253 | + heartMatrix = heartMatrix * heartTranslateMatrix; |
| 254 | + } |
| 255 | + glUniformMatrix4fv(myMatrixLocation, 1, GL_FALSE, &heartMatrix[0][0]); |
| 256 | + glBindVertexArray(heartVao); |
| 257 | + glDrawArrays(GL_POLYGON, 0, 14); |
| 258 | + } |
282 | 259 |
|
283 | 260 | glutPostRedisplay(); |
284 | 261 | glFlush(); |
285 | 262 | } |
286 | 263 |
|
287 | | -bool colliding(Rocket rocket, Asteroid asteroid) |
288 | | -{ |
289 | | - return false; |
290 | | -} |
291 | | - |
292 | | - |
293 | | - |
294 | 264 | void Game::CreateBackgroundBuffers() { |
295 | 265 |
|
296 | 266 | const int nrOfVertices = 1000 * 5; |
@@ -464,24 +434,20 @@ void Game::CreateAsteroidBuffers() { |
464 | 434 | GLfloat Colors[1000]; |
465 | 435 | for (int k = 0; k < Constants::nrOfVerticesPerCircle; k++) { |
466 | 436 | float theta = Constants::TWO_PI * k / Constants::nrOfVerticesPerCircle; |
467 | | - cout << "angle " << float(Constants::TWO_PI * float(k)) / float(Constants::nrOfVerticesPerCircle) << "\n"; |
468 | 437 | float x = cos(theta); |
469 | 438 | float y = sin(theta); |
470 | 439 | // varfurile corespunzatoare cercului |
471 | 440 | Vertices[4 * k] = x; |
472 | 441 | Vertices[4 * k + 1] = y; |
473 | 442 | Vertices[4 * k + 2] = 0.0f; |
474 | 443 | Vertices[4 * k + 3] = 1.0f; |
475 | | - cout << 4*k << " " << Vertices[4 * k] << " " << Vertices[4 * k + 1] << " " << Vertices[4 * k + 2] << " " << Vertices[4 * k + 3] << "\n"; |
476 | 444 |
|
477 | 445 | Colors[4 * k] = 1.0f; |
478 | 446 | Colors[4 * k + 1] = 0.0f; |
479 | 447 | Colors[4 * k + 2] = 0.0f; |
480 | 448 | Colors[4 * k + 3] = 1.0f; |
481 | 449 | } |
482 | | - for (int i = 0; i < Constants::nrOfVerticesPerCircle * 4 - 4; i+=4) { |
483 | | - //cout << Vertices[i] << " " << Vertices[i + 1] << " " << Vertices[i + 2] << " " << Vertices[i + 3] << "\n"; |
484 | | - } |
| 450 | + |
485 | 451 | int verticesCount = sizeof(Vertices) / sizeof(GLfloat); |
486 | 452 |
|
487 | 453 | glGenBuffers(1, &asteroidVbo); |
@@ -614,3 +580,53 @@ void Game::UpdateBullets() { |
614 | 580 |
|
615 | 581 | bullets.erase(end, bullets.end()); |
616 | 582 | } |
| 583 | + |
| 584 | +void Game::CreateHeartBuffers() { |
| 585 | + |
| 586 | + GLfloat Vertices[] = { |
| 587 | + 7.0f, 3.7f, 0.0f, 1.0f, |
| 588 | + |
| 589 | + 8.0f, 4.5f, 0.0f, 1.0f, |
| 590 | + 9.6f, 6.0f, 0.0f, 1.0f, |
| 591 | + 10.4f, 7.5f, 0.0f, 1.0f, |
| 592 | + 10.0f, 9.0f, 0.0f, 1.0f, |
| 593 | + 8.7f, 9.8f, 0.0f, 1.0f, |
| 594 | + 7.8f, 9.7f, 0.0f, 1.0f, |
| 595 | + |
| 596 | + 7.0f, 8.9f, 0.0f, 1.0f, |
| 597 | + |
| 598 | + 6.2f, 9.7f, 0.0f, 1.0f, |
| 599 | + 5.3f, 9.8f, 0.0f, 1.0f, |
| 600 | + 4.0f, 9.0f, 0.0f, 1.0f, |
| 601 | + 3.6f, 7.5f, 0.0f, 1.0f, |
| 602 | + 4.4f, 6.0f, 0.0f, 1.0f, |
| 603 | + 6.0f, 4.5f, 0.0f, 1.0f, |
| 604 | + }; |
| 605 | + |
| 606 | + const int verticesCount = sizeof(Vertices) / sizeof(GLfloat); |
| 607 | + |
| 608 | + GLfloat Colors[verticesCount]; |
| 609 | + |
| 610 | + for (int i = 0; i < verticesCount; i += 4) { |
| 611 | + Colors[i] = 1.0f; |
| 612 | + Colors[i + 1] = 0.0f; |
| 613 | + Colors[i + 2] = 0.0f; |
| 614 | + Colors[i + 3] = 1.0f; |
| 615 | + } |
| 616 | + |
| 617 | + glGenBuffers(1, &heartVbo); |
| 618 | + glBindBuffer(GL_ARRAY_BUFFER, heartVbo); |
| 619 | + glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW); |
| 620 | + |
| 621 | + glGenVertexArrays(1, &heartVao); |
| 622 | + glBindVertexArray(heartVao); |
| 623 | + |
| 624 | + glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0); |
| 625 | + glEnableVertexAttribArray(0); |
| 626 | + |
| 627 | + glGenBuffers(1, &heartColorBufferId); |
| 628 | + glBindBuffer(GL_ARRAY_BUFFER, heartColorBufferId); |
| 629 | + glBufferData(GL_ARRAY_BUFFER, sizeof(Colors), Colors, GL_STATIC_DRAW); |
| 630 | + glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 0); |
| 631 | + glEnableVertexAttribArray(1); |
| 632 | +} |
0 commit comments