//---------------------------
// Includes
//---------------------------
#include "StdAfx.h"
#include "Food.h"
#include "BarrelList.h"
#include "Painter.h"
#include "ResourceLoader.h"
#include "InputState.h"
#include "CollisionMesh.h"
#include "Image.h"

//---------------------------
// Constructor & Destructor
//---------------------------
BarrelList::BarrelList(): ItemList()
{
}

BarrelList::~BarrelList()
{
	// Deletes all the elements in the array, 
	// Uses the RemoveAll method
	this->RemoveAll();
}

//---------------------------
// Own methods
//---------------------------

void BarrelList::HitTest(Character* character)
{
	// Searches in the list for a Barrel that hits the given character
	// When a Barrel hits the character, the barrel will change it's state and the state of the character

	for(int i = 0; i < MAX_NR_OF_ITEMS;++i)
	{
		if(m_ItemPtrArr[i] != 0)
		{
			m_ItemPtrArr[i]->HitTest(character);
		}
	}
}

void BarrelList::KeyUp(TCHAR cKey)
{
	for(int i = 0; i < MAX_NR_OF_ITEMS;++i)
	{
		if(m_ItemPtrArr[i] != 0)
		{
			// Casts the superClass Item to the subClass barrel, in order to use the KeyUp method of this class
			Barrel *barrel = dynamic_cast<Barrel *>( m_ItemPtrArr[i]);
			if(barrel != NULL)
			{
				barrel->KeyUp(cKey);
			}
		}
	}
}

void BarrelList::CheckCollision(LevelProp *levelProp, InputState *inputStatePtr) const
{
	for(int i = 0; i < MAX_NR_OF_ITEMS;++i)
	{
		if(m_ItemPtrArr[i] != 0)
		{
			levelProp->CheckCollision(m_ItemPtrArr[i],inputStatePtr);
		}
	}
}