/**
 *  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 <cmath>
#include "Star.hpp"

Star::Star(const sf::Texture& texture, const sf::Texture& lightTexture, sf::Vector2f position): Lantern()
{
	light()->_emissionSprite.setPosition(position + sf::Vector2f(32.f, 32.f));
	light()->_emissionSprite.setTexture(lightTexture);
	light()->_emissionSprite.setOrigin(sf::Vector2f(lightTexture.getSize() / 2u));
	setPosition(position + sf::Vector2f(32.f, 32.f));
	setTexture(texture);
	setOrigin(sf::Vector2f(texture.getSize() / 2u));
}

bool Star::gravity(sf::Vector2f position, sf::Time time)
{
	light()->_emissionSprite.rotate(time.asSeconds() * 60.f);
	rotate(time.asSeconds() * 60.f);
	sf::Vector2f delta = position - light()->_emissionSprite.getPosition();
	if(delta.x > -1.f && delta.y > -1.f && delta.x < 1.f && delta.y < 1.f)
		return 1.f;
	return std::sqrt(delta.x * delta.x + delta.y * delta.y) <= 150;
}
