
#include "Cell.h"

// Cell sets
void Cell::set_layer(unsigned short newlayer, unsigned short p)
{
layer[p] = newlayer;
}
void Cell::set_value(unsigned short newvalue, unsigned short p)
{
value[p] = newvalue;
}
void Cell::set_tileset(unsigned short newtileset, unsigned short p)
{
tileset[p] = newtileset;
}
void Cell::set_passable(unsigned short newpassable, unsigned short p)
{
passable[p] = newpassable;
}
void Cell::set_trans(unsigned short newtrans, unsigned short p)
{
trans[p] = newtrans;
}
//// Cell construtor
Cell::Cell()
{
 for(int p = 0; p<leves; p++)
 {
passable[p]=0;
layer[p]=p+1;
trans[p]=0;
value[p]=247;
 animated[p]= false;
triger[p]=false;
speed[p]=0;
 conter[p]=0;
 frame[p]=1;
animate_id[p]=0;
 }
 value[0]=34;
speed[0]=100;
}
//Cell gets
unsigned short Cell::get_layer(unsigned short p)
{
return layer[p] ;
}
unsigned short Cell::get_value(unsigned short p)
{
return value[p] ;
}
unsigned short Cell::get_tileset(unsigned short p)
{
return tileset[p] ;
}
unsigned short Cell::get_passable(unsigned short p)
{
return passable[p];
}
unsigned short Cell::get_trans(unsigned short p)
{
return trans[p] ;
}




void Cell::animate(TileAnimeList animations)
{
	for(int p = 0; p<leves; p++)
 {
	if(value[p]==113)//grass tile
	{

		//need a way to set animate_id in editer
	    animated[p]=true;
		animate_id[p] = 1;
	}
	else if(value[p]==34)
	{
animated[p]=false;//temp bug fix
	}
	


if (animated[p] == true)
	{
	
		if(conter[p] < speed[p])
			{
				conter[p]++;

			}
			else
			{
			

				value[p] = animations.Find_animate_id( animate_id[p] , frame[p] );
				
				if (frame[p]<5)
					{
						frame[p]++;
					}
					else
					{
					frame[p]=1;
					}
					
			conter[p]=0;
			}

	//animations.save();
	}
	}
	
}