text_format_text.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Text formatting (adapted for HTML5 platform)
  4. *
  5. * This example has been created using raylib 1.3 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2015 Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. #if defined(PLATFORM_WEB)
  13. #include <emscripten/emscripten.h>
  14. #endif
  15. //----------------------------------------------------------------------------------
  16. // Global Variables Definition
  17. //----------------------------------------------------------------------------------
  18. int screenWidth = 800;
  19. int screenHeight = 450;
  20. int score = 100020;
  21. int hiscore = 200450;
  22. int lives = 5;
  23. //----------------------------------------------------------------------------------
  24. // Module Functions Declaration
  25. //----------------------------------------------------------------------------------
  26. void UpdateDrawFrame(void); // Update and Draw one frame
  27. //----------------------------------------------------------------------------------
  28. // Main Enry Point
  29. //----------------------------------------------------------------------------------
  30. int main()
  31. {
  32. // Initialization
  33. //--------------------------------------------------------------------------------------
  34. InitWindow(screenWidth, screenHeight, "raylib [text] example - text formatting");
  35. #if defined(PLATFORM_WEB)
  36. emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
  37. #else
  38. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  39. //--------------------------------------------------------------------------------------
  40. // Main game loop
  41. while (!WindowShouldClose()) // Detect window close button or ESC key
  42. {
  43. UpdateDrawFrame();
  44. }
  45. #endif
  46. // De-Initialization
  47. //--------------------------------------------------------------------------------------
  48. CloseWindow(); // Close window and OpenGL context
  49. //--------------------------------------------------------------------------------------
  50. return 0;
  51. }
  52. //----------------------------------------------------------------------------------
  53. // Module Functions Definition
  54. //----------------------------------------------------------------------------------
  55. void UpdateDrawFrame(void)
  56. {
  57. // Update
  58. //----------------------------------------------------------------------------------
  59. // TODO: Update your variables here
  60. //----------------------------------------------------------------------------------
  61. // Draw
  62. //----------------------------------------------------------------------------------
  63. BeginDrawing();
  64. ClearBackground(RAYWHITE);
  65. DrawText(FormatText("Score: %08i", score), 200, 80, 20, RED);
  66. DrawText(FormatText("HiScore: %08i", hiscore), 200, 120, 20, GREEN);
  67. DrawText(FormatText("Lives: %02i", lives), 200, 160, 40, BLUE);
  68. DrawText(FormatText("Elapsed Time: %02.02f ms", GetFrameTime()*1000), 200, 220, 20, BLACK);
  69. EndDrawing();
  70. //----------------------------------------------------------------------------------
  71. }