Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

151 Zeilen
5.6 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib - Simple Game template
  4. *
  5. * <Game title>
  6. * <Game description>
  7. *
  8. * This game has been created using raylib (www.raylib.com)
  9. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  10. *
  11. * Copyright (c) 2014-2018 Ramon Santamaria (@raysan5)
  12. *
  13. ********************************************************************************************/
  14. #include "raylib.h"
  15. //----------------------------------------------------------------------------------
  16. // Types and Structures Definition
  17. //----------------------------------------------------------------------------------
  18. typedef enum GameScreen { LOGO = 0, TITLE, GAMEPLAY, ENDING } GameScreen;
  19. //----------------------------------------------------------------------------------
  20. // Main entry point
  21. //----------------------------------------------------------------------------------
  22. int main(void)
  23. {
  24. // Initialization (Note windowTitle is unused on Android)
  25. //--------------------------------------------------------------------------------------
  26. const int screenWidth = 800;
  27. const int screenHeight = 450;
  28. InitWindow(screenWidth, screenHeight, "raylib template - simple game");
  29. GameScreen currentScreen = LOGO;
  30. // TODO: Initialize all required variables and load all required data here!
  31. int framesCounter = 0; // Useful to count frames
  32. SetTargetFPS(60); // Set desired framerate (frames-per-second)
  33. //--------------------------------------------------------------------------------------
  34. // Main game loop
  35. while (!WindowShouldClose()) // Detect window close button or ESC key
  36. {
  37. // Update
  38. //----------------------------------------------------------------------------------
  39. switch(currentScreen)
  40. {
  41. case LOGO:
  42. {
  43. // TODO: Update LOGO screen variables here!
  44. framesCounter++; // Count frames
  45. // Wait for 2 seconds (120 frames) before jumping to TITLE screen
  46. if (framesCounter > 120)
  47. {
  48. currentScreen = TITLE;
  49. }
  50. } break;
  51. case TITLE:
  52. {
  53. // TODO: Update TITLE screen variables here!
  54. // Press enter to change to GAMEPLAY screen
  55. if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP))
  56. {
  57. currentScreen = GAMEPLAY;
  58. }
  59. } break;
  60. case GAMEPLAY:
  61. {
  62. // TODO: Update GAMEPLAY screen variables here!
  63. // Press enter to change to ENDING screen
  64. if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP))
  65. {
  66. currentScreen = ENDING;
  67. }
  68. } break;
  69. case ENDING:
  70. {
  71. // TODO: Update ENDING screen variables here!
  72. // Press enter to return to TITLE screen
  73. if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP))
  74. {
  75. currentScreen = TITLE;
  76. }
  77. } break;
  78. default: break;
  79. }
  80. //----------------------------------------------------------------------------------
  81. // Draw
  82. //----------------------------------------------------------------------------------
  83. BeginDrawing();
  84. ClearBackground(RAYWHITE);
  85. switch(currentScreen)
  86. {
  87. case LOGO:
  88. {
  89. // TODO: Draw LOGO screen here!
  90. DrawText("LOGO SCREEN", 20, 20, 40, LIGHTGRAY);
  91. DrawText("WAIT for 2 SECONDS...", 290, 220, 20, GRAY);
  92. } break;
  93. case TITLE:
  94. {
  95. // TODO: Draw TITLE screen here!
  96. DrawRectangle(0, 0, screenWidth, screenHeight, GREEN);
  97. DrawText("TITLE SCREEN", 20, 20, 40, DARKGREEN);
  98. DrawText("PRESS ENTER or TAP to JUMP to GAMEPLAY SCREEN", 120, 220, 20, DARKGREEN);
  99. } break;
  100. case GAMEPLAY:
  101. {
  102. // TODO: Draw GAMEPLAY screen here!
  103. DrawRectangle(0, 0, screenWidth, screenHeight, PURPLE);
  104. DrawText("GAMEPLAY SCREEN", 20, 20, 40, MAROON);
  105. DrawText("PRESS ENTER or TAP to JUMP to ENDING SCREEN", 130, 220, 20, MAROON);
  106. } break;
  107. case ENDING:
  108. {
  109. // TODO: Draw ENDING screen here!
  110. DrawRectangle(0, 0, screenWidth, screenHeight, BLUE);
  111. DrawText("ENDING SCREEN", 20, 20, 40, DARKBLUE);
  112. DrawText("PRESS ENTER or TAP to RETURN to TITLE SCREEN", 120, 220, 20, DARKBLUE);
  113. } break;
  114. default: break;
  115. }
  116. EndDrawing();
  117. //----------------------------------------------------------------------------------
  118. }
  119. // De-Initialization
  120. //--------------------------------------------------------------------------------------
  121. // TODO: Unload all loaded data (textures, fonts, audio) here!
  122. CloseWindow(); // Close window and OpenGL context
  123. //--------------------------------------------------------------------------------------
  124. return 0;
  125. }