Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include "SDL.h"
  4.  
  5. using namespace std;
  6.  
  7. const int screen_width = 500;
  8. const int screen_height = 500;
  9.  
  10. int main(int argc, char ** argv)
  11. {
  12. SDL_Init(SDL_INIT_VIDEO);
  13. SDL_Window *window = SDL_CreateWindow("SDLDEMOSCENE", 50, 50, screen_width, screen_height, SDL_WINDOW_SHOWN);
  14. SDL_Renderer *renderer = SDL_CreateRenderer(window, 0, SDL_RENDERER_ACCELERATED);
  15.  
  16. SDL_Rect rectangle, rectangle2;
  17.  
  18. double rect1_x = screen_width / 2;
  19. double rect1_y = screen_height / 2;
  20. double rect1_width = 5;
  21. double rect1_height = 5;
  22.  
  23. double rect2_x = screen_width / 2;
  24. double rect2_y = screen_height / 2;
  25. double rect2_width = 5;
  26. double rect2_height = 5;
  27.  
  28.  
  29.  
  30. bool quit = false;
  31.  
  32. while (quit == false)
  33. {
  34. SDL_Event event;
  35. while (SDL_PollEvent(&event))
  36. {
  37. if (event.type == SDL_QUIT)
  38. {
  39. quit = true;
  40. }
  41. }
  42.  
  43. rectangle.x = rect1_x;
  44. rectangle.y = rect1_y;
  45. rectangle.h = rect1_height;
  46. rectangle.w = rect1_width;
  47.  
  48. rectangle2.x = rect2_x;
  49. rectangle2.y = rect2_y;
  50. rectangle2.h = rect2_height;
  51. rectangle2.w = rect2_width;
  52.  
  53.  
  54. SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
  55. SDL_RenderFillRect(renderer, &rectangle);
  56.  
  57. rect1_x -= 0.01;
  58. rect1_y -= 0.01;
  59. rect1_width += 0.02;
  60. rect1_height += 0.02;
  61.  
  62. if (rect1_x < 200 || rect1_y < 200)
  63. {
  64. SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
  65. SDL_RenderFillRect(renderer, &rectangle2);
  66.  
  67. rect2_x -= 0.01;
  68. rect2_y -= 0.01;
  69. rect2_width += 0.02;
  70. rect2_height += 0.02;
  71. }
  72.  
  73. if (rect2_x < 0 || rect2_y < 0)
  74. {
  75. rect2_height = 0;
  76. rect2_width = 0;
  77. rect2_x = 250;
  78. rect2_y = 250;
  79. rect1_height = 5;
  80. rect1_width = 5;
  81. rect1_x = 250;
  82. rect1_y = 250;
  83. }
  84.  
  85.  
  86.  
  87. SDL_RenderPresent(renderer);
  88. }
  89.  
  90. SDL_Quit();
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement