killfeed update implementation

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply

Which method

Method 1
0
No votes
Method 2
2
100%
Method 3 (your own method if you have a better one)
0
No votes
 
Total votes: 2

thatdudeoverthere
Posts: 28
Joined: Fri Apr 24, 2009 2:43 pm
Location: over there...

killfeed update implementation

Post by thatdudeoverthere »

I was wondering how to update a killfeed, and by a "killfeed" i mean the little text in a corner of your HUD in a fps type game that tell the player who killed who and with which weapon, or if a player fell off the map, or lost network connection, etc.

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
       }
   }
}

Second method (Have the Killfeed Manager have a list of all the current players and check there health to see if it is less than 0)

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());
    }
  }
}
I'm debating which one looks nicer and/or cleaner and I don't think these two different methods will cause problems down the road, it's just that the first method will eventually make Player::Update() really clustered and not look like clean code
//Personal code

bool sarcasm;

void set_sarcastic()
{
sarcasm = true;
}
[img]
http://imgs.xkcd.com/comics/goto.png
[/img]
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

Could you please shrink your avatar? Looks like svn doesn`t auto resize or size-check the images used for avatars.

About your question, I`d use a manager keeping track of the events to display the needed info, meaning your second example is closer IMO.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
RageD
Posts: 34
Joined: Mon Jun 13, 2005 2:34 pm

Post by RageD »

I would use your second option. Obviously, the implementation will probably vary as you expand, but the code will definitely be simpler.

-RageD
DuF = (del)F.u
Microsonic Development
pepeshka
Posts: 29
Joined: Wed Jul 02, 2008 8:42 pm

Post by pepeshka »

I would suggest using an eventing system such that player::update just raises a "player x died" event with attached info (killer, etc) then recievers can catch and interpret that event - the killfeed would scroll itself to display he info, etc.
Post Reply