2
0

Example_-_Switch_array_hills.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "raylib.h"
  2. void floodit();
  3. int main(void)
  4. {
  5. // Initialization
  6. //--------------------------------------------------------------------------------------
  7. const int screenWidth = 800;
  8. const int screenHeight = 450;
  9. InitWindow(screenWidth, screenHeight, "raylib example.");
  10. int mymap[50][50] = {0};
  11. for (int i=0;i<20;i++){
  12. int y=0;
  13. if (GetRandomValue(0,1) == 1) y=1;
  14. mymap[10+i][25+y] = 1;
  15. }
  16. for (int i=0;i<31550;i++)
  17. {
  18. int x = GetRandomValue(1,49);
  19. int y = GetRandomValue(1,49);
  20. if (mymap[y][x] == 1)
  21. {
  22. switch (GetRandomValue(0,3))
  23. {
  24. case 0:
  25. mymap[y-1][x]=1;
  26. break;
  27. case 1:
  28. mymap[y+1][x]=1;
  29. break;
  30. case 2:
  31. mymap[y][x-1]=1;
  32. break;
  33. case 3:
  34. mymap[y][x+1]=1;
  35. break;
  36. }
  37. }
  38. }
  39. // Create a Image in memory
  40. RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
  41. // Clear our texture(image) before entering the game loop
  42. BeginTextureMode(target);
  43. ClearBackground(BLUE);
  44. EndTextureMode();
  45. // Draw something on it.
  46. for (int y=0;y<50;y++)
  47. {
  48. for (int x=0;x<50; x++)
  49. {
  50. if (mymap[y][x]==1)
  51. {
  52. BeginTextureMode(target);
  53. DrawRectangle(x*16,y*8,16,8,BLACK);
  54. EndTextureMode();
  55. }
  56. }
  57. }
  58. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  59. //--------------------------------------------------------------------------------------
  60. // Main game loop
  61. while (!WindowShouldClose()) // Detect window close button or ESC key
  62. {
  63. // Update
  64. //----------------------------------------------------------------------------------
  65. //----------------------------------------------------------------------------------
  66. // Draw
  67. //----------------------------------------------------------------------------------
  68. BeginDrawing();
  69. ClearBackground(RAYWHITE);
  70. // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
  71. DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE);
  72. DrawText("Switch/array/hillalgo.", 100, 180, 40, LIGHTGRAY);
  73. EndDrawing();
  74. //----------------------------------------------------------------------------------
  75. }
  76. // De-Initialization
  77. //--------------------------------------------------------------------------------------
  78. UnloadRenderTexture(target); // Unload render texture
  79. //--------------------------------------------------------------------------------------
  80. CloseWindow(); // Close window and OpenGL context
  81. //--------------------------------------------------------------------------------------
  82. return 0;
  83. }