Changeset e6c26b8 in network-game for client/Client/main.cpp
- Timestamp:
- Oct 1, 2013, 8:08:24 PM (11 years ago)
- Branches:
- master
- Children:
- 95ffe57
- Parents:
- 373089e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
r373089e re6c26b8 54 54 void initWinSock(); 55 55 void shutdownWinSock(); 56 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, WorldMap *gameMap, map<unsigned int, Player >& mapPlayers, map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId, int &scoreBlue, int &scoreRed);56 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, WorldMap *gameMap, map<unsigned int, Player*>& mapPlayers, map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId, int &scoreBlue, int &scoreRed); 57 57 int getRefreshRate(int width, int height); 58 58 void drawMessageStatus(ALLEGRO_FONT* font); … … 133 133 ALLEGRO_TIMER *timer = NULL; 134 134 bool key[4] = { false, false, false, false }; 135 map<unsigned int, Player > mapPlayers;135 map<unsigned int, Player*> mapPlayers; 136 136 map<unsigned int, Projectile> mapProjectiles; 137 137 unsigned int curPlayerId = -1; … … 362 362 if (state == STATE_GAME) { 363 363 // find the current player in the player list 364 map<unsigned int, Player >::iterator it;364 map<unsigned int, Player*>::iterator it; 365 365 Player* p = NULL; 366 366 for(it = mapPlayers.begin(); it != mapPlayers.end(); it++) 367 367 { 368 if (it->second .id == curPlayerId)369 p = &it->second;368 if (it->second->id == curPlayerId) 369 p = it->second; 370 370 } 371 371 … … 416 416 cout << "Invalid point: User did not click on the map" << endl; 417 417 }else if (ev.mouse.button == 2) { // right click 418 map<unsigned int, Player >::iterator it;418 map<unsigned int, Player*>::iterator it; 419 419 420 420 cout << "Detected a right-click" << endl; … … 423 423 for(it = mapPlayers.begin(); it != mapPlayers.end(); it++) 424 424 { 425 if (it->second .id == curPlayerId)426 curPlayer = &it->second;425 if (it->second->id == curPlayerId) 426 curPlayer = it->second; 427 427 } 428 428 … … 432 432 // need to check if the right-click was actually on this player 433 433 // right now, this code will target all players other than the current one 434 target = &it->second;434 target = it->second; 435 435 if (target->id != curPlayerId && target->team != curPlayer->team) 436 436 { … … 502 502 503 503 // update players 504 map<unsigned int, Player >::iterator it;504 map<unsigned int, Player*>::iterator it; 505 505 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) 506 506 { 507 it->second .updateTarget(mapPlayers);507 it->second->updateTarget(mapPlayers); 508 508 } 509 509 510 510 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) 511 511 { 512 it->second .move(gameMap);// ignore return value512 it->second->move(gameMap); // ignore return value 513 513 } 514 514 … … 528 528 Projectile proj = it2->second; 529 529 530 FLOAT_POSITION target = mapPlayers[proj.target] .pos;530 FLOAT_POSITION target = mapPlayers[proj.target]->pos; 531 531 float angle = atan2(target.y-proj.pos.toFloat().y, target.x-proj.pos.toFloat().x); 532 532 … … 572 572 delete game; 573 573 574 map<unsigned int, Player*>::iterator it; 575 576 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) { 577 delete it->second; 578 } 579 574 580 al_destroy_event_queue(event_queue); 575 581 al_destroy_display(display); … … 617 623 } 618 624 619 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, WorldMap *gameMap, map<unsigned int, Player >& mapPlayers, map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId, int &scoreBlue, int &scoreRed)625 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, WorldMap *gameMap, map<unsigned int, Player*>& mapPlayers, map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId, int &scoreBlue, int &scoreRed) 620 626 { 621 627 string response = string(msg.buffer); … … 671 677 Player p("", ""); 672 678 p.deserialize(msg.buffer); 673 mapPlayers[p.id] = p; 679 680 if (mapPlayers.find(p.id) != mapPlayers.end()) 681 delete mapPlayers[p.id]; 682 mapPlayers[p.id] = new Player(p); 674 683 curPlayerId = p.id; 675 684 … … 708 717 p.isDead = false; 709 718 710 mapPlayers[p.id] = p; 719 if (mapPlayers.find(p.id) != mapPlayers.end()) 720 delete mapPlayers[p.id]; 721 mapPlayers[p.id] = new Player(p); 711 722 712 723 break; … … 721 732 memcpy(&y, msg.buffer+8, 4); 722 733 723 mapPlayers[id] .target.x = x;724 mapPlayers[id] .target.y = y;734 mapPlayers[id]->target.x = x; 735 mapPlayers[id]->target.y = y; 725 736 726 737 break; … … 781 792 cout << "target id: " << targetID << endl; 782 793 783 Player* source = &mapPlayers[id];794 Player* source = mapPlayers[id]; 784 795 source->targetPlayer = targetID; 785 796 source->isChasing = true;
Note:
See TracChangeset
for help on using the changeset viewer.