Skip to content

Commit fc70fc9

Browse files
committed
Added Game Over screen
1 parent 4edda07 commit fc70fc9

File tree

7 files changed

+53
-6
lines changed

7 files changed

+53
-6
lines changed

OpenRocket/OpenRocket/Constants.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const std::vector<const char*> Constants::textureImages {
2727
"orangeAsteroid.png",
2828
"turquoiseAsteroid.png"
2929
};
30+
const char* Constants::gameOverTexture = "gameOver.png";
3031
const int Constants::nrOfTextures = 6;
3132
const float Constants::bulletSpeed = 0.1f;
3233
const double Constants::bulletSpawnCooldown = 0.1;

OpenRocket/OpenRocket/Constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Constants
2525
static const std::string RED;
2626
static const std::string SAFE;
2727
static const std::vector<const char*> textureImages;
28+
static const char* gameOverTexture;
2829
static const int nrOfTextures;
2930
static const float bulletSpeed;
3031
static const double bulletSpawnCooldown;

OpenRocket/OpenRocket/Game.cpp

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Game::Game(int initial_pos_x, int initial_pos_y) :
7171
CreateRocketBuffers();
7272
CreateAsteroidBuffers();
7373
CreateBulletBuffers();
74+
CreateGameOverBuffers();
7475
GenerateAsteroids(Constants::nrOfAsteroidsPerFrame);
7576
}
7677

@@ -90,7 +91,7 @@ void Game::InitializeLibraries() {
9091

9192
void Game::CreateShaders() {
9293
ProgramId = LoadShaders("vertShader.vert", "fragShader.frag");
93-
TextureProgramId = LoadShaders("asteroidTextureShader.vert", "asteroidTextureShader.frag");
94+
TextureProgramId = LoadShaders("textureShader.vert", "textureShader.frag");
9495
glUseProgram(ProgramId);
9596
}
9697

@@ -120,6 +121,7 @@ void Game::DestroyVBO(void) {
120121
glDeleteBuffers(1, &squareVbo);
121122
glDeleteBuffers(1, &heartColorBufferId);
122123
glDeleteBuffers(1, &heartVbo);
124+
glDeleteBuffers(1, &gameOverVbo);
123125

124126
glBindVertexArray(0);
125127
}
@@ -175,11 +177,21 @@ void Game::RenderFunction(void) {
175177
Rocket* rocket = Rocket::getInstance();
176178

177179
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
178-
glClear(GL_COLOR_BUFFER_BIT);
180+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
179181

180182
if (rocket->getIsDead()) {
181-
// TODO: render a png with the text GAME OVER
182-
//glutSwapBuffers();
183+
glUseProgram(TextureProgramId);
184+
myMatrixLocation = glGetUniformLocation(TextureProgramId, "myMatrix");
185+
186+
glActiveTexture(GL_TEXTURE0);
187+
glBindTexture(GL_TEXTURE_2D, gameOverTexture);
188+
189+
glm::mat4 gameOverMatrix = backgroundMatrix;
190+
glUniformMatrix4fv(myMatrixLocation, 1, GL_FALSE, &gameOverMatrix[0][0]);
191+
glBindVertexArray(gameOverVao);
192+
glDrawArrays(GL_POLYGON, 0, 4);
193+
194+
glFlush();
183195
return;
184196
}
185197

@@ -391,7 +403,7 @@ void Game::CreateRocketBuffers() {
391403
glBindBuffer(GL_ARRAY_BUFFER, squareVbo);
392404
glBufferData(GL_ARRAY_BUFFER, sizeof(Square), Square, GL_STATIC_DRAW);
393405

394-
glGenVertexArrays(1, &squareVbo);
406+
glGenVertexArrays(1, &squareVao);
395407
glBindVertexArray(squareVao);
396408

397409
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
@@ -516,7 +528,8 @@ void Game::loadTextures() {
516528
GLuint texture;
517529
LoadTexture(texture, imageName);
518530
Game::textures.push_back(texture);
519-
}
531+
}
532+
LoadTexture(gameOverTexture, Constants::gameOverTexture);
520533
}
521534

522535
void Game::CreateBulletBuffers() {
@@ -676,3 +689,29 @@ void Game::CreateHeartBuffers() {
676689
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 0);
677690
glEnableVertexAttribArray(1);
678691
}
692+
693+
void Game::CreateGameOverBuffers() {
694+
GLfloat Vertices[] = {
695+
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
696+
Constants::maxX, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
697+
Constants::maxX, Constants::maxY, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f,
698+
0.0f, Constants::maxY, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
699+
};
700+
701+
glGenVertexArrays(1, &gameOverVao);
702+
glGenBuffers(1, &gameOverVbo);
703+
704+
glBindVertexArray(gameOverVao);
705+
706+
glBindBuffer(GL_ARRAY_BUFFER, gameOverVbo);
707+
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
708+
709+
glEnableVertexAttribArray(0);
710+
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 9 * sizeof(GLfloat), (GLvoid*)0);
711+
712+
glEnableVertexAttribArray(1);
713+
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(GLfloat), (GLvoid*)(4 * sizeof(GLfloat)));
714+
715+
glEnableVertexAttribArray(2);
716+
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 9 * sizeof(GLfloat), (GLvoid*)(7 * sizeof(GLfloat)));
717+
}

OpenRocket/OpenRocket/Game.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class Game {
5353
GLuint heartVbo;
5454
GLuint heartColorBufferId;
5555

56+
GLuint gameOverVao;
57+
GLuint gameOverVbo;
58+
5659
glm::mat4 rocketMatrix = glm::mat4(1.0f);
5760
glm::mat4 rocketScaleMatrix = glm::mat4(1.0f);
5861
glm::mat4 rocketRotateMatrix = glm::mat4(1.0f);
@@ -79,6 +82,8 @@ class Game {
7982
GLuint ProgramId;
8083
GLuint TextureProgramId;
8184

85+
GLuint gameOverTexture;
86+
8287
int nrOfStars;
8388
int score;
8489

@@ -124,6 +129,7 @@ class Game {
124129
void CreateAsteroidBuffers();
125130
void CreateBulletBuffers();
126131
void CreateHeartBuffers();
132+
void CreateGameOverBuffers();
127133

128134
void InitializeLibraries();
129135
void CreateShaders();

OpenRocket/OpenRocket/gameOver.png

10.3 KB
Loading
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)