Beginners_-_Array_Of_Strings.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "raylib.h"
  2. #include "string.h"
  3. #define MAX_ITEMS 10
  4. #define MAX_ITEMSSSIZE 32
  5. int main(void)
  6. {
  7. // Initialization
  8. //--------------------------------------------------------------------------------------
  9. const int screenWidth = 800;
  10. const int screenHeight = 450;
  11. InitWindow(screenWidth, screenHeight, "raylib example.");
  12. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  13. //--------------------------------------------------------------------------------------
  14. // Maxim number of items here is 9. End with 'End'
  15. char myitems[MAX_ITEMS][MAX_ITEMSSSIZE] = {
  16. "Sword",
  17. "Shield",
  18. "Axe",
  19. "Helmet",
  20. "End"
  21. };
  22. // Main game loop
  23. while (!WindowShouldClose()) // Detect window close button or ESC key
  24. {
  25. // Update
  26. //----------------------------------------------------------------------------------
  27. //----------------------------------------------------------------------------------
  28. // Draw
  29. //----------------------------------------------------------------------------------
  30. BeginDrawing();
  31. ClearBackground(RAYWHITE);
  32. // Draw the items on the screen and exit if the item is "End"
  33. DrawText("Inventory:",70,80,20,BLACK);
  34. for(int i=0;i<MAX_ITEMS-1;i++){
  35. DrawText(FormatText("%i",i),70,100+i*20,20,BLACK);
  36. DrawText(myitems[i],100,100+i*20,20,BLACK);
  37. if(strcmp(myitems[i+1],"End")==0)break;
  38. }
  39. EndDrawing();
  40. //----------------------------------------------------------------------------------
  41. }
  42. // De-Initialization
  43. //--------------------------------------------------------------------------------------
  44. CloseWindow(); // Close window and OpenGL context
  45. //--------------------------------------------------------------------------------------
  46. return 0;
  47. }