Greetings,
I am creating a 2d puzzle game inspired by Talos Principle, I don't have much to show but still here it is...
-Doors are working perfectly
-Jammer needs fixing
-The box has no purpose
-The sphere(enemy) is half done, it detects the player and reacts to it. In the future it will start to warm up for 2 seconds and if the player is still in the range it will shoot him. The range is currently drawn around it for testing purposes.
Currently I am working on the jammer ray collision with walls, I was planing on asking for an advice but I just got an idea.
Here is the video
All placeholders are drawn by me, except the jammer, and if you want to use them just ask, I'll upload them
The jammer is a mushroom from Super Mario, on which I redraw that ugly thing.
I don't have much experience with inheritance, and if anybody can give me some tips on this, it would be great.
I have a base class BaseObject and all object derive from it.
I have a vector of unique_ptr to BaseObject containing all objects except the player and walls.
When i try to access a function from derived class I get an error, to solve this I cast it to desired type.
The question is: how would look the correct usage of std::vector<unique_ptr<BaseObject> > so that I can access the derived class functions without casting them? Or is this acceptable design?
My code looks like this:
std::vector<std::unique_ptr<BaseObject>> m_objects;
m_objectContainer.emplace_back(new Jammer("jammer.png", sf::Vector2f(0, 0)));
for(int i=0; i<m_objects[i];++i)
{
m_object[i]->derivedClassFunction();
//Error base class doesn't have derivedClassFunction()
if(m_objects[i]->type() == objectType::Jammer)
{
Jammer* tempJammer = dynamic_cast<Jammer*>(m_object[i].get());
if(tempJammer != nullptr)
{
tempJammer->derivedClassFunction();
//OK
}
}
}