Circle.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * Triangles
  3. * Copyright (C) 2016 POSITIVE MENTAL ATTITUDE
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, version 3 of the License.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "Circle.hpp"
  18. Circle::Circle(sf::Color color, float scale): _size(10)
  19. {
  20. _arc.resize(100);
  21. for(unsigned i = 0; i < 100; ++i)
  22. {
  23. _arc[i].setColor(color);
  24. _arc[i].setRotation(3.6f * i);
  25. _arc[i].setScale(scale, scale);
  26. }
  27. }
  28. Circle::~Circle()
  29. {
  30. _arc.clear();
  31. }
  32. void Circle::setTexture(sf::Texture& texture)
  33. {
  34. for(unsigned i = 0; i < 100; ++i)
  35. {
  36. _arc[i].setOrigin(texture.getSize().x / 2.f, 205.f);
  37. _arc[i].setTexture(texture);
  38. }
  39. }
  40. void Circle::setPosition(sf::Vector2f position)
  41. {
  42. for(unsigned i = 0; i < 100; ++i)
  43. _arc[i].setPosition(position);
  44. }
  45. void Circle::setPosition(float x, float y)
  46. {
  47. setPosition(sf::Vector2f(x, y));
  48. }
  49. void Circle::setRotation(float rotation)
  50. {
  51. for(unsigned i = 0; i < 100; ++i)
  52. _arc[i].setRotation(3.6f * i + rotation);
  53. }
  54. void Circle::rotate(float rotation)
  55. {
  56. for(unsigned i = 0; i < 100; ++i)
  57. _arc[i].rotate(rotation);
  58. }
  59. void Circle::setSize(unsigned size)
  60. {
  61. if(size <= 100)
  62. _size = size;
  63. }
  64. void Circle::show()
  65. {
  66. _elapsedTime = sf::Time::Zero;
  67. }
  68. void Circle::update(sf::Time delta)
  69. {
  70. _elapsedTime += delta;
  71. float seconds = _elapsedTime.asSeconds();
  72. if(seconds >= 2.75f && seconds < 3.f)
  73. {
  74. sf::Color color = _arc[0].getColor();
  75. color.a = int((3.f - _elapsedTime.asSeconds()) * 255 * 4);
  76. for(unsigned i = 0; i < _size; ++i)
  77. _arc[i].setColor(color);
  78. }
  79. else if(seconds >= 3.f)
  80. {
  81. sf::Color color = _arc[0].getColor();
  82. color.a = 255;
  83. for(unsigned i = 0; i < _size; ++i)
  84. _arc[i].setColor(color);
  85. }
  86. }
  87. void Circle::draw(sf::RenderTarget& target, sf::RenderStates states) const
  88. {
  89. if(_elapsedTime.asSeconds() >= 3.f)
  90. return;
  91. for(unsigned i = 0; i < _size; ++i)
  92. target.draw(_arc[i]);
  93. }