2022-05-24 00:19:55 +00:00
|
|
|
/*
|
2022-05-29 16:02:30 +00:00
|
|
|
- Avoid ~ a game by Canneddonuts
|
2022-05-24 00:19:55 +00:00
|
|
|
- Filename ~ Main.c
|
|
|
|
- Author ~ Return0ne
|
|
|
|
- 2022
|
|
|
|
- *no license*
|
|
|
|
*/
|
2022-05-29 16:02:30 +00:00
|
|
|
|
2022-04-14 19:20:18 +00:00
|
|
|
#include "../include/raylib.h"
|
|
|
|
|
2022-06-12 17:49:42 +00:00
|
|
|
#include "Screens.h"
|
2022-06-11 20:10:58 +00:00
|
|
|
#include "Controls.h"
|
|
|
|
|
2022-06-12 17:49:42 +00:00
|
|
|
|
2022-03-30 00:29:19 +00:00
|
|
|
#if defined(PLATFORM_WEB)
|
|
|
|
#include <emscripten/emscripten.h>
|
|
|
|
#endif
|
|
|
|
|
2022-03-27 20:40:15 +00:00
|
|
|
// screen variables
|
|
|
|
static const int screenWidth = 800;
|
|
|
|
static const int screenHeight = 450;
|
|
|
|
|
2022-06-12 17:49:42 +00:00
|
|
|
GameScreen currentScreen = 0;
|
2022-03-27 20:40:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Game functions
|
2022-04-30 16:06:03 +00:00
|
|
|
static void gameSetup(void);
|
|
|
|
static void updateGame(void);
|
|
|
|
static void drawGame(void);
|
|
|
|
static void gameLoop(void);
|
|
|
|
static void unloadGame(void);
|
2022-03-27 20:40:15 +00:00
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
InitWindow(screenWidth, screenHeight, "Avoid");
|
|
|
|
|
|
|
|
InitAudioDevice();
|
|
|
|
|
2022-04-30 16:06:03 +00:00
|
|
|
gameSetup();
|
2022-03-27 20:40:15 +00:00
|
|
|
|
2022-03-30 00:29:19 +00:00
|
|
|
#if defined(PLATFORM_WEB)
|
2022-05-19 00:31:20 +00:00
|
|
|
emscripten_set_main_loop(gameLoop, 60, 1);
|
2022-03-30 00:29:19 +00:00
|
|
|
#else
|
2022-05-17 23:03:22 +00:00
|
|
|
SetTargetFPS(60);
|
2022-03-30 00:29:19 +00:00
|
|
|
|
2022-05-17 23:03:22 +00:00
|
|
|
while (!WindowShouldClose()) gameLoop();
|
2022-03-30 00:29:19 +00:00
|
|
|
#endif
|
2022-03-27 20:40:15 +00:00
|
|
|
|
2022-04-30 16:06:03 +00:00
|
|
|
unloadGame();
|
2022-03-27 20:40:15 +00:00
|
|
|
|
2022-06-11 20:10:58 +00:00
|
|
|
CloseAudioDevice();
|
|
|
|
|
2022-03-27 20:40:15 +00:00
|
|
|
CloseWindow();
|
|
|
|
|
2022-03-30 00:29:19 +00:00
|
|
|
return 0;
|
2022-03-27 20:40:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 16:06:03 +00:00
|
|
|
void gameSetup(void)
|
2022-03-27 20:40:15 +00:00
|
|
|
{
|
2022-04-30 16:06:03 +00:00
|
|
|
// asset loading & setting of variable values
|
2022-03-27 20:40:15 +00:00
|
|
|
currentScreen = TITLE;
|
|
|
|
|
2022-06-12 17:49:42 +00:00
|
|
|
InitGameplayScreen();
|
2022-03-27 20:40:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 16:06:03 +00:00
|
|
|
void updateGame(void)
|
2022-03-27 20:40:15 +00:00
|
|
|
{
|
2022-04-30 16:06:03 +00:00
|
|
|
// code that runs as long as the program is running
|
2022-04-13 19:33:00 +00:00
|
|
|
if ((IsKeyDown(KEY_LEFT_ALT)) && (IsKeyPressed(KEY_F))) ToggleFullscreen();
|
2022-03-27 20:40:15 +00:00
|
|
|
|
|
|
|
switch(currentScreen) {
|
2022-06-12 17:49:42 +00:00
|
|
|
case TITLE: UpdateTitleScreen(); break;
|
|
|
|
case GAMEPLAY: UpdateGameplayScreen(); break;
|
|
|
|
case GAMEOVER: UpdateGameoverScreen(); break;
|
|
|
|
case CREDITS: UpdateCreditsScreen(); break;
|
|
|
|
default: break;
|
2022-03-27 20:40:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-30 16:06:03 +00:00
|
|
|
void drawGame(void)
|
2022-03-27 20:40:15 +00:00
|
|
|
{
|
2022-04-30 16:06:03 +00:00
|
|
|
// code to render the game to the game window
|
2022-03-27 20:40:15 +00:00
|
|
|
BeginDrawing();
|
|
|
|
|
|
|
|
ClearBackground(RAYWHITE);
|
|
|
|
|
|
|
|
switch(currentScreen) {
|
2022-06-12 17:49:42 +00:00
|
|
|
case TITLE: DrawTitleScreen(); break;
|
|
|
|
case GAMEPLAY: DrawGameplayScreen(); break;
|
|
|
|
case GAMEOVER: DrawGameoverScreen(); break;
|
|
|
|
case CREDITS: DrawCreditsScreen(); break;
|
2022-03-27 20:40:15 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
EndDrawing();
|
|
|
|
}
|
|
|
|
|
2022-04-30 16:06:03 +00:00
|
|
|
void gameLoop(void)
|
2022-03-27 20:40:15 +00:00
|
|
|
{
|
2022-04-30 16:06:03 +00:00
|
|
|
updateGame();
|
|
|
|
drawGame();
|
2022-03-27 20:40:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 16:06:03 +00:00
|
|
|
void unloadGame(void)
|
2022-03-27 20:40:15 +00:00
|
|
|
{
|
2022-06-12 17:49:42 +00:00
|
|
|
UnloadGameplayScreen();
|
2022-03-27 20:40:15 +00:00
|
|
|
}
|