123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- /**
- * Triangles
- * Copyright (C) 2016 POSITIVE MENTAL ATTITUDE
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "Circle.hpp"
- Circle::Circle(sf::Color color, float scale): _size(10)
- {
- _arc.resize(100);
- for(unsigned i = 0; i < 100; ++i)
- {
- _arc[i].setColor(color);
- _arc[i].setRotation(3.6f * i);
- _arc[i].setScale(scale, scale);
- }
- }
- Circle::~Circle()
- {
- _arc.clear();
- }
- void Circle::setTexture(sf::Texture& texture)
- {
- for(unsigned i = 0; i < 100; ++i)
- {
- _arc[i].setOrigin(texture.getSize().x / 2.f, 205.f);
- _arc[i].setTexture(texture);
- }
- }
- void Circle::setPosition(sf::Vector2f position)
- {
- for(unsigned i = 0; i < 100; ++i)
- _arc[i].setPosition(position);
- }
- void Circle::setPosition(float x, float y)
- {
- setPosition(sf::Vector2f(x, y));
- }
- void Circle::setRotation(float rotation)
- {
- for(unsigned i = 0; i < 100; ++i)
- _arc[i].setRotation(3.6f * i + rotation);
- }
- void Circle::rotate(float rotation)
- {
- for(unsigned i = 0; i < 100; ++i)
- _arc[i].rotate(rotation);
- }
- void Circle::setSize(unsigned size)
- {
- if(size <= 100)
- _size = size;
- }
- void Circle::show()
- {
- _elapsedTime = sf::Time::Zero;
- }
- void Circle::update(sf::Time delta)
- {
- _elapsedTime += delta;
- float seconds = _elapsedTime.asSeconds();
- if(seconds >= 2.75f && seconds < 3.f)
- {
- sf::Color color = _arc[0].getColor();
- color.a = int((3.f - _elapsedTime.asSeconds()) * 255 * 4);
- for(unsigned i = 0; i < _size; ++i)
- _arc[i].setColor(color);
- }
- else if(seconds >= 3.f)
- {
- sf::Color color = _arc[0].getColor();
- color.a = 255;
- for(unsigned i = 0; i < _size; ++i)
- _arc[i].setColor(color);
- }
- }
- void Circle::draw(sf::RenderTarget& target, sf::RenderStates states) const
- {
- if(_elapsedTime.asSeconds() >= 3.f)
- return;
- for(unsigned i = 0; i < _size; ++i)
- target.draw(_arc[i]);
- }
|