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.

260 line
7.9 KiB

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