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.

271 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. //SetConfigFlags(FLAG_FULLSCREEN_MODE);
  46. // Note that windowTitle is ignored on Android
  47. InitWindow(screenWidth, screenHeight, windowTitle);
  48. // Load global data here (assets that must be available in all screens, i.e. fonts)
  49. font = LoadFont("resources/graphics/mainfont.png");
  50. atlas01 = LoadTexture("resources/graphics/atlas01.png");
  51. atlas02 = LoadTexture("resources/graphics/atlas02.png");
  52. #if defined(PLATFORM_WEB) || defined(PLATFORM_RPI) || defined(PLATFORM_ANDROID)
  53. colorBlend = LoadShader("resources/shaders/glsl100/base.vs", "resources/shaders/glsl100/blend_color.fs");
  54. #else
  55. colorBlend = LoadShader("resources/shaders/glsl330/base.vs", "resources/shaders/glsl330/blend_color.fs");
  56. #endif
  57. InitAudioDevice();
  58. // Load sounds data
  59. fxJump = LoadSound("resources/audio/jump.ogg");
  60. fxDash = LoadSound("resources/audio/dash.ogg");
  61. fxEatLeaves = LoadSound("resources/audio/eat_leaves.ogg");
  62. fxHitResin = LoadSound("resources/audio/resin_hit.ogg");
  63. fxWind = LoadSound("resources/audio/wind_sound.ogg");
  64. fxDieSnake = LoadSound("resources/audio/snake_die.ogg");
  65. fxDieDingo = LoadSound("resources/audio/dingo_die.ogg");
  66. fxDieOwl = LoadSound("resources/audio/owl_die.ogg");
  67. music = LoadMusicStream("resources/audio/jngl.xm");
  68. PlayMusicStream(music);
  69. SetMusicVolume(music, 1.0f);
  70. // Define and init first screen
  71. // NOTE: currentScreen is defined in screens.h as a global variable
  72. currentScreen = TITLE;
  73. InitLogoScreen();
  74. //InitOptionsScreen();
  75. InitTitleScreen();
  76. InitGameplayScreen();
  77. InitEndingScreen();
  78. #if defined(PLATFORM_WEB)
  79. emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
  80. #else
  81. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  82. //--------------------------------------------------------------------------------------
  83. // Main game loop
  84. while (!WindowShouldClose()) UpdateDrawFrame();
  85. #endif
  86. // De-Initialization
  87. //--------------------------------------------------------------------------------------
  88. UnloadEndingScreen();
  89. UnloadTitleScreen();
  90. UnloadGameplayScreen();
  91. UnloadLogoScreen();
  92. UnloadTexture(atlas01);
  93. UnloadTexture(atlas02);
  94. UnloadFont(font);
  95. UnloadShader(colorBlend); // Unload color overlay blending shader
  96. UnloadSound(fxJump);
  97. UnloadSound(fxDash);
  98. UnloadSound(fxEatLeaves);
  99. UnloadSound(fxHitResin);
  100. UnloadSound(fxWind);
  101. UnloadSound(fxDieSnake);
  102. UnloadSound(fxDieDingo);
  103. UnloadSound(fxDieOwl);
  104. UnloadMusicStream(music);
  105. CloseAudioDevice(); // Close audio device
  106. CloseWindow(); // Close window and OpenGL context
  107. //--------------------------------------------------------------------------------------
  108. return 0;
  109. }
  110. void TransitionToScreen(int screen)
  111. {
  112. onTransition = true;
  113. transFromScreen = currentScreen;
  114. transToScreen = screen;
  115. }
  116. void UpdateTransition(void)
  117. {
  118. if (!transFadeOut)
  119. {
  120. transAlpha += 0.05f;
  121. if (transAlpha >= 1.0)
  122. {
  123. transAlpha = 1.0;
  124. currentScreen = transToScreen;
  125. transFadeOut = true;
  126. framesCounter = 0;
  127. }
  128. }
  129. else // Transition fade out logic
  130. {
  131. transAlpha -= 0.05f;
  132. if (transAlpha <= 0)
  133. {
  134. transAlpha = 0;
  135. transFadeOut = false;
  136. onTransition = false;
  137. transFromScreen = -1;
  138. transToScreen = -1;
  139. }
  140. }
  141. }
  142. void DrawTransition(void)
  143. {
  144. DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(BLACK, transAlpha));
  145. }
  146. // Update and Draw one frame
  147. void UpdateDrawFrame(void)
  148. {
  149. // Update
  150. //----------------------------------------------------------------------------------
  151. if (!onTransition)
  152. {
  153. switch (currentScreen)
  154. {
  155. case LOGO:
  156. {
  157. UpdateLogoScreen();
  158. if (FinishLogoScreen()) TransitionToScreen(TITLE);
  159. } break;
  160. case TITLE:
  161. {
  162. UpdateTitleScreen();
  163. // NOTE: FinishTitleScreen() return an int defining the screen to jump to
  164. if (FinishTitleScreen() == 1)
  165. {
  166. UnloadTitleScreen();
  167. //currentScreen = OPTIONS;
  168. //InitOptionsScreen();
  169. }
  170. else if (FinishTitleScreen() == 2)
  171. {
  172. UnloadTitleScreen();
  173. InitGameplayScreen();
  174. TransitionToScreen(GAMEPLAY);
  175. }
  176. } break;
  177. case GAMEPLAY:
  178. {
  179. UpdateGameplayScreen();
  180. if (FinishGameplayScreen())
  181. {
  182. UnloadGameplayScreen();
  183. InitEndingScreen();
  184. TransitionToScreen(ENDING);
  185. }
  186. } break;
  187. case ENDING:
  188. {
  189. UpdateEndingScreen();
  190. if (FinishEndingScreen())
  191. {
  192. UnloadEndingScreen();
  193. InitGameplayScreen();
  194. TransitionToScreen(GAMEPLAY);
  195. }
  196. } break;
  197. default: break;
  198. }
  199. }
  200. else UpdateTransition();
  201. UpdateMusicStream(music);
  202. //----------------------------------------------------------------------------------
  203. // Draw
  204. //----------------------------------------------------------------------------------
  205. BeginDrawing();
  206. ClearBackground(WHITE);
  207. switch (currentScreen)
  208. {
  209. case LOGO: DrawLogoScreen(); break;
  210. case TITLE: DrawTitleScreen(); break;
  211. case GAMEPLAY: DrawGameplayScreen(); break;
  212. case ENDING: DrawEndingScreen(); break;
  213. default: break;
  214. }
  215. if (onTransition) DrawTransition();
  216. DrawFPS(20, GetScreenHeight() - 30);
  217. DrawRectangle(GetScreenWidth() - 200, GetScreenHeight() - 50, 200, 40, Fade(WHITE, 0.6f));
  218. DrawText("ALPHA VERSION", GetScreenWidth() - 180, GetScreenHeight() - 40, 20, DARKGRAY);
  219. EndDrawing();
  220. //----------------------------------------------------------------------------------
  221. }