Advertisement
janducev

Untitled

Nov 25th, 2019
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 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(void)
  25. {
  26. // Initialization
  27. //--------------------------------------------------------------------------------------
  28.  
  29.  
  30. const int screenWidth = 800;
  31. const int screenHeight = 450;
  32.  
  33. const int spriteWidth = 32;
  34. const int spriteHeight = 32;
  35.  
  36. InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
  37.  
  38. Texture2D characters = LoadTexture("Resources/characters.png");
  39.  
  40. Rectangle sourceRec;
  41. sourceRec.x = 0;
  42. sourceRec.y = 0;
  43. sourceRec.width = spriteWidth; // 32
  44. sourceRec.height = spriteHeight; //32
  45.  
  46. Rectangle destinationRec;
  47. destinationRec.x = screenWidth/2 - spriteWidth/2;
  48. destinationRec.y = screenHeight/2 - spriteHeight/2;
  49. destinationRec.width = sourceRec.width;
  50. destinationRec.height = sourceRec.height;
  51.  
  52. Vector2 origin;
  53. origin.x = 0;
  54. origin.y = 0;
  55.  
  56. int framesCounter = 0;
  57.  
  58.  
  59. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  60. //--------------------------------------------------------------------------------------
  61.  
  62. // Main game loop
  63. while (!WindowShouldClose()) // Detect window close button or ESC key
  64. {
  65. // Update
  66. //----------------------------------------------------------------------------------
  67. // TODO: Update your variables here
  68. //----------------------------------------------------------------------------------
  69. framesCounter++;
  70.  
  71. if (framesCounter >= 6)
  72. {
  73. if (sourceRec.x > characters.width)
  74. {
  75. sourceRec.x = 0;
  76. }
  77. framesCounter = 0;
  78. sourceRec.x += spriteWidth;
  79.  
  80. }
  81.  
  82. // Draw
  83. //----------------------------------------------------------------------------------
  84. BeginDrawing();
  85.  
  86. ClearBackground(RAYWHITE);
  87.  
  88. DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
  89.  
  90. DrawTexturePro(characters, sourceRec, destinationRec, origin, 0, WHITE);
  91.  
  92. DrawTexture(characters, 0, 0, WHITE);
  93.  
  94. EndDrawing();
  95. //----------------------------------------------------------------------------------
  96. }
  97.  
  98. // De-Initialization
  99. //--------------------------------------------------------------------------------------
  100. UnloadTexture(characters);
  101.  
  102. CloseWindow(); // Close window and OpenGL context
  103. //--------------------------------------------------------------------------------------
  104.  
  105. return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement