2
0

File_-_ReadAndWrite_Array.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "raylib.h"
  5. static int spritelibmap[80*4][32][32]; // numspritelib,
  6. int main(void)
  7. {
  8. // Initialization
  9. //--------------------------------------------------------------------------------------
  10. const int screenWidth = 800;
  11. const int screenHeight = 450;
  12. InitWindow(screenWidth, screenHeight, "raylib example.");
  13. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  14. //--------------------------------------------------------------------------------------
  15. // Put some values in the array.
  16. spritelibmap[0][0][0] = 1;
  17. spritelibmap[20][10][10] = 1;
  18. // Create out file pointer.
  19. FILE *fp;
  20. // Write the array to disk.
  21. fp=fopen("spritedata.spr","w");
  22. fwrite(spritelibmap,sizeof(spritelibmap),1,fp); /* Write to File */
  23. fclose(fp);
  24. // Reset the values in the array.
  25. spritelibmap[0][0][0] = 0;
  26. spritelibmap[20][10][10] = 0;
  27. // Read the array from disk..
  28. fp=fopen("spritedata.spr","r");
  29. fread(spritelibmap,sizeof(spritelibmap),1,fp); /* read the entire file into the array */
  30. fclose(fp);
  31. // Main game loop
  32. while (!WindowShouldClose()) // Detect window close button or ESC key
  33. {
  34. // Update
  35. //----------------------------------------------------------------------------------
  36. //----------------------------------------------------------------------------------
  37. // Draw
  38. //----------------------------------------------------------------------------------
  39. BeginDrawing();
  40. ClearBackground(RAYWHITE);
  41. DrawText(FormatText("%i",spritelibmap[0][0][0]),200,200,20,BLACK);
  42. DrawText(FormatText("%i",spritelibmap[20][10][10]),200,220,20,BLACK);
  43. EndDrawing();
  44. //----------------------------------------------------------------------------------
  45. }
  46. // De-Initialization
  47. //--------------------------------------------------------------------------------------
  48. CloseWindow(); // Close window and OpenGL context
  49. //--------------------------------------------------------------------------------------
  50. return 0;
  51. }