From 18c26edd6bae8ce5bd26e0ab632086725f492871 Mon Sep 17 00:00:00 2001 From: nathansmithsmith Date: Fri, 22 Dec 2023 02:06:49 -0700 Subject: Moved the screens to a better place --- src/game.h | 6 +- src/gameScreen.c | 545 ------------------------------------------ src/gameScreen.h | 69 ------ src/howToPlayScreen.c | 58 ----- src/howToPlayScreen.h | 15 -- src/mainMenu.c | 54 ----- src/mainMenu.h | 18 -- src/screens/gameScreen.c | 545 ++++++++++++++++++++++++++++++++++++++++++ src/screens/gameScreen.h | 69 ++++++ src/screens/howToPlayScreen.c | 58 +++++ src/screens/howToPlayScreen.h | 15 ++ src/screens/mainMenu.c | 54 +++++ src/screens/mainMenu.h | 18 ++ 13 files changed, 762 insertions(+), 762 deletions(-) delete mode 100644 src/gameScreen.c delete mode 100644 src/gameScreen.h delete mode 100644 src/howToPlayScreen.c delete mode 100644 src/howToPlayScreen.h delete mode 100644 src/mainMenu.c delete mode 100644 src/mainMenu.h create mode 100644 src/screens/gameScreen.c create mode 100644 src/screens/gameScreen.h create mode 100644 src/screens/howToPlayScreen.c create mode 100644 src/screens/howToPlayScreen.h create mode 100644 src/screens/mainMenu.c create mode 100644 src/screens/mainMenu.h (limited to 'src') diff --git a/src/game.h b/src/game.h index 74252e6..e93afc9 100644 --- a/src/game.h +++ b/src/game.h @@ -1,6 +1,6 @@ #include "gameCommon.h" -#include "mainMenu.h" -#include "gameScreen.h" +#include "screens/mainMenu.h" +#include "screens/gameScreen.h" #include "cameras.h" #include "entity.h" #include "assets.h" @@ -9,7 +9,7 @@ #include "bullets.h" #include "levels.h" #include "killLog.h" -#include "howToPlayScreen.h" +#include "screens/howToPlayScreen.h" #ifndef GAME_H #define GAME_H diff --git a/src/gameScreen.c b/src/gameScreen.c deleted file mode 100644 index de650c5..0000000 --- a/src/gameScreen.c +++ /dev/null @@ -1,545 +0,0 @@ -#include "gameScreen.h" -#include "game.h" -#include "world.h" -#include "entity.h" -#include "bullets.h" -#include "assets.h" -#include "killLog.h" -#include "entitiesInclude.h" - -#define NEXT_LEVEL_INSULTS_COUNT 4 - -const char * nextLevelInsults[NEXT_LEVEL_INSULTS_COUNT] = { - "You suck at this game", - "Your the living enbodiment of a skill issue", - "Your grandma could do better then that", - "Go touch grass" -}; - -void initGameScreenGui(GameScreen * gameScreen) { - float width = GetScreenWidth(); - float height = GetScreenHeight(); - - // It is kind of terrible but works. - gameScreen->infoTextPosition = (Vector2){0.0, height / 1.5}; - - gameScreen->targetInfoPosition = (Vector2){ - width - (GAME_SCREEN_TEXT_SIZE * (GAME_SCREEN_TARGET_INFO_MAX / 2.0)), - height - RADAR_TEXTURE_SIZE - (GAME_SCREEN_TEXT_SIZE * 4.0) - }; - - gameScreen->zoomViewPosition = (Vector2){width - GAME_SCREEN_ZOOM_VIEW_UI_SIZE - 20.0, 10.0}; - - gameScreen->killLogPosition = (Vector2){0.0, 40.0}; - - resetRadarPosition(&gameScreen->radar); - resetGyroscopePosition(&gameScreen->gyroscope); -} - -void initGameScreen(Game * game, GameScreen * gameScreen) { - - // World render. - if (game->settings.useWorldRenderTexture) { - gameScreen->worldRender = LoadRenderTexture(game->settings.renderWidth, game->settings.renderHeight); - gameScreen->usingWorldRenderTexture = true; - } else { - gameScreen->usingWorldRenderTexture = false; - } - - // Zoom view. - gameScreen->zoomViewTexture = LoadRenderTexture(GAME_SCREEN_ZOOM_VIEW_SIZE, GAME_SCREEN_ZOOM_VIEW_SIZE); - - gameScreen->gameOver = false; - gameScreen->mainCamera = THIRD_PERSON_CAMERA; - gameScreen->levelComplete = false; - gameScreen->healthAtLevelEnd = ENTITY_MAX_HEALTH; - gameScreen->nextLevelInsultNum = 0; - gameScreen->gameComplete = false; - - // Gyroscope indeed - initGyroscope(&gameScreen->gyroscope); - - // Radar indeed. - initRadar(&gameScreen->radar); - - initStars(&gameScreen->stars); - - initGameScreenGui(gameScreen); -} - -void freeGameScreen(GameScreen * gameScreen) { - closeGyroscope(&gameScreen->gyroscope); - closeRadar(&gameScreen->radar); - - if (gameScreen->usingWorldRenderTexture) - UnloadRenderTexture(gameScreen->worldRender); - - UnloadRenderTexture(gameScreen->zoomViewTexture); -} - -void drawCrossHairPosition(Vector2 position, float size, float thick, Color color) { - // Left to right. - DrawLineEx( - (Vector2){position.x - size, position.y}, - (Vector2){position.x + size, position.y}, - thick, - color - ); - - // Top to bottom. - DrawLineEx( - (Vector2){position.x, position.y - size}, - (Vector2){position.x, position.y + size}, - thick, - color - ); -} - -void drawCrossHair(float size, float thick, Color color) { - Vector2 center = (Vector2){GetScreenWidth() / 2.0, GetScreenHeight() / 2.0}; - drawCrossHairPosition(center, size, thick, color); -} - -void drawGameScreenInfoText(Game * game, GameScreen * gameScreen) { - Entity * player = getEntityFromWorld(game->world, 0); - AntifaShip * data = (AntifaShip*)player->data; - - // Hello reader. I fucking hate you! - size_t bufSize = 255; - char buf[bufSize]; - - // Format text. - snprintf( - buf, - bufSize, - "Health %.2f\n\nX %.2f\nY %.2f\nZ %.2f\n\nSpeed %.2f/%.2f", - player->health, - player->position.x, - player->position.y, - player->position.z, - data->forwardSpeed, - Vector3Length(player->velocity.velocity) - ); - - // Draw info text. - DrawText( - buf, - gameScreen->infoTextPosition.x, - gameScreen->infoTextPosition.y, - GAME_SCREEN_TEXT_SIZE, - GREEN - ); -} - -void drawGameScreenTargetInfo(Game * game, GameScreen * gameScreen) { - Entity * player = getEntityFromWorld(game->world, 0); - AntifaShip * data = (AntifaShip*)player->data; - - size_t bufSize = 255; - char buf[bufSize]; - - // Format. - snprintf( - buf, - bufSize, - "Auto: %s", - data->doAutoTarget ? "On" : "Off" - ); - - // Is auto targeting. - if (data->doAutoTarget) { - Entity * targetedEntity = getEntityFromWorld(game->world, data->targetedEntityId); - - if (targetedEntity != NULL) { - char bufCopy[bufSize]; - strncpy(bufCopy, buf, bufSize); - - // Add more formatted text. - snprintf( - buf, - bufSize, - "%s\nId: %d@%x\nDistance: %.2f\nOn Target: %s", - bufCopy, - data->targetedEntityId, - data->targetedEntityFingerprint, - Vector3Distance(player->position, targetedEntity->position), - data->isOnTarget ? "Yes" : "No" - ); - } - } - - // Draw. - DrawText( - buf, - gameScreen->targetInfoPosition.x, - gameScreen->targetInfoPosition.y, - GAME_SCREEN_TEXT_SIZE, - GREEN - ); -} - -void drawGameScreenGui(Game * game) { - GameScreen * gameScreen = &game->gameScreen; - - // Draw cross hair. - if (gameScreen->mainCamera == FIRST_PERSON_CAMERA || gameScreen->mainCamera == ZOOM_CAMERA) { - // Get color depending if on target or not. - Entity * player = getEntityFromWorld(game->world, 0); - AntifaShip * data = (AntifaShip*)player->data; - Color color = data->isOnTarget ? RED : BLUE; - - drawCrossHair(10.0, 2.0, color); - } - - drawKillLog(&game->killLog, gameScreen->killLogPosition); - drawGameScreenInfoText(game, gameScreen); - drawGameScreenTargetInfo(game, gameScreen); - drawGyroscope(game, &gameScreen->gyroscope); - drawRadar(game, &gameScreen->radar); -} - -void handleGameScreenInput(Game * game, GameScreen * gameScreen) { - switch(GetKeyPressed()) { - case KEY_ONE: - gameScreen->mainCamera = FIRST_PERSON_CAMERA; - break; - case KEY_TWO: - gameScreen->mainCamera = THIRD_PERSON_CAMERA; - break; - case KEY_THREE: - gameScreen->mainCamera = ZOOM_CAMERA; - break; - // case KEY_FOUR: - // gameScreen->mainCamera = DEBUG_CAMERA; - // break; - default: - break; - } -} - -void drawNextLevelScreen(Game * game, GameScreen * gameScreen) { - float width = GetScreenWidth(); - float height = GetScreenHeight(); - - size_t bufSize = 100; - char buf[bufSize]; - - // Complete message. - snprintf( - buf, - bufSize, - "Level %d complete", - gameScreen->lastLevel + 1 - ); - - DrawText( - buf, - (width / 2.0) - (50.0 * strnlen(buf, bufSize) / 4.0), - height / 3.0, - 50, - GREEN - ); - - // Draw insult. - const char * insult = nextLevelInsults[gameScreen->nextLevelInsultNum]; - - DrawText( - insult, - (width / 2.0) - (GAME_SCREEN_TEXT_SIZE * strlen(insult) / 4.0), - height / 3.0 + 70.0, - GAME_SCREEN_TEXT_SIZE, - GREEN - ); -} - -void callThisFuckerAtGameComplete(Game * game, GameScreen * gameScreen) { - gameScreen->gameComplete = true; - gameScreen->gameCompleteAt = GetTime(); -} - -void gameScreenHandleLevels(Game * game, GameScreen * gameScreen) { - // Show complete screen if level complete. - if (gameScreen->levelComplete) { - drawNextLevelScreen(game, gameScreen); - - // Next fucking level. - if (GetTime() - gameScreen->timeAtLevelComplete >= GAME_SCREEN_NEXT_LEVEL_DELAY || IsKeyPressed(KEY_SPACE)) { - gameScreen->levelComplete = false; - startLevel(game, &game->levels, gameScreen->lastLevel + 1); - getEntityFromWorld(game->world, 0)->health = Clamp(gameScreen->healthAtLevelEnd * 1.5, 0.0, 1.0); - } - - return; - } - - bool complete = updateLevel(game, &game->levels); - - // This fucker been completed. - if (complete) { - gameScreen->lastLevel = game->levels.currentLevel; - gameScreen->healthAtLevelEnd = getEntityFromWorld(game->world, 0)->health; - - // Game is complete lol. - if (game->levels.currentLevel == GAME_LEVELS_COMPLETE_AT) - callThisFuckerAtGameComplete(game, gameScreen); - - endLevel(game, &game->levels); - - gameScreen->levelComplete = true; - gameScreen->timeAtLevelComplete = GetTime(); - - SetRandomSeed(time(NULL)); - gameScreen->nextLevelInsultNum = GetRandomValue(0, NEXT_LEVEL_INSULTS_COUNT - 1); - } -} - -void drawGameScreenStars(Game * game, GameScreen * gameScreen) { - DrawModel( - game->assets.models[SKY_ASSET], - getEntityFromWorld(game->world, 0)->position, - GAME_SCREEN_SKY_BOX_SIZE, - WHITE - ); - - drawStars(game, &gameScreen->stars); -} - -void renderWorldGameScreen(Game * game, GameScreen * gameScreen) { - BeginMode3D(game->cameras[gameScreen->mainCamera]); - - drawGameScreenStars(game, gameScreen); - - // Draw world. - drawWorld(&game->world, game); - - EndMode3D(); -} - -void drawZoomViewGameScreen(Game * game, GameScreen * gameScreen) { - CameraId cameraId = ZOOM_CAMERA; - - if (gameScreen->mainCamera == ZOOM_CAMERA) - cameraId = THIRD_PERSON_CAMERA; - - // Update camera. - runCameraUpdate(game, game->cameras, cameraId); - - // Render onto texture. - BeginTextureMode(gameScreen->zoomViewTexture); - ClearBackground(BLACK); - - BeginMode3D(game->cameras[cameraId]); - drawWorld(&game->world, game); - EndMode3D(); - - EndTextureMode(); - - // Draw texture. - DrawTexturePro( - gameScreen->zoomViewTexture.texture, - (Rectangle){0.0, 0.0, GAME_SCREEN_ZOOM_VIEW_SIZE, -GAME_SCREEN_ZOOM_VIEW_SIZE}, - (Rectangle){ - gameScreen->zoomViewPosition.x, - gameScreen->zoomViewPosition.y, - GAME_SCREEN_ZOOM_VIEW_UI_SIZE, - GAME_SCREEN_ZOOM_VIEW_UI_SIZE, - }, - (Vector2){0.0, 0.0}, - 0.0, - WHITE - ); - - // Draw cross hair. - if (cameraId == ZOOM_CAMERA) { - float halfSize = GAME_SCREEN_ZOOM_VIEW_UI_SIZE / 2.0; - Vector2 crossHairPosition = Vector2Add(gameScreen->zoomViewPosition, (Vector2){halfSize, halfSize}); - - Entity * player = getEntityFromWorld(game->world, 0); - AntifaShip * data = (AntifaShip*)player->data; - Color color = data->isOnTarget ? RED : BLUE; - - drawCrossHairPosition(crossHairPosition, 4.0, 2.0, color); - } - - // Draw outline. - DrawRectangleLines( - gameScreen->zoomViewPosition.x, - gameScreen->zoomViewPosition.y, - GAME_SCREEN_ZOOM_VIEW_UI_SIZE, - GAME_SCREEN_ZOOM_VIEW_UI_SIZE, - GREEN - ); -} - -void drawGameOverGameScreen(Game * game, GameScreen * gameScreen) { - float width = GetScreenWidth(); - float height = GetScreenHeight(); - - const char gameOverMsg[] = "Game Over"; - - Vector2 position = (Vector2){ - width / 2.0 - ((sizeof(gameOverMsg) + 1) * (GAME_SCREEN_GAME_OVER_FONT_SIZE / 2.0) / 2.0), - height / 3.0 - }; - - DrawText(gameOverMsg, position.x, position.y, GAME_SCREEN_GAME_OVER_FONT_SIZE, GREEN); -} - -void resetGame(Game * game, GameScreen * gameScreen) { - gameScreen->gameOver = false; - gameScreen->lastLevel = 0; - gameScreen->levelComplete = false; - gameScreen->gameComplete = false; - resetKillLog(&game->killLog); - - startLevel(game, &game->levels, 0); -} - -bool handleGameOver(Game * game, GameScreen * gameScreen) { - Entity * player = getEntityFromWorld(game->world, 0); - - // Already game over. - if (gameScreen->gameOver) { - - // To main after after so much time. - if (GetTime() - gameScreen->gameOverAt >= GAME_SCREEN_SHOW_GAME_OVER_FOR || IsKeyPressed(KEY_SPACE)) { - closeGameScreen(game); - game->screenId = SCREEN_MAIN_MENU; - resetGame(game, gameScreen); - } - - return true; - } - - // Check if there is player. - if (!gameScreen->levelComplete) { - if (player == NULL) - gameScreen->gameOver = true; - else if (player->health <= 0.0) - gameScreen->gameOver = true; - } - - // End game ): - if (gameScreen->gameOver) { - gameScreen->gameOverAt = GetTime(); - endLevel(game, &game->levels); - } - - return gameScreen->gameOver; -} - -void handleGameComplete(Game * game, GameScreen * gameScreen) { - float width = GetScreenWidth(); - float height = GetScreenHeight(); - - const char gameCompleteMsg[] = "Game Complete"; - - // Game over message. - Vector2 position = (Vector2){ - width / 2.0 - ((sizeof(gameCompleteMsg) + 1) * (GAME_SCREEN_GAME_COMPLETE_FONT_SIZE / 2.0) / 2.0), - height / 3.0 - }; - - DrawText(gameCompleteMsg, position.x, position.y, GAME_SCREEN_GAME_COMPLETE_FONT_SIZE, GREEN); - - // Funny little shitty message. - const char funnyLittleMsg[] = "I guess you don't completely suck at this game lmao"; - - position = (Vector2){ - width / 2.0 - ((sizeof(funnyLittleMsg) + 1) * (GAME_SCREEN_TEXT_SIZE / 2.0) / 2.0), - height / 3.0 + GAME_SCREEN_GAME_COMPLETE_FONT_SIZE + 10 - }; - - DrawText(funnyLittleMsg, position.x, position.y, GAME_SCREEN_TEXT_SIZE, GREEN); - - // End game. - if (GetTime() - gameScreen->gameCompleteAt >= GAME_SCREEN_GAME_COMPLETE_SHOW_FOR || IsKeyPressed(KEY_SPACE)) { - closeGameScreen(game); - game->screenId = SCREEN_MAIN_MENU; - resetGame(game, gameScreen); - } -} - -void updateGameScreen(Game * game) { - GameScreen * gameScreen = &game->gameScreen; - - handleGameScreenInput(game, gameScreen); - - ClearBackground(BLACK); - - // Game over ): - if (handleGameOver(game, gameScreen)) { - drawGameOverGameScreen(game, gameScreen); - return; - } - - // Game complete stuff. - if (gameScreen->gameComplete) { - handleGameComplete(game, gameScreen); - return; - } - - // Levels indeed. - gameScreenHandleLevels(game, gameScreen); - - if (gameScreen->levelComplete) - return; - - // Update world. - updateWorld(&game->world, game); - - // Camera. - runCameraUpdate(game, game->cameras, gameScreen->mainCamera); - - // Draw world. - if (gameScreen->usingWorldRenderTexture) { - BeginTextureMode(gameScreen->worldRender); - ClearBackground(BLACK); - renderWorldGameScreen(game, gameScreen); - EndTextureMode(); - - DrawTexturePro( - gameScreen->worldRender.texture, - (Rectangle){0.0, 0.0, game->settings.renderWidth, -game->settings.renderHeight}, - (Rectangle){0.0, 0.0, GetScreenWidth(), GetScreenHeight()}, - (Vector2){0.0, 0.0}, - 0.0, - WHITE - ); - } else { - renderWorldGameScreen(game, gameScreen); - } - - drawZoomViewGameScreen(game, gameScreen); - - // GUI. - drawGameScreenGui(game); -} - -void resizeGameScreen(Game * game, GameScreen * gameScreen) { - initGameScreenGui(gameScreen); -} - -void openGameScreen(Game * game) { - game->screenId = SCREEN_GAME; - - if (game->settings.lockMouse) - DisableCursor(); -} - -void closeGameScreen(Game * game) { - if (game->settings.lockMouse) - EnableCursor(); -} - -// You may think are minds are empty and we lack soul. Have you ever thought that was just a way to cover up what you have to hide? -// While to you I seemed a bit weird to me you were not even human. To me you were just a copy paste child with the same -// fake nice act that I know the teacher told you to put on only around me. It doesn't matter if you put on the fake little nice act or -// was a straight up bully because you were still a complete asshole. I could have watched the most terrible things happen to you and I would have just -// stood there and not done anything about it even if I had the power to stop it. The teachers at school put a lot of shit -// into teaching me and others like me how to put on a little mask so we could exist around people like you. -// Why do I need to be trained to act in a acceptable way just to even exist around you while you were saying and doing -// your stupid little shit. I was being put down by all the adults for doing something close to as shitty as the -// things you did daily. Now you see yourself as a decent person and might even think you support people like me. -// The truth is your hands are covered with blood and the layer of blood only gets thicker every day. -// FUCK YOU!!! diff --git a/src/gameScreen.h b/src/gameScreen.h deleted file mode 100644 index d2b058d..0000000 --- a/src/gameScreen.h +++ /dev/null @@ -1,69 +0,0 @@ -#include "gameCommon.h" -#include "gyroscope.h" -#include "radar.h" -#include "cameras.h" -#include "stars.h" - -#ifndef GAME_SCREEN_H -#define GAME_SCREEN_H - -#define GAME_SCREEN_TEXT_SIZE 20.0 -#define GAME_SCREEN_NEXT_LEVEL_DELAY 4.0 -#define GAME_SCREEN_TARGET_INFO_MAX 20 - -#define GAME_SCREEN_ZOOM_VIEW_SIZE 100 // Size it renders at. -#define GAME_SCREEN_ZOOM_VIEW_UI_SIZE 350 // Size on screen. - -#define GAME_SCREEN_SKY_BOX_SIZE 1020.0 - -#define GAME_SCREEN_SHOW_GAME_OVER_FOR 4.0 -#define GAME_SCREEN_GAME_OVER_FONT_SIZE 100 - -#define GAME_SCREEN_GAME_COMPLETE_SHOW_FOR 6.0 -#define GAME_SCREEN_GAME_COMPLETE_FONT_SIZE 100 - -// Gui stuff and shit. -typedef struct GameScreen { - Vector2 infoTextPosition; - Vector2 targetInfoPosition; - Vector2 killLogPosition; - - Gyroscope gyroscope; - Radar radar; - CameraId mainCamera; - - bool levelComplete; - double timeAtLevelComplete; - int lastLevel; - int nextLevelInsultNum; - - // Since the player entity gets reallocated each level we use this to remember its health. - float healthAtLevelEnd; - - bool gameOver; - double gameOverAt; - - bool gameComplete; - double gameCompleteAt; - - RenderTexture zoomViewTexture; - Vector2 zoomViewPosition; - - RenderTexture worldRender; - bool usingWorldRenderTexture; - - Stars stars; -} GameScreen; - -void initGameScreen(Game * game, GameScreen * gameScreen); -void freeGameScreen(GameScreen * gameScreen); - -void updateGameScreen(Game * game); -void resizeGameScreen(Game * game, GameScreen * gameScreen); - -void openGameScreen(Game * game); - -// Call before setting screen when in game screen -void closeGameScreen(Game * game); - -#endif diff --git a/src/howToPlayScreen.c b/src/howToPlayScreen.c deleted file mode 100644 index 8c31c20..0000000 --- a/src/howToPlayScreen.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "howToPlayScreen.h" -#include "game.h" - -void initHowToPlayScreen(Game * game) { - HowToPlayScreen * howToPlayScreen = &game->howToPlayScreen; - - howToPlayScreen->goBackButton = (Rectangle){0.0, 25.0, 100.0, 50.0}; - howToPlayScreen->infoText = (Rectangle){0.0, 0.0, 0.0, 0.0}; - - resizeHowToPlayScreen(game, howToPlayScreen); -} - -void updateHowToPlayScreen(Game * game) { - HowToPlayScreen * howToPlayScreen = &game->howToPlayScreen; - - ClearBackground(RAYWHITE); - - // Back to main menu button. - bool backPressed = GuiButton(howToPlayScreen->goBackButton, "back"); - - if (backPressed) - game->screenId = SCREEN_MAIN_MENU; - - // Info text. - const char info[] = - "Game play:\n" - " Kill fascist space ships and move on (:\n" - "Controls:\n" - " Sorry no wasd ):\n" - " Mouse to look around normally\n" - " Middle click with mouse movement to rotate\n" - " Scroll wheel to change the ship speed\n" - " Shift to slow down the mouse and scroll wheel\n" - " Ctrl to speed up the moues and scroll wheel\n" - " Number key to change the camera view\n" - " Left click to shoot\n" - " Right click to auto target\n" - "Using auto target:\n" - " Hitting things is hard so use the auto target pleaz (:\n" - " It will auto target on anything that is in range\n" - " Auto target will stop if you are out of range\n" - " The color will change from blue to red when you can kill\n" - " For some types of color blindness use the \"On Target\" instead\n" - " Try to manually aim to help the auto target"; - - DrawText(info, howToPlayScreen->infoText.x + 3, howToPlayScreen->infoText.y + 3, 20, BLACK); - DrawRectangleLinesEx(howToPlayScreen->infoText, 2, BLUE); -} - -void resizeHowToPlayScreen(Game * game, HowToPlayScreen * howToPlayScreen) { - int width = GetScreenWidth(); - int height = GetScreenHeight(); - - howToPlayScreen->infoText.width = width / 1.5; - howToPlayScreen->infoText.height = height / 1.5; - howToPlayScreen->infoText.x = (width / 2.0) - (howToPlayScreen->infoText.width / 2.0); - howToPlayScreen->infoText.y = (height / 2.0) - (howToPlayScreen->infoText.height / 2.0); -} diff --git a/src/howToPlayScreen.h b/src/howToPlayScreen.h deleted file mode 100644 index ff083e3..0000000 --- a/src/howToPlayScreen.h +++ /dev/null @@ -1,15 +0,0 @@ -#include "gameCommon.h" - -#ifndef HOW_TO_PLAY_SCREEN_H -#define HOW_TO_PLAY_SCREEN_H - -typedef struct HowToPlayScreen { - Rectangle goBackButton; - Rectangle infoText; -} HowToPlayScreen; - -void initHowToPlayScreen(Game * game); -void updateHowToPlayScreen(Game * game); -void resizeHowToPlayScreen(Game * game, HowToPlayScreen * howToPlayScreen); - -#endif diff --git a/src/mainMenu.c b/src/mainMenu.c deleted file mode 100644 index 8cc2b09..0000000 --- a/src/mainMenu.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "mainMenu.h" -#include "game.h" -#include "gameScreen.h" - -void initMainMenu(Game * game) { - game->mainMenu = (MainMenu){ - .startButton = (Rectangle){0.0, 0.0, 100.0, 50.0}, - .howToPlayButton = (Rectangle){0.0, 0.0, 100.0, 50.0}, - .logoTexture = &game->assets.textures[ICON128_ASSET] - }; - - resizeMainMenu(game, &game->mainMenu); -} - -void updateMainMenu(Game * game) { - MainMenu * mainMenu = &game->mainMenu; - ClearBackground(RAYWHITE); - - // Logo. - DrawTextureV( - *mainMenu->logoTexture, - mainMenu->logoPosition, - WHITE - ); - - // Start button. - bool start = GuiButton(mainMenu->startButton, "Start"); - - if (start) - openGameScreen(game); - - // How to play button. - bool clickedHowToPlay = GuiButton(mainMenu->howToPlayButton, "How to play"); - - if (clickedHowToPlay) - game->screenId= HOW_TO_PLAY_SCREEN; -} - -void resizeMainMenu(Game * game, MainMenu * mainMenu) { - // Logo. - mainMenu->logoPosition = (Vector2){ - (GetScreenWidth() / 2.0) - (mainMenu->logoTexture->width / 2.0), - (GetScreenHeight() / 2.0) - (mainMenu->logoTexture->height * 1.50) - }; - - // Start button. - mainMenu->startButton.x = (GetScreenWidth() / 2.0) - (mainMenu->startButton.width / 2.0); - mainMenu->startButton.y = (GetScreenHeight() / 2.0) - (mainMenu->startButton.height / 2.0); - - // How to play button. - mainMenu->howToPlayButton.x = (GetScreenWidth() / 2.0) - (mainMenu->startButton.width / 2.0); - mainMenu->howToPlayButton.y = (GetScreenHeight() / 2.0) - (mainMenu->startButton.height / 2.0); - mainMenu->howToPlayButton.y += mainMenu->startButton.height; -} diff --git a/src/mainMenu.h b/src/mainMenu.h deleted file mode 100644 index c8bae78..0000000 --- a/src/mainMenu.h +++ /dev/null @@ -1,18 +0,0 @@ -#include "gameCommon.h" - -#ifndef MAIN_MENU_H -#define MAIN_MENU_H - -typedef struct MainMenu { - Vector2 logoPosition; - Texture2D * logoTexture; - - Rectangle startButton; - Rectangle howToPlayButton; -} MainMenu; - -void initMainMenu(Game * game); -void updateMainMenu(Game * game); -void resizeMainMenu(Game * game, MainMenu * mainMenu); - -#endif diff --git a/src/screens/gameScreen.c b/src/screens/gameScreen.c new file mode 100644 index 0000000..de650c5 --- /dev/null +++ b/src/screens/gameScreen.c @@ -0,0 +1,545 @@ +#include "gameScreen.h" +#include "game.h" +#include "world.h" +#include "entity.h" +#include "bullets.h" +#include "assets.h" +#include "killLog.h" +#include "entitiesInclude.h" + +#define NEXT_LEVEL_INSULTS_COUNT 4 + +const char * nextLevelInsults[NEXT_LEVEL_INSULTS_COUNT] = { + "You suck at this game", + "Your the living enbodiment of a skill issue", + "Your grandma could do better then that", + "Go touch grass" +}; + +void initGameScreenGui(GameScreen * gameScreen) { + float width = GetScreenWidth(); + float height = GetScreenHeight(); + + // It is kind of terrible but works. + gameScreen->infoTextPosition = (Vector2){0.0, height / 1.5}; + + gameScreen->targetInfoPosition = (Vector2){ + width - (GAME_SCREEN_TEXT_SIZE * (GAME_SCREEN_TARGET_INFO_MAX / 2.0)), + height - RADAR_TEXTURE_SIZE - (GAME_SCREEN_TEXT_SIZE * 4.0) + }; + + gameScreen->zoomViewPosition = (Vector2){width - GAME_SCREEN_ZOOM_VIEW_UI_SIZE - 20.0, 10.0}; + + gameScreen->killLogPosition = (Vector2){0.0, 40.0}; + + resetRadarPosition(&gameScreen->radar); + resetGyroscopePosition(&gameScreen->gyroscope); +} + +void initGameScreen(Game * game, GameScreen * gameScreen) { + + // World render. + if (game->settings.useWorldRenderTexture) { + gameScreen->worldRender = LoadRenderTexture(game->settings.renderWidth, game->settings.renderHeight); + gameScreen->usingWorldRenderTexture = true; + } else { + gameScreen->usingWorldRenderTexture = false; + } + + // Zoom view. + gameScreen->zoomViewTexture = LoadRenderTexture(GAME_SCREEN_ZOOM_VIEW_SIZE, GAME_SCREEN_ZOOM_VIEW_SIZE); + + gameScreen->gameOver = false; + gameScreen->mainCamera = THIRD_PERSON_CAMERA; + gameScreen->levelComplete = false; + gameScreen->healthAtLevelEnd = ENTITY_MAX_HEALTH; + gameScreen->nextLevelInsultNum = 0; + gameScreen->gameComplete = false; + + // Gyroscope indeed + initGyroscope(&gameScreen->gyroscope); + + // Radar indeed. + initRadar(&gameScreen->radar); + + initStars(&gameScreen->stars); + + initGameScreenGui(gameScreen); +} + +void freeGameScreen(GameScreen * gameScreen) { + closeGyroscope(&gameScreen->gyroscope); + closeRadar(&gameScreen->radar); + + if (gameScreen->usingWorldRenderTexture) + UnloadRenderTexture(gameScreen->worldRender); + + UnloadRenderTexture(gameScreen->zoomViewTexture); +} + +void drawCrossHairPosition(Vector2 position, float size, float thick, Color color) { + // Left to right. + DrawLineEx( + (Vector2){position.x - size, position.y}, + (Vector2){position.x + size, position.y}, + thick, + color + ); + + // Top to bottom. + DrawLineEx( + (Vector2){position.x, position.y - size}, + (Vector2){position.x, position.y + size}, + thick, + color + ); +} + +void drawCrossHair(float size, float thick, Color color) { + Vector2 center = (Vector2){GetScreenWidth() / 2.0, GetScreenHeight() / 2.0}; + drawCrossHairPosition(center, size, thick, color); +} + +void drawGameScreenInfoText(Game * game, GameScreen * gameScreen) { + Entity * player = getEntityFromWorld(game->world, 0); + AntifaShip * data = (AntifaShip*)player->data; + + // Hello reader. I fucking hate you! + size_t bufSize = 255; + char buf[bufSize]; + + // Format text. + snprintf( + buf, + bufSize, + "Health %.2f\n\nX %.2f\nY %.2f\nZ %.2f\n\nSpeed %.2f/%.2f", + player->health, + player->position.x, + player->position.y, + player->position.z, + data->forwardSpeed, + Vector3Length(player->velocity.velocity) + ); + + // Draw info text. + DrawText( + buf, + gameScreen->infoTextPosition.x, + gameScreen->infoTextPosition.y, + GAME_SCREEN_TEXT_SIZE, + GREEN + ); +} + +void drawGameScreenTargetInfo(Game * game, GameScreen * gameScreen) { + Entity * player = getEntityFromWorld(game->world, 0); + AntifaShip * data = (AntifaShip*)player->data; + + size_t bufSize = 255; + char buf[bufSize]; + + // Format. + snprintf( + buf, + bufSize, + "Auto: %s", + data->doAutoTarget ? "On" : "Off" + ); + + // Is auto targeting. + if (data->doAutoTarget) { + Entity * targetedEntity = getEntityFromWorld(game->world, data->targetedEntityId); + + if (targetedEntity != NULL) { + char bufCopy[bufSize]; + strncpy(bufCopy, buf, bufSize); + + // Add more formatted text. + snprintf( + buf, + bufSize, + "%s\nId: %d@%x\nDistance: %.2f\nOn Target: %s", + bufCopy, + data->targetedEntityId, + data->targetedEntityFingerprint, + Vector3Distance(player->position, targetedEntity->position), + data->isOnTarget ? "Yes" : "No" + ); + } + } + + // Draw. + DrawText( + buf, + gameScreen->targetInfoPosition.x, + gameScreen->targetInfoPosition.y, + GAME_SCREEN_TEXT_SIZE, + GREEN + ); +} + +void drawGameScreenGui(Game * game) { + GameScreen * gameScreen = &game->gameScreen; + + // Draw cross hair. + if (gameScreen->mainCamera == FIRST_PERSON_CAMERA || gameScreen->mainCamera == ZOOM_CAMERA) { + // Get color depending if on target or not. + Entity * player = getEntityFromWorld(game->world, 0); + AntifaShip * data = (AntifaShip*)player->data; + Color color = data->isOnTarget ? RED : BLUE; + + drawCrossHair(10.0, 2.0, color); + } + + drawKillLog(&game->killLog, gameScreen->killLogPosition); + drawGameScreenInfoText(game, gameScreen); + drawGameScreenTargetInfo(game, gameScreen); + drawGyroscope(game, &gameScreen->gyroscope); + drawRadar(game, &gameScreen->radar); +} + +void handleGameScreenInput(Game * game, GameScreen * gameScreen) { + switch(GetKeyPressed()) { + case KEY_ONE: + gameScreen->mainCamera = FIRST_PERSON_CAMERA; + break; + case KEY_TWO: + gameScreen->mainCamera = THIRD_PERSON_CAMERA; + break; + case KEY_THREE: + gameScreen->mainCamera = ZOOM_CAMERA; + break; + // case KEY_FOUR: + // gameScreen->mainCamera = DEBUG_CAMERA; + // break; + default: + break; + } +} + +void drawNextLevelScreen(Game * game, GameScreen * gameScreen) { + float width = GetScreenWidth(); + float height = GetScreenHeight(); + + size_t bufSize = 100; + char buf[bufSize]; + + // Complete message. + snprintf( + buf, + bufSize, + "Level %d complete", + gameScreen->lastLevel + 1 + ); + + DrawText( + buf, + (width / 2.0) - (50.0 * strnlen(buf, bufSize) / 4.0), + height / 3.0, + 50, + GREEN + ); + + // Draw insult. + const char * insult = nextLevelInsults[gameScreen->nextLevelInsultNum]; + + DrawText( + insult, + (width / 2.0) - (GAME_SCREEN_TEXT_SIZE * strlen(insult) / 4.0), + height / 3.0 + 70.0, + GAME_SCREEN_TEXT_SIZE, + GREEN + ); +} + +void callThisFuckerAtGameComplete(Game * game, GameScreen * gameScreen) { + gameScreen->gameComplete = true; + gameScreen->gameCompleteAt = GetTime(); +} + +void gameScreenHandleLevels(Game * game, GameScreen * gameScreen) { + // Show complete screen if level complete. + if (gameScreen->levelComplete) { + drawNextLevelScreen(game, gameScreen); + + // Next fucking level. + if (GetTime() - gameScreen->timeAtLevelComplete >= GAME_SCREEN_NEXT_LEVEL_DELAY || IsKeyPressed(KEY_SPACE)) { + gameScreen->levelComplete = false; + startLevel(game, &game->levels, gameScreen->lastLevel + 1); + getEntityFromWorld(game->world, 0)->health = Clamp(gameScreen->healthAtLevelEnd * 1.5, 0.0, 1.0); + } + + return; + } + + bool complete = updateLevel(game, &game->levels); + + // This fucker been completed. + if (complete) { + gameScreen->lastLevel = game->levels.currentLevel; + gameScreen->healthAtLevelEnd = getEntityFromWorld(game->world, 0)->health; + + // Game is complete lol. + if (game->levels.currentLevel == GAME_LEVELS_COMPLETE_AT) + callThisFuckerAtGameComplete(game, gameScreen); + + endLevel(game, &game->levels); + + gameScreen->levelComplete = true; + gameScreen->timeAtLevelComplete = GetTime(); + + SetRandomSeed(time(NULL)); + gameScreen->nextLevelInsultNum = GetRandomValue(0, NEXT_LEVEL_INSULTS_COUNT - 1); + } +} + +void drawGameScreenStars(Game * game, GameScreen * gameScreen) { + DrawModel( + game->assets.models[SKY_ASSET], + getEntityFromWorld(game->world, 0)->position, + GAME_SCREEN_SKY_BOX_SIZE, + WHITE + ); + + drawStars(game, &gameScreen->stars); +} + +void renderWorldGameScreen(Game * game, GameScreen * gameScreen) { + BeginMode3D(game->cameras[gameScreen->mainCamera]); + + drawGameScreenStars(game, gameScreen); + + // Draw world. + drawWorld(&game->world, game); + + EndMode3D(); +} + +void drawZoomViewGameScreen(Game * game, GameScreen * gameScreen) { + CameraId cameraId = ZOOM_CAMERA; + + if (gameScreen->mainCamera == ZOOM_CAMERA) + cameraId = THIRD_PERSON_CAMERA; + + // Update camera. + runCameraUpdate(game, game->cameras, cameraId); + + // Render onto texture. + BeginTextureMode(gameScreen->zoomViewTexture); + ClearBackground(BLACK); + + BeginMode3D(game->cameras[cameraId]); + drawWorld(&game->world, game); + EndMode3D(); + + EndTextureMode(); + + // Draw texture. + DrawTexturePro( + gameScreen->zoomViewTexture.texture, + (Rectangle){0.0, 0.0, GAME_SCREEN_ZOOM_VIEW_SIZE, -GAME_SCREEN_ZOOM_VIEW_SIZE}, + (Rectangle){ + gameScreen->zoomViewPosition.x, + gameScreen->zoomViewPosition.y, + GAME_SCREEN_ZOOM_VIEW_UI_SIZE, + GAME_SCREEN_ZOOM_VIEW_UI_SIZE, + }, + (Vector2){0.0, 0.0}, + 0.0, + WHITE + ); + + // Draw cross hair. + if (cameraId == ZOOM_CAMERA) { + float halfSize = GAME_SCREEN_ZOOM_VIEW_UI_SIZE / 2.0; + Vector2 crossHairPosition = Vector2Add(gameScreen->zoomViewPosition, (Vector2){halfSize, halfSize}); + + Entity * player = getEntityFromWorld(game->world, 0); + AntifaShip * data = (AntifaShip*)player->data; + Color color = data->isOnTarget ? RED : BLUE; + + drawCrossHairPosition(crossHairPosition, 4.0, 2.0, color); + } + + // Draw outline. + DrawRectangleLines( + gameScreen->zoomViewPosition.x, + gameScreen->zoomViewPosition.y, + GAME_SCREEN_ZOOM_VIEW_UI_SIZE, + GAME_SCREEN_ZOOM_VIEW_UI_SIZE, + GREEN + ); +} + +void drawGameOverGameScreen(Game * game, GameScreen * gameScreen) { + float width = GetScreenWidth(); + float height = GetScreenHeight(); + + const char gameOverMsg[] = "Game Over"; + + Vector2 position = (Vector2){ + width / 2.0 - ((sizeof(gameOverMsg) + 1) * (GAME_SCREEN_GAME_OVER_FONT_SIZE / 2.0) / 2.0), + height / 3.0 + }; + + DrawText(gameOverMsg, position.x, position.y, GAME_SCREEN_GAME_OVER_FONT_SIZE, GREEN); +} + +void resetGame(Game * game, GameScreen * gameScreen) { + gameScreen->gameOver = false; + gameScreen->lastLevel = 0; + gameScreen->levelComplete = false; + gameScreen->gameComplete = false; + resetKillLog(&game->killLog); + + startLevel(game, &game->levels, 0); +} + +bool handleGameOver(Game * game, GameScreen * gameScreen) { + Entity * player = getEntityFromWorld(game->world, 0); + + // Already game over. + if (gameScreen->gameOver) { + + // To main after after so much time. + if (GetTime() - gameScreen->gameOverAt >= GAME_SCREEN_SHOW_GAME_OVER_FOR || IsKeyPressed(KEY_SPACE)) { + closeGameScreen(game); + game->screenId = SCREEN_MAIN_MENU; + resetGame(game, gameScreen); + } + + return true; + } + + // Check if there is player. + if (!gameScreen->levelComplete) { + if (player == NULL) + gameScreen->gameOver = true; + else if (player->health <= 0.0) + gameScreen->gameOver = true; + } + + // End game ): + if (gameScreen->gameOver) { + gameScreen->gameOverAt = GetTime(); + endLevel(game, &game->levels); + } + + return gameScreen->gameOver; +} + +void handleGameComplete(Game * game, GameScreen * gameScreen) { + float width = GetScreenWidth(); + float height = GetScreenHeight(); + + const char gameCompleteMsg[] = "Game Complete"; + + // Game over message. + Vector2 position = (Vector2){ + width / 2.0 - ((sizeof(gameCompleteMsg) + 1) * (GAME_SCREEN_GAME_COMPLETE_FONT_SIZE / 2.0) / 2.0), + height / 3.0 + }; + + DrawText(gameCompleteMsg, position.x, position.y, GAME_SCREEN_GAME_COMPLETE_FONT_SIZE, GREEN); + + // Funny little shitty message. + const char funnyLittleMsg[] = "I guess you don't completely suck at this game lmao"; + + position = (Vector2){ + width / 2.0 - ((sizeof(funnyLittleMsg) + 1) * (GAME_SCREEN_TEXT_SIZE / 2.0) / 2.0), + height / 3.0 + GAME_SCREEN_GAME_COMPLETE_FONT_SIZE + 10 + }; + + DrawText(funnyLittleMsg, position.x, position.y, GAME_SCREEN_TEXT_SIZE, GREEN); + + // End game. + if (GetTime() - gameScreen->gameCompleteAt >= GAME_SCREEN_GAME_COMPLETE_SHOW_FOR || IsKeyPressed(KEY_SPACE)) { + closeGameScreen(game); + game->screenId = SCREEN_MAIN_MENU; + resetGame(game, gameScreen); + } +} + +void updateGameScreen(Game * game) { + GameScreen * gameScreen = &game->gameScreen; + + handleGameScreenInput(game, gameScreen); + + ClearBackground(BLACK); + + // Game over ): + if (handleGameOver(game, gameScreen)) { + drawGameOverGameScreen(game, gameScreen); + return; + } + + // Game complete stuff. + if (gameScreen->gameComplete) { + handleGameComplete(game, gameScreen); + return; + } + + // Levels indeed. + gameScreenHandleLevels(game, gameScreen); + + if (gameScreen->levelComplete) + return; + + // Update world. + updateWorld(&game->world, game); + + // Camera. + runCameraUpdate(game, game->cameras, gameScreen->mainCamera); + + // Draw world. + if (gameScreen->usingWorldRenderTexture) { + BeginTextureMode(gameScreen->worldRender); + ClearBackground(BLACK); + renderWorldGameScreen(game, gameScreen); + EndTextureMode(); + + DrawTexturePro( + gameScreen->worldRender.texture, + (Rectangle){0.0, 0.0, game->settings.renderWidth, -game->settings.renderHeight}, + (Rectangle){0.0, 0.0, GetScreenWidth(), GetScreenHeight()}, + (Vector2){0.0, 0.0}, + 0.0, + WHITE + ); + } else { + renderWorldGameScreen(game, gameScreen); + } + + drawZoomViewGameScreen(game, gameScreen); + + // GUI. + drawGameScreenGui(game); +} + +void resizeGameScreen(Game * game, GameScreen * gameScreen) { + initGameScreenGui(gameScreen); +} + +void openGameScreen(Game * game) { + game->screenId = SCREEN_GAME; + + if (game->settings.lockMouse) + DisableCursor(); +} + +void closeGameScreen(Game * game) { + if (game->settings.lockMouse) + EnableCursor(); +} + +// You may think are minds are empty and we lack soul. Have you ever thought that was just a way to cover up what you have to hide? +// While to you I seemed a bit weird to me you were not even human. To me you were just a copy paste child with the same +// fake nice act that I know the teacher told you to put on only around me. It doesn't matter if you put on the fake little nice act or +// was a straight up bully because you were still a complete asshole. I could have watched the most terrible things happen to you and I would have just +// stood there and not done anything about it even if I had the power to stop it. The teachers at school put a lot of shit +// into teaching me and others like me how to put on a little mask so we could exist around people like you. +// Why do I need to be trained to act in a acceptable way just to even exist around you while you were saying and doing +// your stupid little shit. I was being put down by all the adults for doing something close to as shitty as the +// things you did daily. Now you see yourself as a decent person and might even think you support people like me. +// The truth is your hands are covered with blood and the layer of blood only gets thicker every day. +// FUCK YOU!!! diff --git a/src/screens/gameScreen.h b/src/screens/gameScreen.h new file mode 100644 index 0000000..d2b058d --- /dev/null +++ b/src/screens/gameScreen.h @@ -0,0 +1,69 @@ +#include "gameCommon.h" +#include "gyroscope.h" +#include "radar.h" +#include "cameras.h" +#include "stars.h" + +#ifndef GAME_SCREEN_H +#define GAME_SCREEN_H + +#define GAME_SCREEN_TEXT_SIZE 20.0 +#define GAME_SCREEN_NEXT_LEVEL_DELAY 4.0 +#define GAME_SCREEN_TARGET_INFO_MAX 20 + +#define GAME_SCREEN_ZOOM_VIEW_SIZE 100 // Size it renders at. +#define GAME_SCREEN_ZOOM_VIEW_UI_SIZE 350 // Size on screen. + +#define GAME_SCREEN_SKY_BOX_SIZE 1020.0 + +#define GAME_SCREEN_SHOW_GAME_OVER_FOR 4.0 +#define GAME_SCREEN_GAME_OVER_FONT_SIZE 100 + +#define GAME_SCREEN_GAME_COMPLETE_SHOW_FOR 6.0 +#define GAME_SCREEN_GAME_COMPLETE_FONT_SIZE 100 + +// Gui stuff and shit. +typedef struct GameScreen { + Vector2 infoTextPosition; + Vector2 targetInfoPosition; + Vector2 killLogPosition; + + Gyroscope gyroscope; + Radar radar; + CameraId mainCamera; + + bool levelComplete; + double timeAtLevelComplete; + int lastLevel; + int nextLevelInsultNum; + + // Since the player entity gets reallocated each level we use this to remember its health. + float healthAtLevelEnd; + + bool gameOver; + double gameOverAt; + + bool gameComplete; + double gameCompleteAt; + + RenderTexture zoomViewTexture; + Vector2 zoomViewPosition; + + RenderTexture worldRender; + bool usingWorldRenderTexture; + + Stars stars; +} GameScreen; + +void initGameScreen(Game * game, GameScreen * gameScreen); +void freeGameScreen(GameScreen * gameScreen); + +void updateGameScreen(Game * game); +void resizeGameScreen(Game * game, GameScreen * gameScreen); + +void openGameScreen(Game * game); + +// Call before setting screen when in game screen +void closeGameScreen(Game * game); + +#endif diff --git a/src/screens/howToPlayScreen.c b/src/screens/howToPlayScreen.c new file mode 100644 index 0000000..8c31c20 --- /dev/null +++ b/src/screens/howToPlayScreen.c @@ -0,0 +1,58 @@ +#include "howToPlayScreen.h" +#include "game.h" + +void initHowToPlayScreen(Game * game) { + HowToPlayScreen * howToPlayScreen = &game->howToPlayScreen; + + howToPlayScreen->goBackButton = (Rectangle){0.0, 25.0, 100.0, 50.0}; + howToPlayScreen->infoText = (Rectangle){0.0, 0.0, 0.0, 0.0}; + + resizeHowToPlayScreen(game, howToPlayScreen); +} + +void updateHowToPlayScreen(Game * game) { + HowToPlayScreen * howToPlayScreen = &game->howToPlayScreen; + + ClearBackground(RAYWHITE); + + // Back to main menu button. + bool backPressed = GuiButton(howToPlayScreen->goBackButton, "back"); + + if (backPressed) + game->screenId = SCREEN_MAIN_MENU; + + // Info text. + const char info[] = + "Game play:\n" + " Kill fascist space ships and move on (:\n" + "Controls:\n" + " Sorry no wasd ):\n" + " Mouse to look around normally\n" + " Middle click with mouse movement to rotate\n" + " Scroll wheel to change the ship speed\n" + " Shift to slow down the mouse and scroll wheel\n" + " Ctrl to speed up the moues and scroll wheel\n" + " Number key to change the camera view\n" + " Left click to shoot\n" + " Right click to auto target\n" + "Using auto target:\n" + " Hitting things is hard so use the auto target pleaz (:\n" + " It will auto target on anything that is in range\n" + " Auto target will stop if you are out of range\n" + " The color will change from blue to red when you can kill\n" + " For some types of color blindness use the \"On Target\" instead\n" + " Try to manually aim to help the auto target"; + + DrawText(info, howToPlayScreen->infoText.x + 3, howToPlayScreen->infoText.y + 3, 20, BLACK); + DrawRectangleLinesEx(howToPlayScreen->infoText, 2, BLUE); +} + +void resizeHowToPlayScreen(Game * game, HowToPlayScreen * howToPlayScreen) { + int width = GetScreenWidth(); + int height = GetScreenHeight(); + + howToPlayScreen->infoText.width = width / 1.5; + howToPlayScreen->infoText.height = height / 1.5; + howToPlayScreen->infoText.x = (width / 2.0) - (howToPlayScreen->infoText.width / 2.0); + howToPlayScreen->infoText.y = (height / 2.0) - (howToPlayScreen->infoText.height / 2.0); +} diff --git a/src/screens/howToPlayScreen.h b/src/screens/howToPlayScreen.h new file mode 100644 index 0000000..ff083e3 --- /dev/null +++ b/src/screens/howToPlayScreen.h @@ -0,0 +1,15 @@ +#include "gameCommon.h" + +#ifndef HOW_TO_PLAY_SCREEN_H +#define HOW_TO_PLAY_SCREEN_H + +typedef struct HowToPlayScreen { + Rectangle goBackButton; + Rectangle infoText; +} HowToPlayScreen; + +void initHowToPlayScreen(Game * game); +void updateHowToPlayScreen(Game * game); +void resizeHowToPlayScreen(Game * game, HowToPlayScreen * howToPlayScreen); + +#endif diff --git a/src/screens/mainMenu.c b/src/screens/mainMenu.c new file mode 100644 index 0000000..8cc2b09 --- /dev/null +++ b/src/screens/mainMenu.c @@ -0,0 +1,54 @@ +#include "mainMenu.h" +#include "game.h" +#include "gameScreen.h" + +void initMainMenu(Game * game) { + game->mainMenu = (MainMenu){ + .startButton = (Rectangle){0.0, 0.0, 100.0, 50.0}, + .howToPlayButton = (Rectangle){0.0, 0.0, 100.0, 50.0}, + .logoTexture = &game->assets.textures[ICON128_ASSET] + }; + + resizeMainMenu(game, &game->mainMenu); +} + +void updateMainMenu(Game * game) { + MainMenu * mainMenu = &game->mainMenu; + ClearBackground(RAYWHITE); + + // Logo. + DrawTextureV( + *mainMenu->logoTexture, + mainMenu->logoPosition, + WHITE + ); + + // Start button. + bool start = GuiButton(mainMenu->startButton, "Start"); + + if (start) + openGameScreen(game); + + // How to play button. + bool clickedHowToPlay = GuiButton(mainMenu->howToPlayButton, "How to play"); + + if (clickedHowToPlay) + game->screenId= HOW_TO_PLAY_SCREEN; +} + +void resizeMainMenu(Game * game, MainMenu * mainMenu) { + // Logo. + mainMenu->logoPosition = (Vector2){ + (GetScreenWidth() / 2.0) - (mainMenu->logoTexture->width / 2.0), + (GetScreenHeight() / 2.0) - (mainMenu->logoTexture->height * 1.50) + }; + + // Start button. + mainMenu->startButton.x = (GetScreenWidth() / 2.0) - (mainMenu->startButton.width / 2.0); + mainMenu->startButton.y = (GetScreenHeight() / 2.0) - (mainMenu->startButton.height / 2.0); + + // How to play button. + mainMenu->howToPlayButton.x = (GetScreenWidth() / 2.0) - (mainMenu->startButton.width / 2.0); + mainMenu->howToPlayButton.y = (GetScreenHeight() / 2.0) - (mainMenu->startButton.height / 2.0); + mainMenu->howToPlayButton.y += mainMenu->startButton.height; +} diff --git a/src/screens/mainMenu.h b/src/screens/mainMenu.h new file mode 100644 index 0000000..c8bae78 --- /dev/null +++ b/src/screens/mainMenu.h @@ -0,0 +1,18 @@ +#include "gameCommon.h" + +#ifndef MAIN_MENU_H +#define MAIN_MENU_H + +typedef struct MainMenu { + Vector2 logoPosition; + Texture2D * logoTexture; + + Rectangle startButton; + Rectangle howToPlayButton; +} MainMenu; + +void initMainMenu(Game * game); +void updateMainMenu(Game * game); +void resizeMainMenu(Game * game, MainMenu * mainMenu); + +#endif -- cgit v1.2.3