Avoid/src/Main.c

108 lines
1.9 KiB
C
Raw Normal View History

/*
2022-05-29 16:02:30 +00:00
- Avoid ~ a game by Canneddonuts
- Filename ~ Main.c
- Author ~ Return0ne
- 2022
- *no license*
*/
2022-05-29 16:02:30 +00:00
#include "../include/raylib.h"
#include "Screens.h"
2022-06-11 20:10:58 +00:00
#include "Controls.h"
#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;
GameScreen currentScreen = 0;
2022-03-27 20:40:15 +00:00
// Game functions
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();
gameSetup();
2022-03-27 20:40:15 +00:00
#if defined(PLATFORM_WEB)
2022-05-19 00:31:20 +00:00
emscripten_set_main_loop(gameLoop, 60, 1);
#else
SetTargetFPS(60);
while (!WindowShouldClose()) gameLoop();
#endif
2022-03-27 20:40:15 +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();
return 0;
2022-03-27 20:40:15 +00:00
}
void gameSetup(void)
2022-03-27 20:40:15 +00:00
{
// asset loading & setting of variable values
2022-03-27 20:40:15 +00:00
currentScreen = TITLE;
InitGameplayScreen();
2022-03-27 20:40:15 +00:00
}
void updateGame(void)
2022-03-27 20:40:15 +00:00
{
// code that runs as long as the program is running
if ((IsKeyDown(KEY_LEFT_ALT)) && (IsKeyPressed(KEY_F))) ToggleFullscreen();
2022-03-27 20:40:15 +00:00
switch(currentScreen) {
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
}
}
void drawGame(void)
2022-03-27 20:40:15 +00:00
{
// code to render the game to the game window
2022-03-27 20:40:15 +00:00
BeginDrawing();
ClearBackground(RAYWHITE);
switch(currentScreen) {
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();
}
void gameLoop(void)
2022-03-27 20:40:15 +00:00
{
updateGame();
drawGame();
2022-03-27 20:40:15 +00:00
}
void unloadGame(void)
2022-03-27 20:40:15 +00:00
{
UnloadGameplayScreen();
2022-03-27 20:40:15 +00:00
}