2
0

Beginners_-_ModifyMultiDArrayFunction.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "raylib.h"
  2. // Let the compiler know we are using a function outside the main function.
  3. // We need to pass the size of the last dimension of the array here.
  4. void changemap(int map[][10],int x,int y);
  5. int main(void)
  6. {
  7. // Initialization
  8. //--------------------------------------------------------------------------------------
  9. const int screenWidth = 800;
  10. const int screenHeight = 450;
  11. InitWindow(screenWidth, screenHeight, "raylib example.");
  12. int map[10][10] = {0};
  13. changemap(map,9,9);
  14. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  15. //--------------------------------------------------------------------------------------
  16. // Main game loop
  17. while (!WindowShouldClose()) // Detect window close button or ESC key
  18. {
  19. // Update
  20. //----------------------------------------------------------------------------------
  21. //----------------------------------------------------------------------------------
  22. // Draw
  23. //----------------------------------------------------------------------------------
  24. BeginDrawing();
  25. ClearBackground(RAYWHITE);
  26. for(int y=0;y<10;y++){
  27. for(int x=0;x<10;x++){
  28. DrawText(FormatText("%i",map[x][y]),x*20,y*20,20,BLACK);
  29. }}
  30. EndDrawing();
  31. //----------------------------------------------------------------------------------
  32. }
  33. // De-Initialization
  34. //--------------------------------------------------------------------------------------
  35. CloseWindow(); // Close window and OpenGL context
  36. //--------------------------------------------------------------------------------------
  37. return 0;
  38. }
  39. // This is our function passed with a multi dim array
  40. // It is outside the main function.
  41. // void means it returns nothing.
  42. // We need to pass it the last dimension size
  43. void changemap(int map[][10],int x,int y){
  44. map[x][y] = 99;
  45. }