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.

291 lines
7.9 KiB

пре 5 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
  1. /**********************************************************************************************
  2. *
  3. * raylib - transmission mission
  4. *
  5. *
  6. * Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
  7. *
  8. * This software is provided "as-is", without any express or implied warranty. In no event
  9. * will the authors be held liable for any damages arising from the use of this software.
  10. *
  11. * Permission is granted to anyone to use this software for any purpose, including commercial
  12. * applications, and to alter it and redistribute it freely, subject to the following restrictions:
  13. *
  14. * 1. The origin of this software must not be misrepresented; you must not claim that you
  15. * wrote the original software. If you use this software in a product, an acknowledgment
  16. * in the product documentation would be appreciated but is not required.
  17. *
  18. * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
  19. * as being the original software.
  20. *
  21. * 3. This notice may not be removed or altered from any source distribution.
  22. *
  23. **********************************************************************************************/
  24. #include "raylib.h"
  25. #include "screens.h"
  26. #include <string.h>
  27. #include <stdlib.h>
  28. #define MISSION_MAX_LENGTH 256
  29. #define KEYWORD_MAX_LENGTH 32
  30. #define MAX_LINE_CHAR 75
  31. //----------------------------------------------------------------------------------
  32. // Global Variables Definition (local to this module)
  33. //----------------------------------------------------------------------------------
  34. // Mission screen global variables
  35. static int framesCounter;
  36. static int finishScreen;
  37. static Texture2D texBackground;
  38. static Texture2D texBackline; //mission_backline
  39. static Rectangle sourceRecBackLine;
  40. static Rectangle destRecBackLine;
  41. static float fadeBackLine;
  42. static Vector2 numberPosition;
  43. static Color numberColor;
  44. //static char textMission[MISSION_MAX_LENGTH];
  45. static Vector2 missionPosition;
  46. static int missionSize;
  47. static Color missionColor;
  48. static int missionLenght;
  49. static bool missionMaxLength;
  50. static int missionSpeed;
  51. //static char textKeyword[KEYWORD_MAX_LENGTH];
  52. static Vector2 keywordPosition;
  53. static Color keywordColor;
  54. static int showMissionWaitFrames;
  55. static int showNumberWaitFrames;
  56. static int showKeywordWaitFrames;
  57. static bool startWritting;
  58. static bool writeMission;
  59. static bool writeNumber;
  60. static bool writeKeyword;
  61. static bool writeEnd;
  62. static bool writtingMission;
  63. static int blinkFrames;
  64. static bool blinkKeyWord = true;
  65. static bool showButton = false;
  66. static Mission *missions = NULL;
  67. static Sound fxTransmit;
  68. static Music musMission;
  69. //----------------------------------------------------------------------------------
  70. // Mission Screen Functions Definition
  71. //----------------------------------------------------------------------------------
  72. static void WriteMissionText();
  73. // Mission Screen Initialization logic
  74. void InitMissionScreen(void)
  75. {
  76. framesCounter = 0;
  77. finishScreen = 0;
  78. fadeButton = 0.80f;
  79. texBackground = LoadTexture("resources/textures/mission_background.png");
  80. texBackline = LoadTexture("resources/textures/mission_backline.png");
  81. sourceRecBackLine = (Rectangle){0,0,GetScreenWidth(), texBackline.height};
  82. destRecBackLine = (Rectangle){0,0,sourceRecBackLine.width, sourceRecBackLine.height};
  83. fadeBackLine = 0;
  84. fxTransmit = LoadSound("resources/audio/fx_message.ogg");
  85. musMission = LoadMusicStream("resources/audio/music_mission.ogg");
  86. PlayMusicStream(musMission);
  87. // Initialize missions
  88. missions = LoadMissions("resources/missions.txt");
  89. missionMaxLength = strlen(missions[currentMission].brief);
  90. // Insert line breaks every MAX_LINE_CHAR
  91. int currentLine = 1;
  92. int i = currentLine * MAX_LINE_CHAR;
  93. while (i < missionMaxLength)
  94. {
  95. if (missions[currentMission].brief[i] == ' ')
  96. {
  97. missions[currentMission].brief[i] = '\n';
  98. currentLine++;
  99. i = currentLine*MAX_LINE_CHAR;
  100. }
  101. else i++;
  102. }
  103. missionSize = 30;
  104. missionLenght = 0;
  105. missionSpeed = 1;
  106. numberColor = RAYWHITE;
  107. missionColor = LIGHTGRAY;
  108. keywordColor = (Color){198, 49, 60, 255}; //RED
  109. numberPosition = (Vector2){150, 185};
  110. missionPosition = (Vector2){numberPosition.x, numberPosition.y + 60};
  111. keywordPosition = (Vector2){missionPosition.x, missionPosition.y + MeasureTextEx(fontMission, missions[currentMission].brief, missionSize, 0).y + 60};
  112. startWritting = false;
  113. writeNumber = false;
  114. writeMission = false;
  115. writeKeyword = false;
  116. writeEnd = false;
  117. writtingMission = false;
  118. showNumberWaitFrames = 30;
  119. showMissionWaitFrames = 60;
  120. showKeywordWaitFrames = 60;
  121. blinkKeyWord = true;
  122. blinkFrames = 15;
  123. PlaySound(fxTransmit);
  124. }
  125. // Mission Screen Update logic
  126. void UpdateMissionScreen(void)
  127. {
  128. UpdateMusicStream(musMission);
  129. if (!writeEnd) WriteMissionText();
  130. else
  131. {
  132. framesCounter++;
  133. if ((framesCounter%blinkFrames) == 0)
  134. {
  135. framesCounter = 0;
  136. blinkKeyWord = !blinkKeyWord;
  137. }
  138. }
  139. if (showButton)
  140. {
  141. if (IsKeyPressed(KEY_ENTER) || IsButtonPressed())
  142. {
  143. if (!writeEnd)
  144. {
  145. writeEnd = true;
  146. writeKeyword = true;
  147. writeNumber = true;
  148. missionLenght = missionMaxLength;
  149. }
  150. else
  151. {
  152. finishScreen = true;
  153. showButton = false;
  154. }
  155. }
  156. }
  157. }
  158. // Mission Screen Draw logic
  159. void DrawMissionScreen(void)
  160. {
  161. // Draw MISSION screen here!
  162. DrawTexture(texBackground, 0,0, WHITE);
  163. DrawTexturePro(texBackline, sourceRecBackLine, destRecBackLine, (Vector2){0,0},0, Fade(WHITE, fadeBackLine));
  164. if (writeNumber) DrawTextEx(fontMission, FormatText("Filtración #%02i ", currentMission + 1), numberPosition, missionSize + 10, 0, numberColor);
  165. DrawTextEx(fontMission, TextSubtext(missions[currentMission].brief, 0, missionLenght), missionPosition, missionSize, 0, missionColor);
  166. if (writeKeyword && blinkKeyWord) DrawTextEx(fontMission, FormatText("Keyword: %s", missions[currentMission].key), keywordPosition, missionSize + 10, 0, keywordColor);
  167. if (showButton)
  168. {
  169. if (!writeEnd) DrawButton("saltar");
  170. else DrawButton("codificar");
  171. }
  172. }
  173. // Mission Screen Unload logic
  174. void UnloadMissionScreen(void)
  175. {
  176. // Unload MISSION screen variables here!
  177. UnloadTexture(texBackground);
  178. UnloadTexture(texBackline);
  179. UnloadSound(fxTransmit);
  180. UnloadMusicStream(musMission);
  181. free(missions);
  182. }
  183. // Mission Screen should finish?
  184. int FinishMissionScreen(void)
  185. {
  186. return finishScreen;
  187. }
  188. static void WriteMissionText()
  189. {
  190. if (!startWritting)
  191. {
  192. framesCounter++;
  193. if (framesCounter % 60 == 0)
  194. {
  195. framesCounter = 0;
  196. startWritting = true;
  197. }
  198. }
  199. else if (!writeNumber)
  200. {
  201. framesCounter++;
  202. fadeBackLine += 0.020f;
  203. if (framesCounter % showNumberWaitFrames == 0)
  204. {
  205. framesCounter = 0;
  206. writeNumber = true;
  207. showButton = true;
  208. }
  209. }
  210. else if (!writeMission)
  211. {
  212. framesCounter ++;
  213. if (framesCounter % showMissionWaitFrames == 0)
  214. {
  215. framesCounter = 0;
  216. writeMission = true;
  217. writtingMission = true;
  218. }
  219. }
  220. else if (writeMission && writtingMission)
  221. {
  222. framesCounter++;
  223. if (framesCounter % missionSpeed == 0)
  224. {
  225. framesCounter = 0;
  226. missionLenght++;
  227. if (missionLenght == missionMaxLength)
  228. {
  229. writtingMission = false;
  230. }
  231. }
  232. }
  233. else if (!writeKeyword)
  234. {
  235. framesCounter++;
  236. if (framesCounter % showKeywordWaitFrames == 0)
  237. {
  238. framesCounter = 0;
  239. writeKeyword = true;
  240. writeEnd = true;
  241. }
  242. }
  243. }