2
0

Beginners_-_Stack_Struct_Array.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "raylib.h"
  2. #include <stdlib.h>
  3. #define MAX_POINTS 1000
  4. #define MAX_BATCH_ELEMENTS 8192
  5. typedef struct Points{
  6. Vector2 position;
  7. } Points;
  8. int main(void)
  9. {
  10. // Initialization
  11. //--------------------------------------------------------------------------------------
  12. const int screenWidth = 800;
  13. const int screenHeight = 450;
  14. InitWindow(screenWidth, screenHeight, "raylib example.");
  15. Points *mypoint = (Points *)malloc(MAX_POINTS*sizeof(Points)); // Points array
  16. int pointscount = 10;
  17. for (int i=0;i<pointscount;i++){
  18. mypoint[i].position.x = GetRandomValue(0,100);
  19. mypoint[i].position.y = GetRandomValue(0,100);
  20. }
  21. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  22. //--------------------------------------------------------------------------------------
  23. // Main game loop
  24. while (!WindowShouldClose()) // Detect window close button or ESC key
  25. {
  26. // Update
  27. //----------------------------------------------------------------------------------
  28. //----------------------------------------------------------------------------------
  29. // Draw
  30. //----------------------------------------------------------------------------------
  31. BeginDrawing();
  32. ClearBackground(RAYWHITE);
  33. for(int i=0;i<pointscount;i++){
  34. DrawText(FormatText("x: %03f",mypoint[i].position.x), 50, 100+i*30, 20, BLACK);
  35. DrawText(FormatText("y: %03f",mypoint[i].position.y), 200, 100+i*30, 20, BLACK);
  36. }
  37. EndDrawing();
  38. //----------------------------------------------------------------------------------
  39. }
  40. // De-Initialization
  41. free(mypoint); // Unload points data array
  42. //--------------------------------------------------------------------------------------
  43. CloseWindow(); // Close window and OpenGL context
  44. //--------------------------------------------------------------------------------------
  45. return 0;
  46. }