You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

272 lines
8.2 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib - Koala Seasons game
  4. *
  5. * Koala Seasons is a runner, you must survive as long as possible jumping from tree to tree
  6. * Ready to start the adventure? How long can you survive?
  7. *
  8. * This game has been created using raylib 1.5 (www.raylib.com)
  9. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  10. *
  11. * Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
  12. *
  13. ********************************************************************************************/
  14. #include "raylib.h"
  15. #include "screens/screens.h" // NOTE: Defines currentScreen
  16. #if defined(PLATFORM_WEB)
  17. #include <emscripten/emscripten.h>
  18. #endif
  19. //----------------------------------------------------------------------------------
  20. // Global Variables Definition (local to this module)
  21. //----------------------------------------------------------------------------------
  22. static float transAlpha = 0;
  23. static bool onTransition = false;
  24. static bool transFadeOut = false;
  25. static int transFromScreen = -1;
  26. static int transToScreen = -1;
  27. static int framesCounter = 0;
  28. static Music music;
  29. //----------------------------------------------------------------------------------
  30. // Local Functions Declaration
  31. //----------------------------------------------------------------------------------
  32. void TransitionToScreen(int screen);
  33. void UpdateTransition(void);
  34. void DrawTransition(void);
  35. void UpdateDrawFrame(void); // Update and Draw one frame
  36. //----------------------------------------------------------------------------------
  37. // Main entry point
  38. //----------------------------------------------------------------------------------
  39. int main(void) {
  40. // Initialization
  41. //---------------------------------------------------------
  42. const int screenWidth = 1280;
  43. const int screenHeight = 720;
  44. const char windowTitle[30] = "KOALA SEASONS";
  45. //ShowLogo();
  46. //SetConfigFlags(FLAG_FULLSCREEN_MODE);
  47. // Note that windowTitle is ignored on Android
  48. InitWindow(screenWidth, screenHeight, windowTitle);
  49. // Load global data here (assets that must be available in all screens, i.e. fonts)
  50. font = LoadFont("resources/graphics/mainfont.png");
  51. atlas01 = LoadTexture("resources/graphics/atlas01.png");
  52. atlas02 = LoadTexture("resources/graphics/atlas02.png");
  53. #if defined(PLATFORM_WEB) || defined(PLATFORM_RPI) || defined(PLATFORM_ANDROID)
  54. colorBlend = LoadShader("resources/shaders/glsl100/base.vs", "resources/shaders/glsl100/blend_color.fs");
  55. #else
  56. colorBlend = LoadShader("resources/shaders/glsl330/base.vs", "resources/shaders/glsl330/blend_color.fs");
  57. #endif
  58. InitAudioDevice();
  59. // Load sounds data
  60. fxJump = LoadSound("resources/audio/jump.ogg");
  61. fxDash = LoadSound("resources/audio/dash.ogg");
  62. fxEatLeaves = LoadSound("resources/audio/eat_leaves.ogg");
  63. fxHitResin = LoadSound("resources/audio/resin_hit.ogg");
  64. fxWind = LoadSound("resources/audio/wind_sound.ogg");
  65. fxDieSnake = LoadSound("resources/audio/snake_die.ogg");
  66. fxDieDingo = LoadSound("resources/audio/dingo_die.ogg");
  67. fxDieOwl = LoadSound("resources/audio/owl_die.ogg");
  68. music = LoadMusicStream("resources/audio/jngl.xm");
  69. PlayMusicStream(music);
  70. SetMusicVolume(music, 1.0f);
  71. // Define and init first screen
  72. // NOTE: currentScreen is defined in screens.h as a global variable
  73. currentScreen = TITLE;
  74. InitLogoScreen();
  75. //InitOptionsScreen();
  76. InitTitleScreen();
  77. InitGameplayScreen();
  78. InitEndingScreen();
  79. #if defined(PLATFORM_WEB)
  80. emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
  81. #else
  82. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  83. //--------------------------------------------------------------------------------------
  84. // Main game loop
  85. while (!WindowShouldClose()) UpdateDrawFrame();
  86. #endif
  87. // De-Initialization
  88. //--------------------------------------------------------------------------------------
  89. UnloadEndingScreen();
  90. UnloadTitleScreen();
  91. UnloadGameplayScreen();
  92. UnloadLogoScreen();
  93. UnloadTexture(atlas01);
  94. UnloadTexture(atlas02);
  95. UnloadFont(font);
  96. UnloadShader(colorBlend); // Unload color overlay blending shader
  97. UnloadSound(fxJump);
  98. UnloadSound(fxDash);
  99. UnloadSound(fxEatLeaves);
  100. UnloadSound(fxHitResin);
  101. UnloadSound(fxWind);
  102. UnloadSound(fxDieSnake);
  103. UnloadSound(fxDieDingo);
  104. UnloadSound(fxDieOwl);
  105. UnloadMusicStream(music);
  106. CloseAudioDevice(); // Close audio device
  107. CloseWindow(); // Close window and OpenGL context
  108. //--------------------------------------------------------------------------------------
  109. return 0;
  110. }
  111. void TransitionToScreen(int screen)
  112. {
  113. onTransition = true;
  114. transFromScreen = currentScreen;
  115. transToScreen = screen;
  116. }
  117. void UpdateTransition(void)
  118. {
  119. if (!transFadeOut)
  120. {
  121. transAlpha += 0.05f;
  122. if (transAlpha >= 1.0)
  123. {
  124. transAlpha = 1.0;
  125. currentScreen = transToScreen;
  126. transFadeOut = true;
  127. framesCounter = 0;
  128. }
  129. }
  130. else // Transition fade out logic
  131. {
  132. transAlpha -= 0.05f;
  133. if (transAlpha <= 0)
  134. {
  135. transAlpha = 0;
  136. transFadeOut = false;
  137. onTransition = false;
  138. transFromScreen = -1;
  139. transToScreen = -1;
  140. }
  141. }
  142. }
  143. void DrawTransition(void)
  144. {
  145. DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(BLACK, transAlpha));
  146. }
  147. // Update and Draw one frame
  148. void UpdateDrawFrame(void)
  149. {
  150. // Update
  151. //----------------------------------------------------------------------------------
  152. if (!onTransition)
  153. {
  154. switch (currentScreen)
  155. {
  156. case LOGO:
  157. {
  158. UpdateLogoScreen();
  159. if (FinishLogoScreen()) TransitionToScreen(TITLE);
  160. } break;
  161. case TITLE:
  162. {
  163. UpdateTitleScreen();
  164. // NOTE: FinishTitleScreen() return an int defining the screen to jump to
  165. if (FinishTitleScreen() == 1)
  166. {
  167. UnloadTitleScreen();
  168. //currentScreen = OPTIONS;
  169. //InitOptionsScreen();
  170. }
  171. else if (FinishTitleScreen() == 2)
  172. {
  173. UnloadTitleScreen();
  174. InitGameplayScreen();
  175. TransitionToScreen(GAMEPLAY);
  176. }
  177. } break;
  178. case GAMEPLAY:
  179. {
  180. UpdateGameplayScreen();
  181. if (FinishGameplayScreen())
  182. {
  183. UnloadGameplayScreen();
  184. InitEndingScreen();
  185. TransitionToScreen(ENDING);
  186. }
  187. } break;
  188. case ENDING:
  189. {
  190. UpdateEndingScreen();
  191. if (FinishEndingScreen())
  192. {
  193. UnloadEndingScreen();
  194. InitGameplayScreen();
  195. TransitionToScreen(GAMEPLAY);
  196. }
  197. } break;
  198. default: break;
  199. }
  200. }
  201. else UpdateTransition();
  202. UpdateMusicStream(music);
  203. //----------------------------------------------------------------------------------
  204. // Draw
  205. //----------------------------------------------------------------------------------
  206. BeginDrawing();
  207. ClearBackground(WHITE);
  208. switch (currentScreen)
  209. {
  210. case LOGO: DrawLogoScreen(); break;
  211. case TITLE: DrawTitleScreen(); break;
  212. case GAMEPLAY: DrawGameplayScreen(); break;
  213. case ENDING: DrawEndingScreen(); break;
  214. default: break;
  215. }
  216. if (onTransition) DrawTransition();
  217. DrawFPS(20, GetScreenHeight() - 30);
  218. DrawRectangle(GetScreenWidth() - 200, GetScreenHeight() - 50, 200, 40, Fade(WHITE, 0.6f));
  219. DrawText("ALPHA VERSION", GetScreenWidth() - 180, GetScreenHeight() - 40, 20, DARKGRAY);
  220. EndDrawing();
  221. //----------------------------------------------------------------------------------
  222. }