1
General / Re: Game Design / Programming Design help
« on: September 08, 2021, 06:25:32 am »
UPDATE
Got a version working, but since I'm inexperienced with smart pointers I'd appreciate input on my new-found solution.
Got a version working, but since I'm inexperienced with smart pointers I'd appreciate input on my new-found solution.
std::vector<Ammunition*>& Weapon::getShots() {
ghostPTR.clear();
for (auto&& ammo : m_Shots)
ghostPTR.push_back(ammo.get());
return ghostPTR;
}
std::vector<Ammunition*>& Ship::getShots() {
ghostPTR.clear();
for (auto&& weapon : m_Weapons)
for (auto&& ammo : weapon->getShots())
ghostPTR.push_back(ammo);
return ghostPTR;
}
// And lastly the game class
void Level::update(const sf::Time& deltaTime) {
std::vector<Ammunition*> ammunition;
for (auto&& entity : m_Entities)
if (Ship* ptr = dynamic_cast<Ship*>(entity.get()); ptr)
ammunition.insert(ammunition.begin(), ptr->getShots().begin(),ptr->getShots().end());
}
ghostPTR.clear();
for (auto&& ammo : m_Shots)
ghostPTR.push_back(ammo.get());
return ghostPTR;
}
std::vector<Ammunition*>& Ship::getShots() {
ghostPTR.clear();
for (auto&& weapon : m_Weapons)
for (auto&& ammo : weapon->getShots())
ghostPTR.push_back(ammo);
return ghostPTR;
}
// And lastly the game class
void Level::update(const sf::Time& deltaTime) {
std::vector<Ammunition*> ammunition;
for (auto&& entity : m_Entities)
if (Ship* ptr = dynamic_cast<Ship*>(entity.get()); ptr)
ammunition.insert(ammunition.begin(), ptr->getShots().begin(),ptr->getShots().end());
}