First step was to define the state itself. I originally wanted it to be a structure, but later on decided it will be easier to manipulate the state if will be defined as a class. Reasoning along these lines, I created the following definition:
Code: Select all
class State
{
private:
const char* name;
int value;
bool enabled;
public:
State(const char* Name)
{
this->name=Name;
}
~State()
{
}
void Enable()
{
this->enabled=true;
}
void Disable()
{
this->enabled=false;
}
void Set(int Value)
{
this->value=Value;
}
const char* GetName()
{
return this->name;
}
int GetValue()
{
return this->value;
}
bool IsEnabled()
{
return this->enabled;
}
};
Code: Select all
std::list<State*> CurrentStates;
Code: Select all
void Character::AppendState(const char* name)
{
State* stat = new State(name);
stat->Disable();
stat->Set(0);
CurrentStates.push_back(stat);
}
State* Character::QueryState(const char* name)
{
std::list<State*>::iterator i;
for(i=CurrentStates.begin();i!=CurrentStates.end();i++)
{
if((*i)->GetName()==name) return (*i);
}
return NULL;
}
Code: Select all
void Character::WalkAndStop()
{
if(QueryState("isMoving")->IsEnabled())
{
//turn on the walking animation
}
That's all to it. The code was written in Code::Blocks, and tested in the application compiled with MinGW. I hope it will prove useful for the Irrlicht forum users.