Changeset c76134b in network-game
- Timestamp:
- Jun 18, 2013, 11:16:21 PM (12 years ago)
- Branches:
- master
- Children:
- 66c4ec4
- Parents:
- 1d0ede1
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Player.cpp
r1d0ede1 rc76134b 17 17 this->timeLastUpdated = 0; 18 18 this->timeAttackStarted = 0; 19 this->timeDied = 0; 19 20 this->isChasing = false; 20 21 this->isAttacking = false; 22 this->isDead = false; 21 23 22 24 this->playerClass = CLASS_NONE; … … 44 46 this->timeLastUpdated = p.timeLastUpdated; 45 47 this->timeAttackStarted = p.timeAttackStarted; 48 this->timeDied = p.timeDied; 46 49 this->isChasing = p.isChasing; 47 50 this->isAttacking = p.isAttacking; 51 this->isDead = p.isDead; 48 52 49 53 this->playerClass = p.playerClass; … … 69 73 this->timeLastUpdated = 0; 70 74 this->timeAttackStarted = 0; 75 this->timeDied = 0; 71 76 this->isChasing = false; 72 77 this->isAttacking = false; 78 this->isDead = false; 73 79 74 80 this->playerClass = CLASS_NONE; -
common/Player.h
r1d0ede1 rc76134b 61 61 unsigned long long timeLastUpdated; 62 62 unsigned long long timeAttackStarted; 63 unsigned long long timeDied; 63 64 bool isChasing; 64 65 bool isAttacking; 65 66 int targetPlayer; 67 bool isDead; 66 68 67 69 int playerClass; -
common/Projectile.cpp
r1d0ede1 rc76134b 74 74 // if the current target logs off, this method will run into problems 75 75 76 //cout << "Inside projectile move" << endl;76 cout << "Inside projectile move" << endl; 77 77 78 78 unsigned long long curTime = getCurrentMillis(); 79 cout << "Got current time" << endl; 80 79 81 Player targetP = mapPlayers[target]; 82 cout << "Got target" << endl; 80 83 81 84 if (timeLastUpdated == 0) { … … 89 92 float dist = sqrt(pow(targetP.pos.x-pos.x, 2) + pow(targetP.pos.y-pos.y, 2)); 90 93 91 //cout << "About to finish projectile move" << endl;94 cout << "About to finish projectile move" << endl; 92 95 93 96 if (dist <= pixels) { -
server/DataAccess.cpp
r1d0ede1 rc76134b 84 84 cout << "Creating a new player" << endl; 85 85 p = new Player(string(row[1]), string(row[2])); 86 cout << "Created new player" << endl; 86 87 }else { 87 88 cout << "Returned no results for some reason" << endl; -
server/server.cpp
r1d0ede1 rc76134b 43 43 void updateUnusedPlayerId(unsigned int& id, map<unsigned int, Player>& mapPlayers); 44 44 void updateUnusedProjectileId(unsigned int& id, map<unsigned int, Projectile>& mapProjectiles); 45 void damagePlayer(Player *p, int damage); 45 46 46 47 // this should probably go somewhere in the common folder … … 150 151 // set targets for all chasing players (or make them attack if they're close enough) 151 152 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) { 153 // check if it's time to revive dead players 154 if (it->second.isDead) { 155 if (getCurrentMillis() - it->second.timeDied >= 10000) { 156 it->second.isDead = false; 157 158 POSITION spawnPos; 159 160 switch (it->second.team) { 161 case 0:// blue team 162 spawnPos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG); 163 break; 164 case 1:// red team 165 spawnPos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG); 166 break; 167 default: 168 // should never go here 169 cout << "Error: Invalid team" << endl; 170 break; 171 } 172 173 // spawn the player to the right of their flag location 174 spawnPos.x = (spawnPos.x+1) * 25 + 12; 175 spawnPos.y = spawnPos.y * 25 + 12; 176 177 it->second.pos = spawnPos.toFloat(); 178 179 serverMsg.type = MSG_TYPE_PLAYER; 180 it->second.serialize(serverMsg.buffer); 181 182 map<unsigned int, Player>::iterator it2; 183 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++) 184 { 185 if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 ) 186 error("sendMessage"); 187 } 188 } 189 190 continue; 191 } 192 152 193 if (it->second.updateTarget(mapPlayers)) { 153 194 serverMsg.type = MSG_TYPE_PLAYER; … … 364 405 365 406 Player* target = &mapPlayers[it->second.targetPlayer]; 366 367 target->health -= it->second.damage; 368 if (target->health < 0) 369 target->health = 0; 407 damagePlayer(target, it->second.damage); 370 408 371 409 serverMsg.type = MSG_TYPE_PLAYER; … … 408 446 map<unsigned int, Projectile>::iterator itProj; 409 447 for (itProj = mapProjectiles.begin(); itProj != mapProjectiles.end(); itProj++) { 448 cout << "About to call projectile move" << endl; 410 449 if (itProj->second.move(mapPlayers)) { 411 450 // send a REMOVE_PROJECTILE message … … 427 466 Player* target = &mapPlayers[itProj->second.target]; 428 467 429 target->health -= itProj->second.damage; 430 if (target->health < 0) 431 target->health = 0; 468 damagePlayer(target, itProj->second.damage); 432 469 433 470 serverMsg.type = MSG_TYPE_PLAYER; … … 441 478 } 442 479 } 480 cout << "Projectile was not moved" << endl; 443 481 } 444 482 } … … 860 898 id++; 861 899 } 900 901 void damagePlayer(Player *p, int damage) { 902 p->health -= damage; 903 if (p->health < 0) 904 p->health = 0; 905 if (p->health == 0) { 906 p->isDead = true; 907 p->timeDied = getCurrentMillis(); 908 } 909 }
Note:
See TracChangeset
for help on using the changeset viewer.