master
ブランチ master
Snake / src / scene / gameover.cc
1.3 KB、43行 生 Blame 履歴
1#include <snake/scene/gameover.hh>
2#include <snake/snake.hh>
3#include <raylib.h>
4
5namespace snake::scene {
6 int highScore = 0;
7
8 bool GameOver::Init() {
9 if (snake::score > highScore) highScore = snake::score;
10 return true;
11 }
12
13 bool GameOver::Update() {
14 if (IsKeyPressed(KEY_ENTER)) {
15 snake::PlaySFX(snake::Confirm, 1.f);
16 snake::Close();
17 snake::s = snake::GameMain;
18 snake::Init();
19 }
20
21 ClearBackground(BLACK);
22
23 int fontSize = 24;
24 int textWidth = MeasureText("GAME OVER", fontSize);
25 DrawText("GAME OVER", GetScreenWidth() / 2 - textWidth / 2, GetScreenHeight() / 2 - 30, fontSize, RED);
26
27 fontSize = 16;
28 const char *score = TextFormat("SCORE: %d", snake::score);
29 textWidth = MeasureText(score, fontSize);
30 DrawText(score, GetScreenWidth() / 2 - textWidth / 2, GetScreenHeight() / 2 + 30, fontSize, RED);
31
32 const char *hScore = TextFormat("HIGH SCORE: %d", highScore);
33 textWidth = MeasureText(hScore, fontSize);
34 DrawText(hScore, GetScreenWidth() / 2 - textWidth / 2, GetScreenHeight() / 2 + 60, fontSize, RED);
35
36 textWidth = MeasureText("PRESS ENTER TO TRY AGAIN", fontSize);
37 DrawText("PRESS ENTER TO TRY AGAIN", GetScreenWidth() / 2 - textWidth / 2, GetScreenHeight() / 2 + 90, fontSize, RED);
38 return true;
39 }
40
41 void GameOver::Close() {
42 }
43} // namespace snake::scene