2
0

Beginners_-_Pass_Array_Function.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "raylib.h"
  2. void passarray(Vector2 pol[]);
  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. // Main game loop
  13. while (!WindowShouldClose()) // Detect window close button or ESC key
  14. {
  15. // Update
  16. //----------------------------------------------------------------------------------
  17. //----------------------------------------------------------------------------------
  18. // Draw
  19. //----------------------------------------------------------------------------------
  20. BeginDrawing();
  21. ClearBackground(RAYWHITE);
  22. //
  23. // Create a Vector2 array and create some points in it
  24. //
  25. Vector2 pol[3];
  26. pol[0] = (Vector2){100,100};
  27. pol[1] = (Vector2){20,300};
  28. pol[2] = (Vector2){180,300};
  29. //
  30. // Here we pass the Vector2 array into the function.
  31. passarray(pol);
  32. EndDrawing();
  33. //----------------------------------------------------------------------------------
  34. }
  35. // De-Initialization
  36. //--------------------------------------------------------------------------------------
  37. CloseWindow(); // Close window and OpenGL context
  38. //--------------------------------------------------------------------------------------
  39. return 0;
  40. }
  41. //
  42. // Fonction that takes a array of Vector2 for use in the function.
  43. void passarray(Vector2 pol[]){
  44. // Draw a triangle.
  45. DrawTriangle(pol[0],pol[1],pol[2],RED);
  46. }