I have two different ways of doing this but wanted a second opinion.
This is pseudo-code so you get the basic understanding of what I'm doing.
First method (if player1 shoots and kills player2, then player2 calls its update function which calls the killfeed manager to display the updated killfeed onto the HUD)
Code: Select all
Player* Player1;
Player* Player2;
Player1->shoot(Player2);
/////Implementation of Player Class
Player::Update()
{
//do drawing stuff here rendered by Irrlicht
if(Player collides with bullet)
{
this->sethealth(-10);
if(this->gethealth() <=0)
{
this->died = true //Boolean
this->setKiller(Player1); //sets who killed player 2
this->getKillfeedManager()->displayBattleOutcome(Player1, this); //displays to the HUD that Player1 killed Player2
this->getKiller()->setScore(+10); //set Player1 score plus ten for killing Player2
}
}
}
Code: Select all
Killfeed* killfeedManager = new Killfeed;
/////Implementation of Killfeed Class
Killfeed::init()
{
std::vector<Player> PlayerList;
std::vector<Player>::iterator PlayerIterator;
for(int i = 0; i < this->getGameManager()->getNumberofPlayers(); ++i)
{
PlayerList.pushback(new Player); vector containing all the players
}
}
Killfeed::Update()
{
for(PlayerIterator = PlayerList.begin(); PlayerIterator != PlayerList.end(); ++PlayerIterator)
{
if(PlayerIterator->getHealth() <=0)
{
Killfeed->displayBattleOutcome((*PlayerIterator), PlayerIterator->getKiller());
}
}
}