您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

168 行
6.2 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib - Android Basic Game template
  4. *
  5. * <Game title>
  6. * <Game description>
  7. *
  8. * This game has been created using raylib v1.2 (www.raylib.com)
  9. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  10. *
  11. * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
  12. *
  13. ********************************************************************************************/
  14. #include "raylib.h"
  15. //----------------------------------------------------------------------------------
  16. // Types and Structures Definition
  17. //----------------------------------------------------------------------------------
  18. typedef enum GameScreen { LOGO, TITLE, GAMEPLAY, ENDING } GameScreen;
  19. //----------------------------------------------------------------------------------
  20. // Android Main entry point
  21. //----------------------------------------------------------------------------------
  22. void android_main(struct android_app *app)
  23. {
  24. // Initialization
  25. //--------------------------------------------------------------------------------------
  26. const int screenWidth = 800;
  27. const int screenHeight = 450;
  28. GameScreen currentScreen = LOGO;
  29. InitWindow(screenWidth, screenHeight, app);
  30. // TODO: Initialize all required variables and load all required data here!
  31. InitAudioDevice(); // Initialize audio device
  32. Sound fx = LoadSound("coin.wav"); // Load WAV audio file (placed on assets folder)
  33. Texture2D texture = LoadTexture("raylib_logo.png"); // Load texture (placed on assets folder)
  34. int framesCounter = 0; // Used to count frames
  35. PlayMusicStream("ambient.ogg");
  36. SetTargetFPS(60); // Not required on Android, already locked to 60 fps
  37. //--------------------------------------------------------------------------------------
  38. // Main game loop
  39. while (!WindowShouldClose()) // Detect window close button or ESC key
  40. {
  41. // Update
  42. //----------------------------------------------------------------------------------
  43. UpdateMusicStream();
  44. switch(currentScreen)
  45. {
  46. case LOGO:
  47. {
  48. // TODO: Update LOGO screen variables here!
  49. framesCounter++; // Count frames
  50. // Wait for 4 seconds (240 frames) before jumping to TITLE screen
  51. if (framesCounter > 240)
  52. {
  53. currentScreen = TITLE;
  54. }
  55. } break;
  56. case TITLE:
  57. {
  58. // TODO: Update TITLE screen variables here!
  59. // Press enter to change to GAMEPLAY screen
  60. if (GetGestureType() == GESTURE_TAP)
  61. {
  62. PlaySound(fx);
  63. currentScreen = GAMEPLAY;
  64. }
  65. } break;
  66. case GAMEPLAY:
  67. {
  68. // TODO: Update GAMEPLAY screen variables here!
  69. // Press enter to change to ENDING screen
  70. if (GetGestureType() == GESTURE_TAP)
  71. {
  72. PlaySound(fx);
  73. currentScreen = ENDING;
  74. }
  75. } break;
  76. case ENDING:
  77. {
  78. // TODO: Update ENDING screen variables here!
  79. // Press enter to return to TITLE screen
  80. if (GetGestureType() == GESTURE_TAP)
  81. {
  82. PlaySound(fx);
  83. currentScreen = TITLE;
  84. }
  85. } break;
  86. default: break;
  87. }
  88. //----------------------------------------------------------------------------------
  89. // Draw
  90. //----------------------------------------------------------------------------------
  91. BeginDrawing();
  92. ClearBackground(RAYWHITE);
  93. switch(currentScreen)
  94. {
  95. case LOGO:
  96. {
  97. // TODO: Draw LOGO screen here!
  98. DrawText("LOGO SCREEN", 20, 20, 40, LIGHTGRAY);
  99. DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE);
  100. DrawText("WAIT for 4 SECONDS...", 290, 400, 20, GRAY);
  101. } break;
  102. case TITLE:
  103. {
  104. // TODO: Draw TITLE screen here!
  105. DrawRectangle(0, 0, screenWidth, screenHeight, GREEN);
  106. DrawText("TITLE SCREEN", 20, 20, 40, DARKGREEN);
  107. DrawText("TAP SCREEN to JUMP to GAMEPLAY SCREEN", 160, 220, 20, DARKGREEN);
  108. } break;
  109. case GAMEPLAY:
  110. {
  111. // TODO: Draw GAMEPLAY screen here!
  112. DrawRectangle(0, 0, screenWidth, screenHeight, PURPLE);
  113. DrawText("GAMEPLAY SCREEN", 20, 20, 40, MAROON);
  114. DrawText("TAP SCREEN to JUMP to ENDING SCREEN", 170, 220, 20, MAROON);
  115. } break;
  116. case ENDING:
  117. {
  118. // TODO: Draw ENDING screen here!
  119. DrawRectangle(0, 0, screenWidth, screenHeight, BLUE);
  120. DrawText("ENDING SCREEN", 20, 20, 40, DARKBLUE);
  121. DrawText("TAP SCREEN to RETURN to TITLE SCREEN", 160, 220, 20, DARKBLUE);
  122. } break;
  123. default: break;
  124. }
  125. EndDrawing();
  126. //----------------------------------------------------------------------------------
  127. }
  128. // De-Initialization
  129. //--------------------------------------------------------------------------------------
  130. // TODO: Unload all loaded data (textures, fonts, audio) here!
  131. UnloadSound(fx); // Unload sound data
  132. CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
  133. UnloadTexture(texture); // Unload texture data
  134. CloseWindow(); // Close window and OpenGL context
  135. //--------------------------------------------------------------------------------------
  136. }