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.

408 lines
12 KiB

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