Hello.
What i am doing is a Class that is called "Interact", the point of class is to allow for type checking.
I am making 2d tile map, and i want to allow for player to "Interact" with map as in(case isBerryBush = harvest)(case Stone = mine(check if item(Pickaxe...)))
I hope i had provided you with what my idea is.
What i am having in mind
//Type of "Addon" on tile (BerryBush, Stone...)
int GetAddonType(TileClass &tile)//TileClass::Addon is defined as int
switch(tile.Addon)
{
type::BerryBush: return my_enum::Hand; break;
type::Stone: return my_enum::Hacking; break;//As in swing to use
}
//Has tool for
bool HasToolFor(my_enum type)
{
//Check player inventory if he has tool
}
//Is the tile ready for harvest
bool IsReadyForHarvest(int TileID)
{
//Returns if the tile has grown since last harvest/planting...
}
//Somewhere in main loop
if(Interact == pressed)//Ilustration
{
if(GetAddonType(CurrentTileStandingOn) == Hand)
{
if(IsReadyForHarvest(CurrentTileStandingOn) == true)
{
//Add item to inventory, set tile to harvested...
}
}
else if(GetAddonType(CurrentTileStandingOn) == HackingHand)
{
if(IsReadyForHarvest(CurrentTileStandingOn) == true)
{
if(HasToolFor(GetAddonType(CurrentTileStandingOn)) == true)
{
//Add item to inventory, set tile to harvested...
}
}
}
}
The issues with this is that its syntax is horrible imo.
Wanna share a better way? pretty please!