//	Player.cpp - The player's deflector thing.
//  ----------------------------------------------------------------------------
//	This file is part of 'GameTemplate', template code for a game.
//	Copyright (C) 2011  Niall Moody
//	
//	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, either version 3 of the License, or
//	(at your option) any later version.
//
//	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 "Player.h"
#include "drawing/Drawer.h"

#include <cmath>

//------------------------------------------------------------------------------
Player::Player():
position(64.0f, 360.0f),
deflecting(false),
attracting(false),
deflectScale(0.0f)
{
	
}

//------------------------------------------------------------------------------
Player::~Player()
{
	
}

//------------------------------------------------------------------------------
void Player::draw(DrawerPtr& d)
{
	/*if(deflecting && !attracting)
	{
		deflectScale += 0.075f;
		if(deflectScale > 6.283185f)
			deflectScale = fmodf(deflectScale, 6.283185f);
		tempf = sinf(deflectScale); //-1 -> +1
		tempf += 2.0f; //1 -> 3

		d->drawImage(deflectorImage,
					 position.x-(32*tempf),
					 position.y-(32*tempf),
					 tempf,
					 tempf,
					 0.25f,
					 0.6640625f,
					 0.6484375f,
					 0.5f);
	}
	else if(attracting && !deflecting)
	{
		deflectScale += 0.075f;
		if(deflectScale > 6.283185f)
			deflectScale = fmodf(deflectScale, 6.283185f);
		tempf = sinf(deflectScale); //-1 -> +1
		tempf += 2.0f; //1 -> 3

		d->drawImage(deflectorImage,
					 position.x-(32*tempf),
					 position.y-(32*tempf),
					 tempf,
					 tempf,
					 0.6640625f,
					 0.6484375f,
					 0.25f,
					 0.5f);
	}*/

	d->drawImage(L"mouse",
				 TwoFloats(position-13),
				 TwoFloats(1.0f),
				 ThreeFloats(0.5f));
}

//------------------------------------------------------------------------------
void Player::mouseMove(const TwoFloats& pos)
{
	position = pos;
}

//------------------------------------------------------------------------------
void Player::mouseDown(int button)
{
	if(button == 3)
	{
		deflecting = true;
		if(!attracting)
			deflectScale = 0.0f;
	}
	else if(button == 1)
	{
		attracting = true;
		if(!deflecting)
			deflectScale = 0.0f;
	}
}

//------------------------------------------------------------------------------
void Player::mouseUp(int button)
{
	if(button == 3)
		deflecting = false;
	else if(button == 1)
		attracting = false;
}
