2
0

Example_-_ArrayToCode-Paste.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "raylib.h"
  2. #include <string.h>
  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. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  11. //--------------------------------------------------------------------------------------
  12. int spritewidth = 8;
  13. int spriteheight = 8;
  14. int sprite[8][8] = {{1,1,1,1,0,0,0,9},
  15. {0,1,1,1,0,0,0,0},
  16. {0,0,1,1,1,2,2,2},
  17. {0,0,0,1,1,2,2,2},
  18. {0,0,0,1,1,2,2,2},
  19. {1,1,1,1,1,2,2,2},
  20. {0,0,1,1,1,2,2,2},
  21. {0,0,0,0,0,2,2,2}};
  22. // Here we create a copy and paste ready
  23. // text that can be pasted into a code editor.
  24. // It shows how to convert a array into c language code.
  25. char output1[1000] = "int sprite[";
  26. char output2[32];
  27. sprintf(output2, "%d", spritewidth);
  28. strcat(output1,output2);
  29. strcat(output1,"][");
  30. sprintf(output2, "%d", spriteheight);
  31. strcat(output1,output2);
  32. strcat(output1,"] = {\n");
  33. int x=0;int y=0;
  34. for (y=0;y<spriteheight;y++){
  35. for(x=0;x<spritewidth-1;x++){
  36. if(x==0)strcat(output1,"{");
  37. char num[16];
  38. sprintf(num, "%d", sprite[y][x]);
  39. strcat(output1,num);
  40. strcat(output1,",");
  41. }
  42. char num2[16];
  43. sprintf(num2, "%d", sprite[y][spritewidth-1]);
  44. strcat(output1,num2);
  45. if(y<spriteheight-1){
  46. strcat(output1,"},\n");
  47. }else{
  48. strcat(output1,"}};\n");
  49. }
  50. }
  51. SetClipboardText(output1);
  52. // Main game loop
  53. while (!WindowShouldClose()) // Detect window close button or ESC key
  54. {
  55. // Update
  56. //----------------------------------------------------------------------------------
  57. //----------------------------------------------------------------------------------
  58. // Draw
  59. //----------------------------------------------------------------------------------
  60. BeginDrawing();
  61. ClearBackground(RAYWHITE);
  62. DrawText("Check your clipboard buffer CTRL+V",50,100,20,DARKGRAY);
  63. EndDrawing();
  64. //----------------------------------------------------------------------------------
  65. }
  66. // De-Initialization
  67. //--------------------------------------------------------------------------------------
  68. CloseWindow(); // Close window and OpenGL context
  69. //--------------------------------------------------------------------------------------
  70. return 0;
  71. }