Changeset 5b92307 in network-game for common/Player.cpp


Ignore:
Timestamp:
Jan 20, 2014, 6:47:58 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
204edcf
Parents:
949cf70
Message:

id and targetPlayer are now both private members of the Player class and have getters and setters to access them

File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/Player.cpp

    r949cf70 r5b92307  
    1515   this->pos.x = this->target.x = 0;
    1616   this->pos.y = this->target.y = 0;
     17   this->targetPlayer = 0;
    1718   this->timeLastUpdated = 0;
    1819   this->timeAttackStarted = 0;
     
    4647   this->target.x = p.target.x;
    4748   this->target.y = p.target.y;
     49   this->targetPlayer = p.targetPlayer;
    4850   this->timeLastUpdated = p.timeLastUpdated;
    4951   this->timeAttackStarted = p.timeAttackStarted;
     
    7577   this->pos.x = this->target.x = 200;
    7678   this->pos.y = this->target.y = 200;
     79   this->targetPlayer = 0;
    7780   this->timeLastUpdated = 0;
    7881   this->timeAttackStarted = 0;
     
    100103}
    101104
     105unsigned int Player::getId()
     106{
     107   return this->id;
     108}
     109
     110unsigned int Player::getTargetPlayer()
     111{
     112   return this->targetPlayer;
     113}
     114
    102115void Player::setId(unsigned int id)
    103116{
    104117   this->id = id;
     118}
     119
     120void Player::setTargetPlayer(unsigned int id)
     121{
     122   this->targetPlayer = id;
    105123}
    106124
     
    217235}
    218236
    219 bool Player::updateTarget(const Player* targetPlayer) {
    220    if (this->isChasing) {
    221       this->target.x = targetPlayer->pos.x;
    222       this->target.y = targetPlayer->pos.y;
     237bool Player::updateTarget(map<unsigned int, Player*>& players) {
     238   Player* p = NULL;
     239   if (this->targetPlayer > 0)
     240      p =players[this->targetPlayer];
     241
     242   if (p != NULL && this->isChasing) {
     243      this->target.x = p->pos.x;
     244      this->target.y = p->pos.y;
    223245
    224246      if (posDistance(this->pos, this->target.toFloat()) <= this->range) {
Note: See TracChangeset for help on using the changeset viewer.