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.

211 line
6.3 KiB

  1. /**********************************************************************************************
  2. *
  3. * raylib - Advance Game template
  4. *
  5. * Ending Screen Functions Definitions (Init, Update, Draw, Unload)
  6. *
  7. * Copyright (c) 2014-2018 Ramon Santamaria (@raysan5)
  8. *
  9. * This software is provided "as-is", without any express or implied warranty. In no event
  10. * will the authors be held liable for any damages arising from the use of this software.
  11. *
  12. * Permission is granted to anyone to use this software for any purpose, including commercial
  13. * applications, and to alter it and redistribute it freely, subject to the following restrictions:
  14. *
  15. * 1. The origin of this software must not be misrepresented; you must not claim that you
  16. * wrote the original software. If you use this software in a product, an acknowledgment
  17. * in the product documentation would be appreciated but is not required.
  18. *
  19. * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
  20. * as being the original software.
  21. *
  22. * 3. This notice may not be removed or altered from any source distribution.
  23. *
  24. **********************************************************************************************/
  25. #include "raylib.h"
  26. #include "screens.h"
  27. #include <string.h>
  28. #include <stdlib.h>
  29. #define MAX_TITLE_CHAR 128
  30. #define MAX_SUBTITLE_CHAR 256
  31. //----------------------------------------------------------------------------------
  32. // Global Variables Definition (local to this module)
  33. //----------------------------------------------------------------------------------
  34. static char *codingWords[MAX_CODING_WORDS] = {
  35. "pollo\0",
  36. "conejo\0",
  37. "huevo\0",
  38. "nido\0",
  39. "aire\0",
  40. "armario\0",
  41. "agujero\0",
  42. "platano\0",
  43. "pastel\0",
  44. "mercado\0",
  45. "raton\0",
  46. "melon\0",
  47. };
  48. // Ending screen global variables
  49. static int framesCounter;
  50. static int finishScreen;
  51. static Texture2D texBackground;
  52. static Texture2D texNewspaper;
  53. static Texture2D texVignette;
  54. static Sound fxNews;
  55. static float rotation = 0.1f;
  56. static float scale = 0.05f;
  57. static int state = 0;
  58. static Mission *missions = NULL;
  59. static bool showResults = false;
  60. //----------------------------------------------------------------------------------
  61. // Ending Screen Functions Definition
  62. //----------------------------------------------------------------------------------
  63. // Ending Screen Initialization logic
  64. void InitEndingScreen(void)
  65. {
  66. framesCounter = 0;
  67. finishScreen = 0;
  68. rotation = 0.1f;
  69. scale = 0.05f;
  70. state = 0;
  71. texBackground = LoadTexture("resources/textures/ending_background.png");
  72. texVignette = LoadTexture("resources/textures/message_vignette.png");
  73. fxNews = LoadSound("resources/audio/fx_batman.ogg");
  74. // TODO: Check game results!
  75. missions = LoadMissions("resources/missions.txt");
  76. int wordsCount = missions[currentMission].wordsCount;
  77. TraceLog(LOG_WARNING, "Words count %i", wordsCount);
  78. char title[MAX_TITLE_CHAR] = "\0";
  79. //char subtitle[MAX_SUBTITLE_CHAR] = "\0";
  80. char *ptrTitle = title;
  81. int len = 0;
  82. for (int i = 0; i < wordsCount; i++)
  83. {
  84. if (messageWords[i].id == missions[currentMission].sols[i])
  85. {
  86. len = strlen(messageWords[i].text);
  87. strncpy(ptrTitle, messageWords[i].text, len);
  88. ptrTitle += len;
  89. // title[len] = ' ';
  90. // len++;
  91. // ptrTitle++;
  92. }
  93. else
  94. {
  95. TraceLog(LOG_WARNING, "Coding word: %s", codingWords[messageWords[i].id]);
  96. len = strlen(codingWords[messageWords[i].id]);
  97. TraceLog(LOG_WARNING, "Lenght: %i", len);
  98. strncpy(ptrTitle, codingWords[messageWords[i].id], len);
  99. ptrTitle += len;
  100. // title[len] = ' ';
  101. // len++;
  102. // ptrTitle++;
  103. }
  104. }
  105. ptrTitle = '\0';
  106. //TraceLog(LOG_WARNING, "Titular: %s", title);
  107. // Generate newspaper with title and subtitle
  108. Image imNewspaper = LoadImage("resources/textures/ending_newspaper.png");
  109. SpriteFont fontNews = LoadSpriteFontEx("resources/fonts/Lora-Bold.ttf", 82, 250, 0);
  110. ImageDrawTextEx(&imNewspaper, (Vector2){ 50, 220 }, fontNews, "FRACASO EN LA GGJ18!", fontNews.baseSize, 0, DARKGRAY);
  111. // TODO: Draw subtitle message
  112. //ImageDrawTextEx(&imNewspaper, (Vector2){ 50, 210 }, fontNews, "SUBE LA ESCALERA!", fontNews.baseSize, 0, DARKGRAY);
  113. texNewspaper = LoadTextureFromImage(imNewspaper);
  114. UnloadSpriteFont(fontNews);
  115. UnloadImage(imNewspaper);
  116. }
  117. // Ending Screen Update logic
  118. void UpdateEndingScreen(void)
  119. {
  120. framesCounter++;
  121. if (framesCounter == 10) PlaySound(fxNews);
  122. if (state == 0)
  123. {
  124. rotation += 18.0f;
  125. scale += 0.0096f;
  126. if (scale >= 1.0f)
  127. {
  128. scale = 1.0f;
  129. state = 1;
  130. }
  131. }
  132. if ((state == 1) && (IsKeyPressed(KEY_ENTER) || IsButtonPressed()))
  133. {
  134. currentMission++;
  135. if (currentMission >= totalMissions) finishScreen = 2;
  136. else finishScreen = 1;
  137. }
  138. if (IsKeyPressed(KEY_SPACE)) showResults = !showResults;
  139. }
  140. // Ending Screen Draw logic
  141. void DrawEndingScreen(void)
  142. {
  143. DrawTexture(texBackground, 0, 0, WHITE);
  144. DrawTexturePro(texNewspaper, (Rectangle){ 0, 0, texNewspaper.width, texNewspaper.height },
  145. (Rectangle){ GetScreenWidth()/2, GetScreenHeight()/2, texNewspaper.width*scale, texNewspaper.height*scale },
  146. (Vector2){ (float)texNewspaper.width*scale/2, (float)texNewspaper.height*scale/2 }, rotation, WHITE);
  147. DrawTextureEx(texVignette, (Vector2){ 0, 0 }, 0.0f, 2.0f, WHITE);
  148. if (showResults)
  149. {
  150. for (int i = 0; i < missions[currentMission].wordsCount; i++)
  151. {
  152. if (messageWords[i].id == missions[currentMission].sols[i]) DrawText(messageWords[i].text, 10, 10 + 30*i, 20, GREEN);
  153. else DrawText(codingWords[messageWords[i].id], 10, 10 + 30*i, 20, RED);
  154. }
  155. }
  156. if (state == 1) DrawButton("continuar");
  157. }
  158. // Ending Screen Unload logic
  159. void UnloadEndingScreen(void)
  160. {
  161. UnloadTexture(texBackground);
  162. UnloadTexture(texNewspaper);
  163. UnloadTexture(texVignette);
  164. UnloadSound(fxNews);
  165. free(missions);
  166. }
  167. // Ending Screen should finish?
  168. int FinishEndingScreen(void)
  169. {
  170. return finishScreen;
  171. }