61 lines
1.7 KiB
C
61 lines
1.7 KiB
C
#include <raylib.h>
|
|
|
|
#include "app.h"
|
|
#include "gameover.h"
|
|
|
|
void InitGameOver(GameOverState *g) {
|
|
int windowWidth = GetScreenWidth();
|
|
int windowHeight = GetScreenHeight();
|
|
Vector2 buttonDimensions = {200, 60};
|
|
Vector2 buttonPos = {windowWidth / 2.0f, windowHeight / 2.0f + 80.0f};
|
|
g->restartButton = initButton("Restart", buttonDimensions, buttonPos);
|
|
}
|
|
|
|
void UpdateGameOver(App *app) {
|
|
if (isButtonClicked(&app->gameOver.restartButton)) {
|
|
ResetGame(app);
|
|
app->state.currentView = GAMEPLAY;
|
|
}
|
|
|
|
UpdateMouseScreen(&app->game.mouse);
|
|
|
|
OnWindowClosedStoppApp(app);
|
|
}
|
|
|
|
void RenderGameOver(App *app) {
|
|
BeginDrawing();
|
|
ClearBackground(BLACK);
|
|
|
|
int windowWidth = GetScreenWidth();
|
|
int windowHeight = GetScreenHeight();
|
|
|
|
const char *title = "GAME OVER";
|
|
int titleSize = app->font.baseSize * 2;
|
|
Vector2 titleDim = MeasureTextEx(app->font, title, titleSize, 2);
|
|
DrawTextEx(
|
|
app->font, title,
|
|
(Vector2){windowWidth / 2.0f - titleDim.x / 2.0f, windowHeight / 2.0f - titleDim.y - 40.0f},
|
|
titleSize, 2, TEXT_COLOR_LIGHT);
|
|
|
|
const char *goldText = TextFormat("Gold collected: %i", app->game.player.gold);
|
|
int goldSize = app->font.baseSize;
|
|
Vector2 goldDim = MeasureTextEx(app->font, goldText, goldSize, 2);
|
|
DrawTextEx(
|
|
app->font, goldText,
|
|
(Vector2){windowWidth / 2.0f - goldDim.x / 2.0f, windowHeight / 2.0f - goldDim.y / 2.0f},
|
|
goldSize, 2, TEXT_COLOR_LIGHT);
|
|
|
|
renderButton(&app->gameOver.restartButton);
|
|
|
|
Mouse *mouse = &app->game.mouse;
|
|
Rectangle mouseRectangle =
|
|
(Rectangle){0, 0, mouse->cursorTexture.width, mouse->cursorTexture.height};
|
|
DrawTextureRec(mouse->cursorTexture, mouseRectangle, mouse->screenPosition, WHITE);
|
|
|
|
if (app->flags.showFPS) {
|
|
DrawFPS(10, 10);
|
|
}
|
|
|
|
EndDrawing();
|
|
}
|