Skip to content

Commit

Permalink
🔥 game over
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeFTN committed Jul 24, 2023
1 parent a352c42 commit 8636468
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ int main() {

Map map{};
int wallTime = 0;
bool gameover = false;
bool show_wall_0 = true;
bool show_wall_1 = false;
Rectangle wall_0{-84, 111, 100, screenHeight / 1.8f};
Expand All @@ -24,7 +25,7 @@ int main() {

while (!WindowShouldClose()) {

map.WallControl(&wallTime, &show_wall_0, &show_wall_1);
map.WallControl(&wallTime, &show_wall_0, &show_wall_1, gameover);

ball_0.Collision(&ball_1, show_wall_0, show_wall_1);
ball_1.Collision(&ball_0, show_wall_0, show_wall_1);
Expand All @@ -41,12 +42,18 @@ int main() {
if (ball_0.GetScore() > 0) {
ball_0.Draw();
ball_0.Move(GetFrameTime());
} else { DrawText("Player 2 Won!", (screenWidth / 2) - 60, screenHeight / 2, 20, LIGHTGRAY); }
} else {
DrawText("Player 2 Won!", (screenWidth / 2) - 60, screenHeight / 2, 20, LIGHTGRAY);
gameover = true;
}

if (ball_1.GetScore() > 0) {
ball_1.Draw();
ball_1.Move(GetFrameTime());
} else { DrawText("Player 1 Won!", (screenWidth / 2) - 60, screenHeight / 2, 20, LIGHTGRAY); }
} else {
DrawText("Player 1 Won!", (screenWidth / 2) - 60, screenHeight / 2, 20, LIGHTGRAY);
gameover = true;
}

EndDrawing();
}
Expand Down
8 changes: 7 additions & 1 deletion src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ void Map::DrawMap(int screenWidth, int screenHeight) {
DrawTextureEx(background, (Vector2){ 0.0f, 0.0f }, 0.0f, 8.0f, WHITE);
}

void Map::WallControl(int *wallTime, bool *show_wall_0, bool *show_wall_1) {
void Map::WallControl(int *wallTime, bool *show_wall_0, bool *show_wall_1, bool gameover) {
if (gameover) {
*show_wall_0 = true;
*show_wall_1 = true;
return;
}

*wallTime += 1;
if (*wallTime == 600) {
*show_wall_0 = *show_wall_0 ? false : true;
Expand Down
2 changes: 1 addition & 1 deletion src/map/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Map {
public:
void DrawMap(int screenWidth, int screenHeight);
void Wall(Rectangle *wall, bool active);
void WallControl(int *wallTime, bool *show_wall_0, bool *show_wall_1);
void WallControl(int *wallTime, bool *show_wall_0, bool *show_wall_1, bool gameover);
void HideWall(Rectangle *wall);
void ShowWall(Rectangle *wall);

Expand Down

0 comments on commit 8636468

Please sign in to comment.