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.

162 lines
5.3 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib game - Dr. Turtle & Mr. Gamera
  4. *
  5. * Welcome to raylib!
  6. *
  7. * To test examples, just press F6 and execute raylib_compile_execute script
  8. * Note that compiled executable is placed in the same folder as .c file
  9. *
  10. * You can find all basic examples on C:\raylib\raylib\examples folder or
  11. * raylib official webpage: www.raylib.com
  12. *
  13. * Enjoy using raylib. :)
  14. *
  15. * This game has been created using raylib 1.1 (www.raylib.com)
  16. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  17. *
  18. * Copyright (c) 2014 Ramon Santamaria (@raysan5)
  19. *
  20. ********************************************************************************************/
  21. #include "raylib.h"
  22. #define MAX_ENEMIES 10
  23. typedef enum { TITLE, GAMEPLAY, ENDING } GameScreen;
  24. int main()
  25. {
  26. // Initialization
  27. //--------------------------------------------------------------------------------------
  28. const int screenWidth = 1280;
  29. const int screenHeight = 720;
  30. // Init window
  31. InitWindow(screenWidth, screenHeight, "Dr. Turtle & Mr. GAMERA");
  32. // Load game resources: textures
  33. Texture2D sky = LoadTexture("resources/sky.png");
  34. Texture2D mountains = LoadTexture("resources/mountains.png");
  35. Texture2D sea = LoadTexture("resources/sea.png");
  36. // Define scrolling variables
  37. int backScrolling = 0;
  38. int seaScrolling = 0;
  39. // Define current screen
  40. GameScreen currentScreen = TITLE;
  41. SetTargetFPS(60); // Setup game frames per second
  42. //--------------------------------------------------------------------------------------
  43. // Main game loop
  44. while (!WindowShouldClose()) // Detect window close button or ESC key
  45. {
  46. // Update
  47. //----------------------------------------------------------------------------------
  48. // Game screens management
  49. switch (currentScreen)
  50. {
  51. case TITLE:
  52. {
  53. // Sea scrolling
  54. seaScrolling -= 2;
  55. if (seaScrolling <= -screenWidth) seaScrolling = 0;
  56. // Press enter to change to gameplay screen
  57. if (IsKeyPressed(KEY_ENTER))
  58. {
  59. currentScreen = GAMEPLAY;
  60. }
  61. } break;
  62. case GAMEPLAY:
  63. {
  64. // Background scrolling logic
  65. backScrolling--;
  66. if (backScrolling <= -screenWidth) backScrolling = 0;
  67. // Sea scrolling logic
  68. seaScrolling -= 8;
  69. if (seaScrolling <= -screenWidth) seaScrolling = 0;
  70. // Press enter to change to ending screen
  71. if (IsKeyPressed(KEY_ENTER))
  72. {
  73. currentScreen = ENDING;
  74. }
  75. } break;
  76. case ENDING:
  77. {
  78. // Press enter to change to title screen
  79. if (IsKeyPressed(KEY_ENTER))
  80. {
  81. currentScreen = TITLE;
  82. }
  83. } break;
  84. default: break;
  85. }
  86. //----------------------------------------------------------------------------------
  87. // Draw
  88. //----------------------------------------------------------------------------------
  89. BeginDrawing();
  90. ClearBackground(RAYWHITE);
  91. // Draw background (common to all screens)
  92. DrawTexture(sky, 0, 0, WHITE);
  93. DrawTexture(mountains, backScrolling, 0, WHITE);
  94. DrawTexture(mountains, screenWidth + backScrolling, 0, WHITE);
  95. DrawTexture(sea, seaScrolling, 0, BLUE);
  96. DrawTexture(sea, screenWidth + seaScrolling, 0, BLUE);
  97. switch (currentScreen)
  98. {
  99. case TITLE:
  100. {
  101. // Draw title screen
  102. DrawText("PRESS ENTER", 450, 420, 40, BLACK);
  103. } break;
  104. case GAMEPLAY:
  105. {
  106. // Draw gameplay screen
  107. DrawText("GAMEPLAY SCREEN", 20, 20, 40, MAROON);
  108. } break;
  109. case ENDING:
  110. {
  111. // Draw ending screen
  112. // Draw a transparent black rectangle that covers all screen
  113. DrawRectangle(0, 0, screenWidth, screenHeight, Fade(BLACK, 0.4f));
  114. DrawText("ENDING SCREEN", 20, 20, 40, DARKBLUE);
  115. } break;
  116. default: break;
  117. }
  118. EndDrawing();
  119. //----------------------------------------------------------------------------------
  120. }
  121. // De-Initialization
  122. //--------------------------------------------------------------------------------------
  123. // Unload textures
  124. UnloadTexture(sky);
  125. UnloadTexture(mountains);
  126. UnloadTexture(sea);
  127. CloseWindow(); // Close window and OpenGL context
  128. //--------------------------------------------------------------------------------------
  129. return 0;
  130. }