//	Puddle.cpp - The puddle class.
//  ----------------------------------------------------------------------------
//	This file is part of 'NiallsAVLib', base code for any kind of audiovisual
//	apps.
//	Copyright (C) 2012  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 "drawing/Drawer.h"
#include "MineModifiers.h"
#include "MiscHelper.h"
#include "Puddle.h"
#include "Tank.h"

//------------------------------------------------------------------------------
Puddle::Puddle(const TwoFloats& pos):
Collidable(L"Puddle"),
position(pos),
colour(0.53f, 0.45f, 1.0f),
puddleScale(0.0f),
currentMod(0),
modCount(22)
{
	
}

//------------------------------------------------------------------------------
Puddle::~Puddle()
{

}

//------------------------------------------------------------------------------
void Puddle::update()
{
	puddleScale += 0.05f;
	if(puddleScale > (2.0f*NIALL_PI))
		puddleScale -= (2.0f*NIALL_PI);

	--modCount;
	if(!modCount)
	{
		++currentMod;
		currentMod %= collisionModifiers.size();

		modCount = 22;
	}
}

//------------------------------------------------------------------------------
void Puddle::draw(shared_ptr<Drawer>& d, float timestepInterp)
{
	float scale = 1.0f + (sinf(puddleScale) * 0.08f);

	d->drawImage(L"Puddle",
				 position - (scale*42.0f),
				 scale,
				 collisionModifiers[currentMod]->getColour(),
				 0.66f);
}

//------------------------------------------------------------------------------
void Puddle::addCollisionModifier(shared_ptr<PuddleCollisionModifier> modifier)
{
	collisionModifiers.push_back(modifier);
}

//------------------------------------------------------------------------------
void Puddle::collideTank(Tank& tank, GamePlayState& state)
{
	collisionModifiers[currentMod]->collideTank(*this, tank, state);
}

//------------------------------------------------------------------------------
void Puddle::collideBullet(Bullet& bullet, GamePlayState& state)
{
	collisionModifiers[currentMod]->collideBullet(*this, bullet, state);
}

//------------------------------------------------------------------------------
void Puddle::collideZombie(Zombie& zombie, GamePlayState& state)
{
	collisionModifiers[currentMod]->collideZombie(*this, zombie, state);
}

//------------------------------------------------------------------------------
bool Puddle::interestedInCollisionsWith(const std::wstring& entity) const
{
	bool retval = false;

	if((entity == L"Tank") || (entity == L"Bullet") || (entity == L"Zombie"))
		retval = true;

	return retval;
}

//------------------------------------------------------------------------------
bool Puddle::collide(const shared_ptr<Collidable>& other, GamePlayState& state)
{
	bool retval = false;

	return retval;
}
