Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

356 строки
10 KiB

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