text_format_text.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*******************************************************************************************
  2. *
  3. * raylib [text] example - format text
  4. *
  5. * Example complexity rating: [★☆☆☆] 1/4
  6. *
  7. * Example originally created with raylib 1.1, last time updated with raylib 3.0
  8. *
  9. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  10. * BSD-like license that allows static linking with closed source software
  11. *
  12. * Copyright (c) 2014-2025 Ramon Santamaria (@raysan5)
  13. *
  14. ********************************************************************************************/
  15. #include "raylib.h"
  16. //------------------------------------------------------------------------------------
  17. // Program main entry point
  18. //------------------------------------------------------------------------------------
  19. int main(void)
  20. {
  21. // Initialization
  22. //--------------------------------------------------------------------------------------
  23. const int screenWidth = 800;
  24. const int screenHeight = 450;
  25. InitWindow(screenWidth, screenHeight, "raylib [text] example - format text");
  26. int score = 100020;
  27. int hiscore = 200450;
  28. int lives = 5;
  29. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  30. //--------------------------------------------------------------------------------------
  31. // Main game loop
  32. while (!WindowShouldClose()) // Detect window close button or ESC key
  33. {
  34. // Update
  35. //----------------------------------------------------------------------------------
  36. // TODO: Update your variables here
  37. //----------------------------------------------------------------------------------
  38. // Draw
  39. //----------------------------------------------------------------------------------
  40. BeginDrawing();
  41. ClearBackground(RAYWHITE);
  42. DrawText(TextFormat("Score: %08i", score), 200, 80, 20, RED);
  43. DrawText(TextFormat("HiScore: %08i", hiscore), 200, 120, 20, GREEN);
  44. DrawText(TextFormat("Lives: %02i", lives), 200, 160, 40, BLUE);
  45. DrawText(TextFormat("Elapsed Time: %02.02f ms", GetFrameTime()*1000), 200, 220, 20, BLACK);
  46. EndDrawing();
  47. //----------------------------------------------------------------------------------
  48. }
  49. // De-Initialization
  50. //--------------------------------------------------------------------------------------
  51. CloseWindow(); // Close window and OpenGL context
  52. //--------------------------------------------------------------------------------------
  53. return 0;
  54. }