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.

105 regels
3.4 KiB

8 jaren geleden
  1. /**********************************************************************************************
  2. *
  3. * raylib - Advance Game template
  4. *
  5. * Title Screen Functions Definitions (Init, Update, Draw, Unload)
  6. *
  7. * Copyright (c) 2014 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 Texture2D background;
  34. static Texture2D title;
  35. static float titleAlpha = 0.0f;
  36. static Sound fxStart;
  37. //----------------------------------------------------------------------------------
  38. // Title Screen Functions Definition
  39. //----------------------------------------------------------------------------------
  40. // Title Screen Initialization logic
  41. void InitTitleScreen(void)
  42. {
  43. // Initialize TITLE screen variables here!
  44. framesCounter = 0;
  45. finishScreen = 0;
  46. background = LoadTexture("resources/textures/back_title.png");
  47. title = LoadTexture("resources/textures/title.png");
  48. fxStart = LoadSound("resources/audio/start.wav");
  49. }
  50. // Title Screen Update logic
  51. void UpdateTitleScreen(void)
  52. {
  53. // Update TITLE screen variables here!
  54. framesCounter++;
  55. titleAlpha += 0.005f;
  56. if (titleAlpha >= 1.0f) titleAlpha = 1.0f;
  57. // Press enter to change to ATTIC screen
  58. if ((IsKeyPressed(KEY_ENTER)) || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)))
  59. {
  60. PlaySound(fxStart);
  61. finishScreen = 1;
  62. }
  63. }
  64. // Title Screen Draw logic
  65. void DrawTitleScreen(void)
  66. {
  67. DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), (Color){ 26, 26, 26, 255 });
  68. DrawTexture(background, GetScreenWidth()/2 - background.width/2, 0, WHITE);
  69. DrawTexture(title, GetScreenWidth()/2 - title.width/2, 30, Fade(WHITE, titleAlpha));
  70. DrawText("(c) Developed by Ramon Santamaria (@raysan5)", 20, GetScreenHeight() - 40, 20, LIGHTGRAY);
  71. if ((framesCounter > 180) && ((framesCounter/40)%2)) DrawTextEx(font, "PRESS ENTER to START LIGHTING", (Vector2){ 230, 450 }, font.baseSize, -2, WHITE);
  72. }
  73. // Title Screen Unload logic
  74. void UnloadTitleScreen(void)
  75. {
  76. // Unload TITLE screen variables here!
  77. UnloadTexture(background);
  78. UnloadTexture(title);
  79. UnloadSound(fxStart);
  80. }
  81. // Title Screen should finish?
  82. int FinishTitleScreen(void)
  83. {
  84. return finishScreen;
  85. }