Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. class Game : public Engine
  2. {
  3. struct Shape
  4. {
  5. Shape(std::vector<Vector2> _points,Color _color,int _thickness,float _inc)
  6. {
  7. points = _points;
  8. color = _color;
  9. thickness = _thickness;
  10. inc = _inc;
  11. }
  12. Shape(){
  13. points = {};
  14. color = Color::White;
  15. thickness = 1;
  16. inc = 0.1f;
  17. }
  18. std::vector<Vector2> points{};
  19. Color color;
  20. int thickness;
  21. float inc;
  22. void draw(Drawer& drawer)
  23. {
  24. if(points.size() < 2 || inc <= 0) return;
  25.  
  26. std::vector<Vector2> newP = points;
  27. float dist = (newP[0]-newP[1]).length() * inc;
  28. for(size_t i = 0; i < newP.size(); i++)
  29. {
  30. drawer.drawLine(
  31. newP[i],
  32. i+1 == newP.size() ? newP[0] :newP[i+1],
  33. color,
  34. thickness
  35. );
  36. }
  37. while(true)
  38. {
  39. if((newP[0]-newP[1]).length() < dist){ break; }
  40.  
  41. for(size_t i = 0; i < newP.size(); i++)
  42. {
  43. newP[i] += ((i+1 == newP.size() ? newP[0] :newP[i+1]) - newP[i]) * inc;
  44. drawer.drawLine(
  45. i == 0 ? newP[newP.size()-1] : newP[i-1],
  46. newP[i],
  47. color,
  48. thickness
  49. );
  50. }
  51. }
  52. }
  53. };
  54.  
  55. std::vector<Shape> shapes{};
  56. Shape currentShape {};
  57. void Initialize()
  58. {
  59. apis.graphicsAPI = GraphicsAPI::OpenGL;
  60. apis.graphicsAPI.OpenGLVer = 4.5;
  61. apis.windowAPI = WindowAPI::Android;
  62. apis.audioAPI = AudioAPI::NoAPI;
  63. apis.graphicsAPI.maxFramesInFlight = 3;
  64.  
  65. //properties.allowResizing = false;
  66. //properties.windowSize = { 500, 500 };
  67. properties.maxUPS = 144;
  68. //properties.maxFPS = 0;
  69. properties.maxFPS = 60;
  70. properties.windowName = "Shapes!";
  71.  
  72. //addShader(shader_wiggly);
  73.  
  74. shapes.push_back(Shape( {{100,100}, {200,100}, {200,200}, {100,200}} ,Color::Blue, 1, 0.1f));
  75. shapes.push_back(Shape( {{200,100}, {200,200}, {300,200}, {300,100}} ,Color::Blue, 1, 0.1f));
  76. shapes.push_back(Shape( {{150,300}, {200,200}, {100,200} } ,Color::Blue, 1, 0.1f));
  77. currentShape.color = Color::Red;
  78. }
  79.  
  80. void Load()
  81. {
  82. //setIcon("resources/icon.bmp");
  83. }
  84.  
  85. void Update(double deltaT)
  86. {
  87. (void)deltaT;
  88. if(input.isKeyboardKeyDown(KK::Q)){
  89. Exit();
  90. }
  91.  
  92. if(input.isMouseKeyClicked(MK::LMB))
  93. {
  94. currentShape.points.push_back(input.getMousePosition());
  95. }
  96.  
  97. if(input.isMouseKeyClicked(MK::RMB))
  98. {
  99. currentShape.color = Color::Blue;
  100. shapes.push_back(currentShape);
  101. currentShape = Shape{};
  102. currentShape.color = Color::Red;
  103. }
  104.  
  105. if(input.getScrollAmount() != 0)
  106. {
  107. currentShape.inc += 0.002f * input.getScrollAmount();
  108. }
  109.  
  110. if(input.isKeyboardKeyClicked(KK::D))
  111. {
  112. shapes.clear();
  113. }
  114. }
  115.  
  116. void Draw(double deltaT)
  117. {
  118. drawer.clear();
  119. drawer.drawText(std::to_string((int)(1/deltaT)), Ubuntu_Font32 , { 0, 0 },{ 0.5f, 0.5f },Color::Green);
  120. for (auto& shape : shapes)
  121. {
  122. shape.draw(drawer);
  123. }
  124. currentShape.draw(drawer);
  125. }
  126.  
  127. void OnClose()
  128. {
  129. printf("Program closed successfully!\n");
  130. }
  131. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement