Changeset 5b92307 in network-game
- Timestamp:
- Jan 20, 2014, 6:47:58 PM (11 years ago)
- Branches:
- master
- Children:
- 204edcf
- Parents:
- 949cf70
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/GameRender.cpp
r949cf70 r5b92307 74 74 pos = mapToScreen(p->pos.toInt()); 75 75 76 if (p-> id== curPlayerId)76 if (p->getId() == curPlayerId) 77 77 al_draw_filled_circle(pos.x, pos.y, 14, al_map_rgb(0, 0, 0)); 78 78 -
client/Client/main.cpp
r949cf70 r5b92307 432 432 target = it->second; 433 433 cout << "set target" << endl; 434 if (target-> id!= curPlayerId && target->team != curPlayer->team)434 if (target->getId() != curPlayerId && target->team != curPlayer->team) 435 435 { 436 436 cout << "Found valid target" << endl; 437 437 438 unsigned int targetId = target->getId(); 439 438 440 msgTo.type = MSG_TYPE_ATTACK; 439 441 memcpy(msgTo.buffer, &curPlayerId, 4); 440 memcpy(msgTo.buffer+4, &target ->id, 4);442 memcpy(msgTo.buffer+4, &targetId, 4); 441 443 442 444 msgProcessor.sendMessage(&msgTo, &server); … … 678 680 p->deserialize(msg.buffer); 679 681 680 if (mapPlayers.find(p-> id) != mapPlayers.end())681 delete mapPlayers[p-> id];682 mapPlayers[p-> id] = p;683 curPlayerId = p-> id;682 if (mapPlayers.find(p->getId()) != mapPlayers.end()) 683 delete mapPlayers[p->getId()]; 684 mapPlayers[p->getId()] = p; 685 curPlayerId = p->getId(); 684 686 685 687 cout << "Got a valid login response with the player" << endl; … … 732 734 p.isDead = false; 733 735 734 if (mapPlayers.find(p. id) != mapPlayers.end())735 *(mapPlayers[p. id]) = p;736 if (mapPlayers.find(p.getId()) != mapPlayers.end()) 737 *(mapPlayers[p.getId()]) = p; 736 738 else 737 mapPlayers[p. id] = new Player(p);739 mapPlayers[p.getId()] = new Player(p); 738 740 739 741 break; … … 771 773 772 774 Player* source = mapPlayers[id]; 773 source-> targetPlayer = targetID;775 source->setTargetPlayer(targetID); 774 776 source->isChasing = true; 775 777 … … 953 955 p.isDead = false; 954 956 955 if (mapPlayers.find(p. id) != mapPlayers.end())956 *(mapPlayers[p. id]) = p;957 if (mapPlayers.find(p.getId()) != mapPlayers.end()) 958 *(mapPlayers[p.getId()]) = p; 957 959 else 958 mapPlayers[p. id] = new Player(p);960 mapPlayers[p.getId()] = new Player(p); 959 961 960 962 break; … … 966 968 Player p("", ""); 967 969 p.deserialize(msg.buffer); 970 cout << "Deserialized player" << endl; 968 971 p.timeLastUpdated = getCurrentMillis(); 969 972 p.isChasing = false; … … 973 976 p.isDead = false; 974 977 975 if (mapPlayers.find(p. id) != mapPlayers.end())976 *(mapPlayers[p. id]) = p;978 if (mapPlayers.find(p.getId()) != mapPlayers.end()) 979 *(mapPlayers[p.getId()]) = p; 977 980 else 978 mapPlayers[p. id] = new Player(p);979 980 game->addPlayer(mapPlayers[p. id]);981 mapPlayers[p.getId()] = new Player(p); 982 983 game->addPlayer(mapPlayers[p.getId()]); 981 984 982 985 break; … … 1051 1054 // need to check the target exists in the current game 1052 1055 Player* source = game->getPlayers()[id]; 1053 source-> targetPlayer = targetId;1056 source->setTargetPlayer(targetId); 1054 1057 source->isChasing = true; 1055 1058 -
common/Game.cpp
r949cf70 r5b92307 43 43 44 44 bool Game::addPlayer(Player* p) { 45 if (players.find(p-> id) == players.end()) {46 players[p-> id] = p;45 if (players.find(p->getId()) == players.end()) { 46 players[p->getId()] = p; 47 47 return true; 48 48 } … … 429 429 cout << "Melee attack" << endl; 430 430 431 Player* target = players[p-> targetPlayer];431 Player* target = players[p->getTargetPlayer()]; 432 432 this->dealDamageToPlayer(target, p->damage); 433 433 } … … 436 436 cout << "Ranged attack" << endl; 437 437 438 Projectile proj(p->pos.x, p->pos.y, p-> targetPlayer, p->damage);438 Projectile proj(p->pos.x, p->pos.y, p->getTargetPlayer(), p->damage); 439 439 this->assignProjectileId(&proj); 440 440 this->addProjectile(proj); … … 442 442 int x = p->pos.x; 443 443 int y = p->pos.y; 444 unsigned int targetId = p->getTargetPlayer(); 444 445 445 446 serverMsg.type = MSG_TYPE_PROJECTILE; … … 447 448 memcpy(serverMsg.buffer+4, &x, 4); 448 449 memcpy(serverMsg.buffer+8, &y, 4); 449 memcpy(serverMsg.buffer+12, & p->targetPlayer, 4);450 memcpy(serverMsg.buffer+12, &targetId, 4); 450 451 msgProcessor->broadcastMessage(serverMsg, players); 451 452 } -
common/Player.cpp
r949cf70 r5b92307 15 15 this->pos.x = this->target.x = 0; 16 16 this->pos.y = this->target.y = 0; 17 this->targetPlayer = 0; 17 18 this->timeLastUpdated = 0; 18 19 this->timeAttackStarted = 0; … … 46 47 this->target.x = p.target.x; 47 48 this->target.y = p.target.y; 49 this->targetPlayer = p.targetPlayer; 48 50 this->timeLastUpdated = p.timeLastUpdated; 49 51 this->timeAttackStarted = p.timeAttackStarted; … … 75 77 this->pos.x = this->target.x = 200; 76 78 this->pos.y = this->target.y = 200; 79 this->targetPlayer = 0; 77 80 this->timeLastUpdated = 0; 78 81 this->timeAttackStarted = 0; … … 100 103 } 101 104 105 unsigned int Player::getId() 106 { 107 return this->id; 108 } 109 110 unsigned int Player::getTargetPlayer() 111 { 112 return this->targetPlayer; 113 } 114 102 115 void Player::setId(unsigned int id) 103 116 { 104 117 this->id = id; 118 } 119 120 void Player::setTargetPlayer(unsigned int id) 121 { 122 this->targetPlayer = id; 105 123 } 106 124 … … 217 235 } 218 236 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; 237 bool 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; 223 245 224 246 if (posDistance(this->pos, this->target.toFloat()) <= this->range) { -
common/Player.h
r949cf70 r5b92307 21 21 22 22 class Player { 23 private: 24 unsigned int id; 25 unsigned int targetPlayer; 26 23 27 public: 24 28 … … 41 45 ~Player(); 42 46 47 unsigned int getId(); 48 unsigned int getTargetPlayer(); 49 43 50 void setId(unsigned int id); 51 void setTargetPlayer(unsigned int id); 44 52 void setAddr(sockaddr_in addr); 45 53 void setClass(PlayerClass c); … … 48 56 void deserialize(char* buffer); 49 57 50 bool updateTarget( const Player* targetPlayer);58 bool updateTarget(map<unsigned int, Player*>& players); 51 59 bool move(WorldMap *map); 52 60 void takeDamage(int damage); … … 55 63 void dropFlag(unsigned int flag, WorldMap* map); 56 64 57 unsigned int id;58 65 string name; 59 66 string password; … … 66 73 bool isChasing; 67 74 bool isAttacking; 68 unsigned int targetPlayer;69 75 bool isDead; 70 76
Note:
See TracChangeset
for help on using the changeset viewer.