#include "Portal.hpp"
#include "Echo.hpp"
#include "Shared.hpp"

Texture Portal::_blue_tex;
Texture Portal::_orange_tex;

void Portal::create(Shared* context, Vector2i src, Vector2i dest)
{
	if(_blue_tex.getSize().x == 0) {
		 _blue_tex.loadFromFile("data/blueportal.png");
	}
	_blue.setTexture(_blue_tex);
	_blue.setTextureRect(IntRect(0, 0, 16, 32));
	_blue.setPosition(src.x * 16, src.y * 16 - 16);
	context->tpa.push_back(src);

	if(_orange_tex.getSize().x == 0) {
		_orange_tex.loadFromFile("data/orangeportal.png");
   }
   _orange.setTexture(_orange_tex);
   _orange.setTextureRect(IntRect(0, 0, 16, 32));
   _orange.setPosition(dest.x * 16, dest.y * 16 - 16);
   context->tpb.push_back(dest);
}
void Portal::animate()
{
	if(_clock.getElapsedTime().asSeconds() > 0.5f) {
		_blue.setTextureRect(IntRect((_blue.getTextureRect().left + 16) % 64, 0, 16, 32));
		_orange.setTextureRect(IntRect((_blue.getTextureRect().left + 16) % 64, 0, 16, 32));
		_clock.restart();
	}
}
void Portal::draw(RenderTarget& target, RenderStates states) const {
	target.draw(_blue, states);
	target.draw(_orange, states);
}
