added TITLE option on the gameover screen

This commit is contained in:
Return0ne 2022-05-17 19:03:22 -04:00
parent 26c96e3274
commit 794d00a4d7
2 changed files with 39 additions and 27 deletions

View file

@ -4,15 +4,15 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>raylib web game</title> <title>Avoid</title>
<meta name="title" content="raylib web game"> <meta name="title" content="Avoid">
<meta name="description" content="New raylib web videogame, developed using raylib videogames library"> <meta name="description" content="New raylib web videogame, developed using raylib videogames library">
<meta name="keywords" content="raylib, games, html5, programming, C, C++, library, learn, videogames"> <meta name="keywords" content="raylib, games, html5, programming, C, C++, library, learn, videogames">
<meta name="viewport" content="width=device-width"> <meta name="viewport" content="width=device-width">
<!-- Open Graph metatags for sharing --> <!-- Open Graph metatags for sharing -->
<meta property="og:title" content="raylib web game"> <meta property="og:title" content="Avoid">
<meta property="og:image:type" content="image/png"> <meta property="og:image:type" content="image/png">
<meta property="og:image" content="https://www.raylib.com/common/img/raylib_logo.png"> <meta property="og:image" content="https://www.raylib.com/common/img/raylib_logo.png">
<meta property="og:site_name" content="raylib.com"> <meta property="og:site_name" content="raylib.com">
@ -22,10 +22,10 @@
<!-- Twitter metatags for sharing --> <!-- Twitter metatags for sharing -->
<meta name="twitter:card" content="summary"> <meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@raysan5"> <meta name="twitter:site" content="@raysan5">
<meta name="twitter:title" content="raylib web game"> <meta name="twitter:title" content="Avoid">
<meta name="twitter:image" content="https://www.raylib.com/common/raylib_logo.png"> <meta name="twitter:image" content="https://www.raylib.com/common/raylib_logo.png">
<meta name="twitter:url" content="https://www.raylib.com/games.html"> <meta name="twitter:url" content="https://www.raylib.com/games.html">
<meta name="twitter:description" content="New raylib web game, developed using raylib videogames library"> <meta name="twitter:description" content="New Avoid, developed using raylib videogames library">
<!-- Favicon --> <!-- Favicon -->
<link rel="shortcut icon" href="https://www.raylib.com/favicon.ico"> <link rel="shortcut icon" href="https://www.raylib.com/favicon.ico">

View file

@ -31,6 +31,9 @@ typedef struct Player {
} Player; } Player;
// Game variables // Game variables
static int pauseTimer;
static int score, bestscore;
static int titleSelected = 0, gameoverSelected = 0;
static GameScreen currentScreen = { 0 }; static GameScreen currentScreen = { 0 };
static Sound fxbounce = { 0 }; static Sound fxbounce = { 0 };
static Player player = { 0 }; static Player player = { 0 };
@ -38,9 +41,6 @@ static Ball ball = { 0 };
static bool pause; static bool pause;
static bool mute; static bool mute;
static bool ShowHitbox; static bool ShowHitbox;
static int pauseTimer;
static int score, bestscore;
static int selected = 0;
// Game functions // Game functions
static void gameSetup(void); static void gameSetup(void);
@ -58,12 +58,13 @@ int main(void)
gameSetup(); gameSetup();
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
emscripten_set_main_loop(gameLoop, 0, 1); emscripten_set_main_loop(gameLoop, 0, 1);
#else #else
SetTargetFPS(60); SetTargetFPS(60);
while (!WindowShouldClose()) gameLoop(); while (!WindowShouldClose()) gameLoop();
#endif #endif
unloadGame(); unloadGame();
@ -99,7 +100,7 @@ void gameSetup(void)
}; };
ball.position = (Vector2){ 50, 50 }; ball.position = (Vector2){ 50, 50 };
ball.speed = (Vector2){ 400.0f, 300.0f }; ball.speed = (Vector2){ 6.0f, 5.0f };
ball.radius = 20; ball.radius = 20;
ball.growth = 2; ball.growth = 2;
ball.color = MAROON; ball.color = MAROON;
@ -108,7 +109,6 @@ void gameSetup(void)
pause = 0; pause = 0;
mute = 0; mute = 0;
ShowHitbox = 0; ShowHitbox = 0;
pauseTimer = 0; pauseTimer = 0;
score = 0; score = 0;
} }
@ -120,14 +120,14 @@ void updateGame(void)
switch(currentScreen) { switch(currentScreen) {
case TITLE: case TITLE:
if (IsKeyPressed(KEY_UP)) selected++; if (IsKeyPressed(KEY_UP)) titleSelected++;
if (IsKeyPressed(KEY_DOWN)) selected--; if (IsKeyPressed(KEY_DOWN)) titleSelected--;
if (selected > 0) selected--; if (titleSelected > 0) titleSelected--;
if (selected < -2) selected++; if (titleSelected < -2) titleSelected++;
if ((selected == 0) && (IsKeyPressed(KEY_ENTER))) currentScreen = GAMEPLAY; if ((titleSelected == 0) && (IsKeyPressed(KEY_ENTER))) currentScreen = GAMEPLAY;
if ((selected == -1) && (IsKeyPressed(KEY_ENTER))) currentScreen = CREDITS; if ((titleSelected == -1) && (IsKeyPressed(KEY_ENTER))) currentScreen = CREDITS;
if ((selected == -2) && (IsKeyPressed(KEY_ENTER))) OpenURL("https://canneddonuts.itch.io/"); if ((titleSelected == -2) && (IsKeyPressed(KEY_ENTER))) OpenURL("https://canneddonuts.itch.io/");
break; break;
case GAMEPLAY: case GAMEPLAY:
@ -169,8 +169,8 @@ void updateGame(void)
if (ball.active) { if (ball.active) {
score++; score++;
// moveiement oof the balls // moveiement oof the balls
ball.position.x += GetFrameTime() * ball.speed.x; ball.position.x += ball.speed.x;
ball.position.y += GetFrameTime() * ball.speed.y; ball.position.y += ball.speed.y;
if (score >= bestscore) bestscore = score; if (score >= bestscore) bestscore = score;
// Ballz to da wallz collies // Ballz to da wallz collies
@ -197,11 +197,17 @@ void updateGame(void)
break; break;
case GAMEOVER: case GAMEOVER:
if (score > bestscore) bestscore = score; if (IsKeyPressed(KEY_UP)) gameoverSelected++;
if (IsKeyPressed(KEY_ENTER)) { if (IsKeyPressed(KEY_DOWN)) gameoverSelected--;
if (gameoverSelected > 0) gameoverSelected--;
if (gameoverSelected < -1) gameoverSelected++;
if ((gameoverSelected == 0) && (IsKeyPressed(KEY_ENTER))) {
gameReset(); gameReset();
currentScreen = GAMEPLAY; currentScreen = GAMEPLAY;
} }
if ((gameoverSelected == -1) && (IsKeyPressed(KEY_ENTER))) gameReset();
break; break;
case CREDITS: case CREDITS:
if (IsKeyPressed(KEY_ENTER)) currentScreen = TITLE; if (IsKeyPressed(KEY_ENTER)) currentScreen = TITLE;
@ -228,13 +234,13 @@ void drawGame(void)
DrawText("Press 'R' to restart", 10, 120, 10, RED); DrawText("Press 'R' to restart", 10, 120, 10, RED);
DrawText("Press 'ENTER' to select an option", 10, 140, 10, RED); DrawText("Press 'ENTER' to select an option", 10, 140, 10, RED);
DrawText("Avoid", 330, 20, 50, BLUE); DrawText("Avoid", 330, 20, 50, BLUE);
if (selected == 0) DrawText("PLAY", 360, 220, 20, WHITE); if (titleSelected == 0) DrawText("PLAY", 360, 220, 20, WHITE);
else DrawText("PLAY", 360, 220, 20, BLUE); else DrawText("PLAY", 360, 220, 20, BLUE);
if (selected == -1) DrawText("CREDITS", 340, 240, 20, WHITE); if (titleSelected == -1) DrawText("CREDITS", 340, 240, 20, WHITE);
else DrawText("CREDITS", 340, 240, 20, BLUE); else DrawText("CREDITS", 340, 240, 20, BLUE);
if (selected == -2) DrawText("MORE GAMES", 320, 260, 20, WHITE); if (titleSelected == -2) DrawText("MORE GAMES", 320, 260, 20, WHITE);
else DrawText("MORE GAMES", 320, 260, 20, BLUE); else DrawText("MORE GAMES", 320, 260, 20, BLUE);
break; break;
@ -253,7 +259,11 @@ void drawGame(void)
case GAMEOVER: case GAMEOVER:
DrawRectangle(0, 0, screenWidth, screenHeight, BLUE); DrawRectangle(0, 0, screenWidth, screenHeight, BLUE);
DrawText("GAMEOVER", 250, 20, 50, RED); DrawText("GAMEOVER", 250, 20, 50, RED);
DrawText("PRESS ENTER TO RESET", 270, 220, 20, WHITE); if (gameoverSelected == 0) DrawText("RETRY", 350, 200, 20, WHITE);
else DrawText("RETRY", 350, 200, 20, RED);
if (gameoverSelected == -1) DrawText("TITLE", 350, 230, 20, WHITE);
else DrawText("TITLE", 350, 230, 20, RED);
break; break;
case CREDITS: case CREDITS:
@ -294,6 +304,8 @@ void gameReset(void)
pauseTimer = 0; pauseTimer = 0;
score = 0; score = 0;
gameoverSelected = 0;
} }
void gameLoop(void) void gameLoop(void)