Changeset 5b1e31e in network-game
- Timestamp:
- Jun 16, 2013, 11:12:31 PM (12 years ago)
- Branches:
- master
- Children:
- 032e550, d3e8f60
- Parents:
- ff2133a
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Player.cpp
rff2133a r5b1e31e 142 142 memcpy(buffer+44, &this->hasBlueFlag, 1); 143 143 memcpy(buffer+45, &this->hasRedFlag, 1); 144 memcpy(buffer+46, &this->range, 4); 144 145 145 146 strcpy(buffer+46, this->name.c_str()); … … 162 163 memcpy(&this->hasBlueFlag, buffer+44, 1); 163 164 memcpy(&this->hasRedFlag, buffer+45, 1); 165 memcpy(&this->range, buffer+46, 4); 164 166 165 167 this->name.assign(buffer+46); … … 192 194 } 193 195 194 voidPlayer::updateTarget(map<unsigned int, Player>& mapPlayers) {196 bool Player::updateTarget(map<unsigned int, Player>& mapPlayers) { 195 197 if (this->isChasing) { 196 198 this->target.x = mapPlayers[this->targetPlayer].pos.x; … … 204 206 this->isAttacking = true; 205 207 this->timeAttackStarted = getCurrentMillis(); 208 209 return true; 206 210 } 207 211 } 208 } 212 213 return false; 214 } -
common/Player.h
rff2133a r5b1e31e 47 47 void deserialize(char* buffer); 48 48 49 voidupdateTarget(map<unsigned int, Player>& mapPlayers);49 bool updateTarget(map<unsigned int, Player>& mapPlayers); 50 50 bool move(WorldMap *map); 51 51 -
server/server.cpp
rff2133a r5b1e31e 119 119 120 120 sock = socket(AF_INET, SOCK_DGRAM, 0); 121 if (sock < 0) error("Opening socket"); 121 if (sock < 0) 122 error("Opening socket"); 122 123 length = sizeof(server); 123 124 bzero(&server,length); … … 149 150 // set targets for all chasing players (or make them attack if they're close enough) 150 151 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) { 151 //Player* p = &it->second; 152 it->second.updateTarget(mapPlayers); 153 154 /* 155 if (p->isChasing) { 156 p->target.x = mapPlayers[p->targetPlayer].pos.x; 157 p->target.y = mapPlayers[p->targetPlayer].pos.y; 158 159 if (posDistance(p->pos, p->target.toFloat()) <= p->range) { 160 p->target.x = p->pos.x; 161 p->target.y = p->pos.y; 162 163 p->isChasing = false; 164 p->isAttacking = true; 165 p->timeAttackStarted = getCurrentMillis(); 166 } 167 } 168 */ 152 if (it->second.updateTarget(mapPlayers)) { 153 serverMsg.type = MSG_TYPE_PLAYER; 154 it->second.serialize(serverMsg.buffer); 155 156 map<unsigned int, Player>::iterator it2; 157 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++) 158 { 159 if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 ) 160 error("sendMessage"); 161 } 162 } 169 163 } 170 164 … … 187 181 it->second.target.x = it->second.pos.x; 188 182 it->second.target.y = it->second.pos.y; 183 it->second.isChasing = false; 189 184 broadcastMove = true; 190 185 break; … … 689 684 mapPlayers[id].target.y = y; 690 685 686 mapPlayers[id].isChasing = false; 687 mapPlayers[id].isAttacking = false; 688 691 689 serverMsg.type = MSG_TYPE_PLAYER_MOVE; 692 690
Note:
See TracChangeset
for help on using the changeset viewer.