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.

406 lines
12 KiB

  1. /*******************************************************************************************
  2. *
  3. * SKULLY ESCAPE [KING GAME JAM 2015]
  4. *
  5. * This game has been created using raylib 1.6 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2014 Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. #include "screens/screens.h" // NOTE: Defines global variable: currentScreen
  13. #include "player.h"
  14. #if defined(PLATFORM_WEB)
  15. #include <emscripten/emscripten.h>
  16. #endif
  17. //----------------------------------------------------------------------------------
  18. // Global Variables Definition (local to this module)
  19. //----------------------------------------------------------------------------------
  20. const int screenWidth = 1280;
  21. const int screenHeight = 720;
  22. // Required variables to manage screen transitions (fade-in, fade-out)
  23. float transAlpha = 0;
  24. bool onTransition = false;
  25. bool transFadeOut = false;
  26. int transFromScreen = -1;
  27. int transToScreen = -1;
  28. static int framesCounter = 0;
  29. Music music;
  30. //----------------------------------------------------------------------------------
  31. // Local Functions Declaration
  32. //----------------------------------------------------------------------------------
  33. void TransitionToScreen(int screen);
  34. void ChangeToScreen(int screen); // No transition effect
  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, "SKULLY ESCAPE [KING GAMEJAM]");
  46. // Global data loading (assets that must be available in all screens, i.e. fonts)
  47. InitAudioDevice();
  48. music = LoadMusicStream("resources/audio/come_play_with_me.ogg");
  49. PlayMusicStream(music);
  50. font = LoadFont("resources/textures/alagard.png");
  51. doors = LoadTexture("resources/textures/doors.png");
  52. sndDoor = LoadSound("resources/audio/door.ogg");
  53. sndScream = LoadSound("resources/audio/scream.ogg");
  54. InitPlayer();
  55. // Setup and Init first screen
  56. currentScreen = LOGO;
  57. InitLogoScreen();
  58. #if defined(PLATFORM_WEB)
  59. emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
  60. #else
  61. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  62. //--------------------------------------------------------------------------------------
  63. // Main game loop
  64. while (!WindowShouldClose()) // Detect window close button or ESC key
  65. {
  66. UpdateDrawFrame();
  67. }
  68. #endif
  69. // De-Initialization
  70. //--------------------------------------------------------------------------------------
  71. // Unload all global loaded data (i.e. fonts) here!
  72. UnloadPlayer();
  73. UnloadFont(font);
  74. UnloadTexture(doors);
  75. UnloadSound(sndDoor);
  76. UnloadSound(sndScream);
  77. UnloadMusicStream(music);
  78. CloseAudioDevice();
  79. CloseWindow(); // Close window and OpenGL context
  80. //--------------------------------------------------------------------------------------
  81. return 0;
  82. }
  83. void TransitionToScreen(int screen)
  84. {
  85. onTransition = true;
  86. transFromScreen = currentScreen;
  87. transToScreen = screen;
  88. }
  89. void ChangeToScreen(int screen)
  90. {
  91. switch (currentScreen)
  92. {
  93. case LOGO: UnloadLogoScreen(); break;
  94. case LOGO_RL: rlUnloadLogoScreen(); break;
  95. case TITLE: UnloadTitleScreen(); break;
  96. case ATTIC: UnloadAtticScreen(); break;
  97. case AISLE01: UnloadAisle01Screen();break;
  98. case AISLE02: UnloadAisle02Screen();break;
  99. case ARMORY: UnloadArmoryScreen();break;
  100. case LIVINGROOM: UnloadLivingroomScreen();break;
  101. case KITCHEN: UnloadKitchenScreen(); break;
  102. case BATHROOM: UnloadBathroomScreen(); break;
  103. case ENDING: UnloadEndingScreen(); break;
  104. default: break;
  105. }
  106. switch (screen)
  107. {
  108. case LOGO: InitLogoScreen(); break;
  109. case LOGO_RL: rlInitLogoScreen(); break;
  110. case TITLE: InitTitleScreen(); break;
  111. case ATTIC: InitAtticScreen(); break;
  112. case AISLE01: InitAisle01Screen();break;
  113. case AISLE02: InitAisle02Screen();break;
  114. case ARMORY: InitArmoryScreen();break;
  115. case LIVINGROOM: InitLivingroomScreen();break;
  116. case KITCHEN: InitKitchenScreen(); break;
  117. case BATHROOM: InitBathroomScreen(); break;
  118. case ENDING: InitEndingScreen(); break;
  119. default: break;
  120. }
  121. currentScreen = screen;
  122. }
  123. void UpdateTransition(void)
  124. {
  125. if (!transFadeOut)
  126. {
  127. transAlpha += 0.05f;
  128. if (transAlpha >= 1.0)
  129. {
  130. transAlpha = 1.0;
  131. switch (transFromScreen)
  132. {
  133. case LOGO: UnloadLogoScreen(); break;
  134. case LOGO_RL: rlUnloadLogoScreen(); break;
  135. case TITLE: UnloadTitleScreen(); break;
  136. case ATTIC: UnloadAtticScreen(); break;
  137. case AISLE01: UnloadAisle01Screen();break;
  138. case AISLE02: UnloadAisle02Screen();break;
  139. case ARMORY: UnloadArmoryScreen();break;
  140. case LIVINGROOM: UnloadLivingroomScreen();break;
  141. case KITCHEN: UnloadKitchenScreen(); break;
  142. case BATHROOM: UnloadBathroomScreen(); break;
  143. case ENDING: UnloadEndingScreen(); break;
  144. default: break;
  145. }
  146. switch (transToScreen)
  147. {
  148. case LOGO:
  149. {
  150. InitLogoScreen();
  151. currentScreen = LOGO;
  152. } break;
  153. case LOGO_RL:
  154. {
  155. rlInitLogoScreen();
  156. currentScreen = LOGO_RL;
  157. } break;
  158. case TITLE:
  159. {
  160. InitTitleScreen();
  161. currentScreen = TITLE;
  162. } break;
  163. case ATTIC:
  164. {
  165. InitAtticScreen();
  166. currentScreen = ATTIC;
  167. } break;
  168. case AISLE01:
  169. {
  170. InitAisle01Screen();
  171. currentScreen = AISLE01;
  172. } break;
  173. case AISLE02:
  174. {
  175. InitAisle02Screen();
  176. currentScreen = AISLE02;
  177. } break;
  178. case BATHROOM:
  179. {
  180. InitBathroomScreen();
  181. currentScreen = BATHROOM;
  182. } break;
  183. case LIVINGROOM:
  184. {
  185. InitLivingroomScreen();
  186. currentScreen = LIVINGROOM;
  187. } break;
  188. case KITCHEN:
  189. {
  190. InitKitchenScreen();
  191. currentScreen = KITCHEN;
  192. } break;
  193. case ARMORY:
  194. {
  195. InitArmoryScreen();
  196. currentScreen = ARMORY;
  197. } break;
  198. case ENDING:
  199. {
  200. InitEndingScreen();
  201. currentScreen = ENDING;
  202. } break;
  203. default: break;
  204. }
  205. transFadeOut = true;
  206. }
  207. }
  208. else // Transition fade out logic
  209. {
  210. transAlpha -= 0.05f;
  211. if (transAlpha <= 0)
  212. {
  213. transAlpha = 0;
  214. transFadeOut = false;
  215. onTransition = false;
  216. transFromScreen = -1;
  217. transToScreen = -1;
  218. }
  219. }
  220. }
  221. void DrawTransition(void)
  222. {
  223. DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(BLACK, transAlpha));
  224. }
  225. // Update and draw game frame
  226. void UpdateDrawFrame(void)
  227. {
  228. // Update
  229. //----------------------------------------------------------------------------------
  230. if (!onTransition)
  231. {
  232. if (player.dead)
  233. {
  234. framesCounter++;
  235. if (framesCounter > 80)
  236. {
  237. framesCounter = 0;
  238. player.dead = false;
  239. player.numLifes = 4;
  240. TransitionToScreen(TITLE);
  241. }
  242. }
  243. switch(currentScreen)
  244. {
  245. case LOGO:
  246. {
  247. UpdateLogoScreen();
  248. if (FinishLogoScreen()) ChangeToScreen(LOGO_RL);
  249. } break;
  250. case LOGO_RL:
  251. {
  252. rlUpdateLogoScreen();
  253. if (rlFinishLogoScreen()) TransitionToScreen(TITLE);
  254. } break;
  255. case TITLE:
  256. {
  257. UpdateTitleScreen();
  258. if (FinishTitleScreen() == 1) TransitionToScreen(ATTIC);
  259. } break;
  260. case ATTIC:
  261. {
  262. UpdateAtticScreen();
  263. if (FinishAtticScreen() == 1) TransitionToScreen(AISLE01);
  264. } break;
  265. case AISLE01:
  266. {
  267. UpdateAisle01Screen();
  268. if (FinishAisle01Screen() == 1) TransitionToScreen(BATHROOM);
  269. else if(FinishAisle01Screen() == 2) TransitionToScreen(KITCHEN);
  270. else if(FinishAisle01Screen() == 3) TransitionToScreen(LIVINGROOM);
  271. } break;
  272. case BATHROOM:
  273. {
  274. UpdateBathroomScreen();
  275. if (FinishBathroomScreen() == 1) TransitionToScreen(AISLE01);
  276. } break;
  277. case LIVINGROOM:
  278. {
  279. UpdateLivingroomScreen();
  280. if (FinishLivingroomScreen() == 1) TransitionToScreen(AISLE01);
  281. else if(FinishLivingroomScreen() == 2)TransitionToScreen(AISLE02);
  282. } break;
  283. case AISLE02:
  284. {
  285. UpdateAisle02Screen();
  286. if (FinishAisle02Screen() == 1) TransitionToScreen(KITCHEN);
  287. } break;
  288. case KITCHEN:
  289. {
  290. UpdateKitchenScreen();
  291. if (FinishKitchenScreen() == 1) TransitionToScreen(ARMORY);
  292. else if(FinishKitchenScreen() == 2)TransitionToScreen(AISLE02);
  293. } break;
  294. case ARMORY:
  295. {
  296. UpdateArmoryScreen();
  297. if(FinishArmoryScreen() == 1) TransitionToScreen(ENDING);
  298. else if(FinishArmoryScreen() == 2) TransitionToScreen(KITCHEN);
  299. } break;
  300. case ENDING:
  301. {
  302. UpdateEndingScreen();
  303. if (FinishEndingScreen()) TransitionToScreen(TITLE);
  304. } break;
  305. default: break;
  306. }
  307. }
  308. else
  309. {
  310. // Update transition (fade-in, fade-out)
  311. UpdateTransition();
  312. }
  313. UpdateMusicStream(music);
  314. //----------------------------------------------------------------------------------
  315. // Draw
  316. //----------------------------------------------------------------------------------
  317. BeginDrawing();
  318. ClearBackground(RAYWHITE);
  319. switch(currentScreen)
  320. {
  321. case LOGO: DrawLogoScreen(); break;
  322. case LOGO_RL: rlDrawLogoScreen(); break;
  323. case TITLE: DrawTitleScreen(); break;
  324. case ATTIC: DrawAtticScreen(); break;
  325. case AISLE01: DrawAisle01Screen();break;
  326. case AISLE02: DrawAisle02Screen();break;
  327. case BATHROOM: DrawBathroomScreen();break;
  328. case LIVINGROOM: DrawLivingroomScreen();break;
  329. case KITCHEN: DrawKitchenScreen();break;
  330. case ARMORY: DrawArmoryScreen();break;
  331. case ENDING: DrawEndingScreen(); break;
  332. default: break;
  333. }
  334. if (onTransition) DrawTransition();
  335. //DrawFPS(10, 10);
  336. EndDrawing();
  337. //----------------------------------------------------------------------------------
  338. }