2
0

Beginners_-_StructDesignatedInitializer.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "raylib.h"
  2. struct unit{
  3. int empty;
  4. bool active;
  5. int x;
  6. int y;
  7. int damage;
  8. char name[10];
  9. };
  10. static struct unit myUnit = {.active = true, .x = 100, .y = 200, .name="hello"};
  11. int main(void)
  12. {
  13. // Initialization
  14. //--------------------------------------------------------------------------------------
  15. const int screenWidth = 800;
  16. const int screenHeight = 450;
  17. InitWindow(screenWidth, screenHeight, "raylib example.");
  18. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  19. //--------------------------------------------------------------------------------------
  20. // Main game loop
  21. while (!WindowShouldClose()) // Detect window close button or ESC key
  22. {
  23. // Update
  24. //----------------------------------------------------------------------------------
  25. //----------------------------------------------------------------------------------
  26. // Draw
  27. //----------------------------------------------------------------------------------
  28. BeginDrawing();
  29. ClearBackground(RAYWHITE);
  30. if(myUnit.active){
  31. DrawText("Active:true",100,200,20,BLACK);
  32. }
  33. DrawText(FormatText("This should be empty : %i",myUnit.empty),100,180,20,BLACK);
  34. DrawText(FormatText("%i , %i",myUnit.x,myUnit.y),100,220,20,BLACK);
  35. DrawText(FormatText("%s",myUnit.name),100,240,20,BLACK);
  36. EndDrawing();
  37. //----------------------------------------------------------------------------------
  38. }
  39. // De-Initialization
  40. //--------------------------------------------------------------------------------------
  41. CloseWindow(); // Close window and OpenGL context
  42. //--------------------------------------------------------------------------------------
  43. return 0;
  44. }