raylib/templates/standard_game/standard_game.c
raysan5 1ef1f3d7ea Multiple templates to start a game
Some basic to advance templates are provided to be use as base code for
new games
2014-09-18 19:00:30 +02: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)
*
* raylib - Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
*
********************************************************************************************/
#include "raylib.h"
#include "screens/screens.h" // NOTE: Defines currentScreen
//----------------------------------------------------------------------------------
// Main entry point
//----------------------------------------------------------------------------------
int main(void)
{
// Initialization
//---------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
const char windowTitle[30] = "<game name goes here>";
InitWindow(screenWidth, screenHeight, windowTitle);
// 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;
}