Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Basic window
  4. *
  5. * Welcome to raylib!
  6. *
  7. * To test examples, just press F6 and execute raylib_compile_execute script
  8. * Note that compiled executable is placed in the same folder as .c file
  9. *
  10. * You can find all basic examples on C:\raylib\raylib\examples folder or
  11. * raylib official webpage: www.raylib.com
  12. *
  13. * Enjoy using raylib. :)
  14. *
  15. * This example has been created using raylib 1.0 (www.raylib.com)
  16. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  17. *
  18. * Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
  19. *
  20. ********************************************************************************************/
  21.  
  22. #include "raylib.h"
  23.  
  24. int main()
  25. {
  26. // Initialization
  27. //--------------------------------------------------------------------------------------
  28. int screenWidth = 800;
  29. int screenHeight = 450;
  30.  
  31. InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
  32.  
  33. Rectangle rec = {0, 0, screenWidth, screenHeight};
  34. Color recColor = BLACK;
  35.  
  36. bool fadeOut = true;
  37. float alpha = 0;
  38. float fadeSpeed = 0.01f;
  39.  
  40. SetTargetFPS(60);
  41. //--------------------------------------------------------------------------------------
  42.  
  43. // Main game loop
  44. while (!WindowShouldClose()) // Detect window close button or ESC key
  45. {
  46. // Update
  47. //----------------------------------------------------------------------------------
  48. // TODO: Update your variables here
  49. if(fadeOut)
  50. {
  51. alpha += fadeSpeed;
  52.  
  53. if(alpha >= 1.0f)
  54. {
  55. alpha = 1.0f;
  56. }
  57. }
  58. else
  59. {
  60. alpha -= fadeSpeed;
  61. if(alpha <= 0.0f)
  62. {
  63. alpha = 0.0f;
  64. }
  65. }
  66.  
  67. if(IsKeyPressed(KEY_SPACE))
  68. {
  69. fadeOut = !fadeOut;
  70. }
  71. //----------------------------------------------------------------------------------
  72.  
  73. // Draw
  74. //----------------------------------------------------------------------------------
  75. BeginDrawing();
  76.  
  77. ClearBackground(RAYWHITE);
  78.  
  79. DrawRectangleRec(rec, Fade(recColor, alpha));
  80.  
  81. DrawText(FormatText("%f", alpha), 10,10, 20, WHITE);
  82.  
  83.  
  84. EndDrawing();
  85. //----------------------------------------------------------------------------------
  86. }
  87.  
  88. // De-Initialization
  89. //--------------------------------------------------------------------------------------
  90. CloseWindow(); // Close window and OpenGL context
  91. //--------------------------------------------------------------------------------------
  92.  
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement