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.

153 lines
4.6 KiB

  1. /**********************************************************************************************
  2. *
  3. * raylib - Advance Game template
  4. *
  5. * Title Screen Functions Definitions (Init, Update, Draw, Unload)
  6. *
  7. * Copyright (c) 2014-2019 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. //----------------------------------------------------------------------------------
  28. // Global Variables Definition (local to this module)
  29. //----------------------------------------------------------------------------------
  30. // Title screen global variables
  31. static int framesCounter;
  32. static int finishScreen;
  33. static int state;
  34. static int scrollPositionX;
  35. static int catPosX;
  36. static int roombaPosX;
  37. static float vsAlpha;
  38. static float vsScale;
  39. static Texture2D cat;
  40. static Texture2D vs;
  41. static Texture2D roomba;
  42. //----------------------------------------------------------------------------------
  43. // Title Screen Functions Definition
  44. //----------------------------------------------------------------------------------
  45. // Title Screen Initialization logic
  46. void InitTitleScreen(void)
  47. {
  48. // TODO: Initialize TITLE screen variables here!
  49. framesCounter = 0;
  50. finishScreen = 0;
  51. cat = LoadTexture("resources/title_cat.png");
  52. vs = LoadTexture("resources/title_vs.png");
  53. roomba = LoadTexture("resources/title_roomba.png");
  54. state = 0;
  55. catPosX = 1760;
  56. roombaPosX = -700;
  57. scrollPositionX = 0;
  58. vsAlpha = 0.0f;
  59. vsScale = 10.0f;
  60. PlayMusicStream(music);
  61. }
  62. // Title Screen Update logic
  63. void UpdateTitleScreen(void)
  64. {
  65. scrollPositionX -= 5;
  66. if (scrollPositionX < -GetScreenWidth()) scrollPositionX = 0;
  67. if (state == 0)
  68. {
  69. catPosX -= 4;
  70. roombaPosX += 3;
  71. if (catPosX < (GetScreenWidth()/2 - cat.width/2)) catPosX = (GetScreenWidth()/2 - cat.width/2);
  72. if (roombaPosX > (GetScreenWidth()/2 - roomba.width/2)) roombaPosX = (GetScreenWidth()/2 - roomba.width/2);
  73. if ((catPosX == (GetScreenWidth()/2 - cat.width/2)) && (roombaPosX == (GetScreenWidth()/2 - roomba.width/2)))
  74. {
  75. state = 1;
  76. framesCounter = 0;
  77. }
  78. }
  79. else if (state == 1)
  80. {
  81. framesCounter++;
  82. vsScale -= 0.1f;
  83. vsAlpha += 0.01f;
  84. if (vsScale < 1.0f) vsScale = 1.0f;
  85. if (vsAlpha > 1.0f) vsAlpha = 1.0f;
  86. if (framesCounter > 160)
  87. {
  88. state = 2;
  89. framesCounter = 0;
  90. }
  91. }
  92. else if (state == 2) framesCounter++;
  93. // Press enter or tap to change to GAMEPLAY screen
  94. if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP))
  95. {
  96. //finishScreen = 1; // OPTIONS
  97. finishScreen = 2; // GAMEPLAY
  98. PlaySound(fxCoin);
  99. }
  100. }
  101. // Title Screen Draw logic
  102. void DrawTitleScreen(void)
  103. {
  104. for (int i = 0; i < 64*2*2; i++)
  105. {
  106. DrawRectangle(64*i + scrollPositionX, 0, 64, GetScreenHeight(), (i%2 == 0)? GetColor(0xf3726dff) : GetColor(0xffcf6bff));
  107. }
  108. DrawTexture(cat, catPosX, 80, WHITE);
  109. DrawTexture(roomba, roombaPosX, 320, WHITE);
  110. if (state > 0)
  111. {
  112. DrawTexturePro(vs, (Rectangle){ 0, 0, vs.width, vs.height }, (Rectangle){ GetScreenWidth()/2, 300, vs.width*vsScale, vs.height*vsScale }, (Vector2){ vs.width/2*vsScale, vs.height/2*vsScale }, 0.0f, Fade(WHITE, vsAlpha));
  113. }
  114. if ((state == 2) && ((framesCounter/30)%2)) DrawTextEx(font2, "PRESS ENTER to START", (Vector2){ 340, 550 }, font2.baseSize, 2, WHITE);
  115. }
  116. // Title Screen Unload logic
  117. void UnloadTitleScreen(void)
  118. {
  119. UnloadTexture(cat);
  120. UnloadTexture(vs);
  121. UnloadTexture(roomba);
  122. }
  123. // Title Screen should finish?
  124. int FinishTitleScreen(void)
  125. {
  126. return finishScreen;
  127. }