//	RetaliatingWalls.cpp - When a bullet hits a wall, it retaliates by firing
//						   another bullet.
//  ----------------------------------------------------------------------------
//	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 "RetaliatingWalls.h"
#include "GamePlayState.h"
#include "Bullet.h"

//------------------------------------------------------------------------------
BulletCollisionCreator<RetaliatingWalls> RetaliatingWalls::creator;

//------------------------------------------------------------------------------
RetaliatingWalls::RetaliatingWalls()
{

}

//------------------------------------------------------------------------------
RetaliatingWalls::~RetaliatingWalls()
{

}

//------------------------------------------------------------------------------
void RetaliatingWalls::wallCollide(Bullet& bullet,
								   GamePlayState& state,
								   const shared_ptr<Collidable>& wall)
{
	float tempf;
	TwoFloats tempDir;
	ThreeFloats tempCol;
	const TwoFloats& drawSize(state.getDrawingAreaSize());
	const ThreeFloats& leftCol(state.getLeftBorderColour());
	const ThreeFloats& rightCol(state.getRightBorderColour());

	tempDir = (bullet.getPosition() - wall->getPosition()).normal();
	tempf = bullet.getPosition().x/drawSize.x;
	tempCol = leftCol + (tempf * (rightCol-leftCol));

	state.firePlainBullet(bullet.getPosition()+(tempDir*12.0f),
						  tempDir,
						  tempCol,
						  L"Wall");
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void RetaliatingWallsCreator::apply(GamePlayState& state)
{
	state.getBulletCreator().addCollisionModifier(&RetaliatingWalls::creator);
}
