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.

167 lines
4.7 KiB

  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. //----------------------------------------------------------------------------------
  28. // Global Variables Definition (local to this module)
  29. //----------------------------------------------------------------------------------
  30. // Title screen global variables
  31. static int framesCounter;
  32. static int finishScreen;
  33. static Texture2D texBackground;
  34. static Font fontTitle;
  35. static Sound fxTyping;
  36. static float titleSize;
  37. static Vector2 transmissionPosition;
  38. static Vector2 missionPositon;
  39. static const char textTitle[20] = "transmissionmission";
  40. static Color titleColor;
  41. static int speedText;
  42. static int transmissionLenght;
  43. static int missionLenght;
  44. static int transmissionMaxLenght;
  45. static int missionMaxLenght;
  46. static bool writeTransmission;
  47. static bool writeMission;
  48. static bool writeEnd;
  49. //----------------------------------------------------------------------------------
  50. // Title Screen Functions Definition
  51. //----------------------------------------------------------------------------------
  52. static void MissionScreen();
  53. // Title Screen Initialization logic
  54. void InitTitleScreen(void)
  55. {
  56. // TODO: Initialize TITLE screen variables here!
  57. framesCounter = 0;
  58. finishScreen = 0;
  59. texBackground = LoadTexture("resources/textures/title_background.png");
  60. fxTyping = LoadSound("resources/audio/fx_typing.ogg");
  61. fontTitle = LoadFontEx("resources/fonts/mom_typewritter.ttf", 96, 0, 0);
  62. titleSize = 44;
  63. transmissionPosition = (Vector2){519, 221};
  64. missionPositon = (Vector2){580, 261};
  65. titleColor = BLACK;
  66. speedText = 15;
  67. missionLenght = 0;
  68. transmissionLenght = 0;
  69. missionMaxLenght = 7;
  70. transmissionMaxLenght = 12;
  71. writeTransmission = true;
  72. writeMission = false;
  73. writeEnd = false;
  74. currentMission = 0;
  75. }
  76. // Title Screen Update logic
  77. void UpdateTitleScreen(void)
  78. {
  79. if (!writeEnd)
  80. {
  81. framesCounter ++;
  82. if (framesCounter%speedText == 0)
  83. {
  84. framesCounter = 0;
  85. if (writeTransmission)
  86. {
  87. transmissionLenght++;
  88. if (transmissionLenght == transmissionMaxLenght)
  89. {
  90. writeTransmission = false;
  91. writeMission = true;
  92. }
  93. }
  94. else if (writeMission)
  95. {
  96. missionLenght++;
  97. if (missionLenght == missionMaxLenght)
  98. {
  99. writeMission = false;
  100. writeEnd = true;
  101. }
  102. }
  103. PlaySound(fxTyping);
  104. }
  105. }
  106. if(IsButtonPressed())
  107. {
  108. MissionScreen();
  109. }
  110. else if (IsKeyPressed(KEY_ENTER)) MissionScreen();
  111. }
  112. // Title Screen Draw logic
  113. void DrawTitleScreen(void)
  114. {
  115. DrawTexture(texBackground, 0,0, WHITE);
  116. DrawTextEx(fontTitle, TextSubtext(textTitle, 0, transmissionLenght), transmissionPosition, titleSize, 0, titleColor);
  117. DrawTextEx(fontTitle, TextSubtext(textTitle, 12, missionLenght), missionPositon, titleSize, 0, titleColor);
  118. DrawButton("start");
  119. }
  120. // Title Screen Unload logic
  121. void UnloadTitleScreen(void)
  122. {
  123. UnloadTexture(texBackground);
  124. UnloadSound(fxTyping);
  125. UnloadFont(fontTitle);
  126. }
  127. // Title Screen should finish?
  128. int FinishTitleScreen(void)
  129. {
  130. return finishScreen;
  131. }
  132. static void MissionScreen()
  133. {
  134. transmissionLenght = transmissionMaxLenght;
  135. missionLenght = missionMaxLenght;
  136. writeEnd = true;
  137. //finishScreen = 1; // OPTIONS
  138. finishScreen = true; // GAMEPLAY
  139. //PlaySound(fxCoin);
  140. }