Beginners_-_voidFunctions.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "raylib.h"
  2. // Let the compiler know we are using a function outside the main function.
  3. void drawmessage(int x,int y);
  4. int main(void)
  5. {
  6. // Initialization
  7. //--------------------------------------------------------------------------------------
  8. const int screenWidth = 800;
  9. const int screenHeight = 450;
  10. InitWindow(screenWidth, screenHeight, "raylib example.");
  11. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  12. //--------------------------------------------------------------------------------------
  13. // Main game loop
  14. while (!WindowShouldClose()) // Detect window close button or ESC key
  15. {
  16. // Update
  17. //----------------------------------------------------------------------------------
  18. //----------------------------------------------------------------------------------
  19. // Draw
  20. //----------------------------------------------------------------------------------
  21. BeginDrawing();
  22. ClearBackground(RAYWHITE);
  23. // Here we use the function that is outside our main function.
  24. drawmessage(100,100);
  25. EndDrawing();
  26. //----------------------------------------------------------------------------------
  27. }
  28. // De-Initialization
  29. //--------------------------------------------------------------------------------------
  30. CloseWindow(); // Close window and OpenGL context
  31. //--------------------------------------------------------------------------------------
  32. return 0;
  33. }
  34. // This is our function
  35. // It is outside the main function.
  36. // void means it returns nothing.
  37. void drawmessage(int x,int y){
  38. DrawText("Hello World.",x,y,20,BLACK);
  39. }