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.

360 lines
11 KiB

  1. /*******************************************************************************************
  2. *
  3. * JUST DO - Global Game Jam 2015 Videogame
  4. * Experimental puzzle game that lets the user try to find a logic solution to
  5. * different shape-color-based situations.
  6. *
  7. * Developed by: Ramon Santamaria (Ray San)
  8. *
  9. * This game has been created using raylib 1.6 (www.raylib.com)
  10. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  11. *
  12. * raylib - Copyright (c) 2015 Ramon Santamaria (@raysan5)
  13. *
  14. ********************************************************************************************/
  15. #include "raylib.h"
  16. #include "screens/screens.h" // NOTE: Defines currentScreen
  17. #if defined(PLATFORM_WEB)
  18. #include <emscripten/emscripten.h>
  19. #endif
  20. //----------------------------------------------------------------------------------
  21. // Global Variables Definition (local to this module)
  22. //----------------------------------------------------------------------------------
  23. const int screenWidth = 1280; // Moved to screens.h
  24. const int screenHeight = 720; // Moved to screens.h
  25. // Required variables to manage screen transitions (fade-in, fade-out)
  26. float transAlpha = 0;
  27. bool onTransition = false;
  28. bool transFadeOut = false;
  29. int transFromScreen = -1;
  30. int transToScreen = -1;
  31. int framesCounter = 0;
  32. //static Sound levelWin;
  33. Music music;
  34. //----------------------------------------------------------------------------------
  35. // Local Functions Declaration
  36. //----------------------------------------------------------------------------------
  37. void TransitionToScreen(int screen);
  38. void UpdateTransition(void);
  39. void DrawTransition(void);
  40. void UpdateDrawFrame(void); // Update and Draw one frame
  41. //----------------------------------------------------------------------------------
  42. // Main entry point
  43. //----------------------------------------------------------------------------------
  44. int main(void)
  45. {
  46. // Initialization (Note windowTitle is unused on Android)
  47. //---------------------------------------------------------
  48. InitWindow(screenWidth, screenHeight, "GGJ15 - JUST DO");
  49. // Load global data here (assets that must be available in all screens, i.e. fonts)
  50. InitAudioDevice();
  51. levelWin = LoadSound("resources/win.wav");
  52. music = LoadMusicStream("resources/ambient.ogg");
  53. // Setup and Init first screen
  54. currentScreen = LOGO;
  55. InitLogoScreen();
  56. #if defined(PLATFORM_WEB)
  57. emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
  58. #else
  59. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  60. //--------------------------------------------------------------------------------------
  61. // Main game loop
  62. while (!WindowShouldClose()) // Detect window close button or ESC key
  63. {
  64. if (IsKeyPressed(KEY_SPACE)) PlaySound(levelWin);
  65. UpdateDrawFrame();
  66. }
  67. #endif
  68. // De-Initialization
  69. //--------------------------------------------------------------------------------------
  70. // Unload all global loaded data (i.e. fonts) here!
  71. UnloadSound(levelWin);
  72. UnloadMusicStream(music);
  73. CloseAudioDevice();
  74. CloseWindow(); // Close window and OpenGL context
  75. //--------------------------------------------------------------------------------------
  76. return 0;
  77. }
  78. //----------------------------------------------------------------------------------
  79. // Local Functions Definition
  80. //----------------------------------------------------------------------------------
  81. void TransitionToScreen(int screen)
  82. {
  83. onTransition = true;
  84. transFromScreen = currentScreen;
  85. transToScreen = screen;
  86. }
  87. void UpdateTransition(void)
  88. {
  89. if (!transFadeOut)
  90. {
  91. transAlpha += 0.02f;
  92. if (transAlpha >= 1.0)
  93. {
  94. transAlpha = 1.0;
  95. currentScreen = transToScreen;
  96. transFadeOut = true;
  97. framesCounter = 0;
  98. }
  99. }
  100. else // Transition fade out logic
  101. {
  102. transAlpha -= 0.02f;
  103. if (transAlpha <= 0)
  104. {
  105. transAlpha = 0;
  106. transFadeOut = false;
  107. onTransition = false;
  108. transFromScreen = -1;
  109. transToScreen = -1;
  110. }
  111. }
  112. }
  113. void DrawTransition(void)
  114. {
  115. DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, transAlpha));
  116. }
  117. void UpdateDrawFrame(void)
  118. {
  119. // Update
  120. //----------------------------------------------------------------------------------
  121. if (!onTransition)
  122. {
  123. if (IsKeyPressed('0'))
  124. {
  125. TransitionToScreen(LEVEL00);
  126. InitLevel00Screen();
  127. }
  128. else if (IsKeyPressed('1'))
  129. {
  130. TransitionToScreen(LEVEL01);
  131. InitLevel01Screen();
  132. }
  133. else if (IsKeyPressed('2'))
  134. {
  135. TransitionToScreen(LEVEL02);
  136. InitLevel02Screen();
  137. }
  138. else if (IsKeyPressed('3'))
  139. {
  140. TransitionToScreen(LEVEL03);
  141. InitLevel03Screen();
  142. }
  143. else if (IsKeyPressed('4'))
  144. {
  145. TransitionToScreen(LEVEL04);
  146. InitLevel04Screen();
  147. }
  148. else if (IsKeyPressed('5'))
  149. {
  150. TransitionToScreen(LEVEL05);
  151. InitLevel05Screen();
  152. }
  153. else if (IsKeyPressed('6'))
  154. {
  155. TransitionToScreen(LEVEL06);
  156. InitLevel06Screen();
  157. }
  158. else if (IsKeyPressed('7'))
  159. {
  160. TransitionToScreen(LEVEL07);
  161. InitLevel07Screen();
  162. }
  163. else if (IsKeyPressed('8'))
  164. {
  165. TransitionToScreen(LEVEL08);
  166. InitLevel08Screen();
  167. }
  168. else if (IsKeyPressed('9'))
  169. {
  170. TransitionToScreen(LEVEL09);
  171. InitLevel08Screen();
  172. }
  173. UpdateMusicStream(music);
  174. switch(currentScreen)
  175. {
  176. case LOGO:
  177. {
  178. UpdateLogoScreen();
  179. if (FinishLogoScreen())
  180. {
  181. UnloadLogoScreen();
  182. TransitionToScreen(LEVEL00);
  183. InitLevel00Screen();
  184. PlayMusicStream(music);
  185. SetMusicVolume(music, 0.6f);
  186. }
  187. } break;
  188. case LEVEL00:
  189. {
  190. UpdateLevel00Screen();
  191. if (FinishLevel00Screen())
  192. {
  193. UnloadLevel00Screen();
  194. TransitionToScreen(LEVEL01);
  195. InitLevel01Screen();
  196. }
  197. } break;
  198. case LEVEL01:
  199. {
  200. UpdateLevel01Screen();
  201. if (FinishLevel01Screen())
  202. {
  203. UnloadLevel01Screen();
  204. TransitionToScreen(LEVEL02);
  205. InitLevel02Screen();
  206. }
  207. } break;
  208. case LEVEL02:
  209. {
  210. UpdateLevel02Screen();
  211. if (FinishLevel02Screen())
  212. {
  213. UnloadLevel02Screen();
  214. TransitionToScreen(LEVEL03);
  215. InitLevel03Screen();
  216. }
  217. } break;
  218. case LEVEL03:
  219. {
  220. UpdateLevel03Screen();
  221. if (FinishLevel03Screen())
  222. {
  223. UnloadLevel03Screen();
  224. TransitionToScreen(LEVEL04);
  225. InitLevel04Screen();
  226. }
  227. } break;
  228. case LEVEL04:
  229. {
  230. UpdateLevel04Screen();
  231. if (FinishLevel04Screen())
  232. {
  233. UnloadLevel04Screen();
  234. TransitionToScreen(LEVEL05);
  235. InitLevel05Screen();
  236. }
  237. } break;
  238. case LEVEL05:
  239. {
  240. UpdateLevel05Screen();
  241. if (FinishLevel05Screen())
  242. {
  243. UnloadLevel05Screen();
  244. TransitionToScreen(LEVEL06);
  245. InitLevel06Screen();
  246. }
  247. } break;
  248. case LEVEL06:
  249. {
  250. UpdateLevel06Screen();
  251. if (FinishLevel06Screen())
  252. {
  253. UnloadLevel06Screen();
  254. TransitionToScreen(LEVEL07);
  255. InitLevel07Screen();
  256. }
  257. } break;
  258. case LEVEL07:
  259. {
  260. UpdateLevel07Screen();
  261. if (FinishLevel07Screen())
  262. {
  263. UnloadLevel07Screen();
  264. TransitionToScreen(LEVEL08);
  265. InitLevel08Screen();
  266. }
  267. } break;
  268. case LEVEL08:
  269. {
  270. UpdateLevel08Screen();
  271. if (FinishLevel08Screen())
  272. {
  273. UnloadLevel08Screen();
  274. TransitionToScreen(LEVEL09);
  275. InitLevel09Screen();
  276. }
  277. } break;
  278. case LEVEL09:
  279. {
  280. UpdateLevel09Screen();
  281. if (FinishLevel09Screen())
  282. {
  283. UnloadLevel09Screen();
  284. TransitionToScreen(LEVEL00);
  285. InitLevel00Screen();
  286. }
  287. } break;
  288. default: break;
  289. }
  290. }
  291. else UpdateTransition(); // Update transition (fade-in, fade-out)
  292. //----------------------------------------------------------------------------------
  293. // Draw
  294. //----------------------------------------------------------------------------------
  295. BeginDrawing();
  296. ClearBackground(RAYWHITE);
  297. switch(currentScreen)
  298. {
  299. case LOGO: DrawLogoScreen(); break;
  300. case LEVEL00: DrawLevel00Screen(); break;
  301. case LEVEL01: DrawLevel01Screen(); break;
  302. case LEVEL02: DrawLevel02Screen(); break;
  303. case LEVEL03: DrawLevel03Screen(); break;
  304. case LEVEL04: DrawLevel04Screen(); break;
  305. case LEVEL05: DrawLevel05Screen(); break;
  306. case LEVEL06: DrawLevel06Screen(); break;
  307. case LEVEL07: DrawLevel07Screen(); break;
  308. case LEVEL08: DrawLevel08Screen(); break;
  309. case LEVEL09: DrawLevel09Screen(); break;
  310. default: break;
  311. }
  312. if (onTransition) DrawTransition();
  313. EndDrawing();
  314. //----------------------------------------------------------------------------------
  315. }