raylib/templates/standard_game/standard_game.c
Ahmad Fatoum 2c219fb814
Allow use of main instead of android_main
Inspired by #504.
Instead of requiring the user to do PLATFORM_ANDROID #ifdefery,
have the android_main entry point exported by raylib and call
the user-defined main. This way many games could (in theory)
run unmodified on Android and elsewhere.

This is untested!
2018-03-16 21:37:22 +01:00

144 lines
4.7 KiB
C

/*******************************************************************************************
*
* raylib - Standard Game template
*
* <Game title>
* <Game description>
*
* This game has been created using raylib (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
#include "screens/screens.h" // NOTE: Defines global variable: currentScreen
//----------------------------------------------------------------------------------
// Main entry point
//----------------------------------------------------------------------------------
int main(void)
{
// Initialization (Note windowTitle is unused on Android)
//---------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib template - standard game");
// TODO: Load global data here (assets that must be available in all screens, i.e. fonts)
// Define and init first screen
currentScreen = LOGO; // NOTE: currentScreen is defined in screens.h as a global variable
InitLogoScreen();
SetTargetFPS(60);
//----------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
switch(currentScreen)
{
case LOGO:
{
UpdateLogoScreen();
if (FinishLogoScreen())
{
UnloadLogoScreen();
currentScreen = TITLE;
InitTitleScreen();
}
} break;
case TITLE:
{
UpdateTitleScreen();
// NOTE: FinishTitleScreen() return an int defining the screen to jump to
if (FinishTitleScreen() == 1)
{
UnloadTitleScreen();
currentScreen = OPTIONS;
InitOptionsScreen();
}
else if (FinishTitleScreen() == 2)
{
UnloadTitleScreen();
currentScreen = GAMEPLAY;
InitGameplayScreen();
}
} break;
case OPTIONS:
{
UpdateOptionsScreen();
if (FinishOptionsScreen())
{
UnloadOptionsScreen();
currentScreen = TITLE;
InitTitleScreen();
}
} break;
case GAMEPLAY:
{
UpdateGameplayScreen();
if (FinishGameplayScreen())
{
UnloadGameplayScreen();
currentScreen = ENDING;
InitEndingScreen();
}
} break;
case ENDING:
{
UpdateEndingScreen();
if (FinishEndingScreen())
{
UnloadEndingScreen();
currentScreen = TITLE;
InitTitleScreen();
}
} break;
default: break;
}
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
switch(currentScreen)
{
case LOGO: DrawLogoScreen(); break;
case TITLE: DrawTitleScreen(); break;
case OPTIONS: DrawOptionsScreen(); break;
case GAMEPLAY: DrawGameplayScreen(); break;
case ENDING: DrawEndingScreen(); break;
default: break;
}
//DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
// TODO: Unload all global loaded data (i.e. fonts) here!
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}