Changeset b4c5b6a in network-game for client/Client


Ignore:
Timestamp:
Dec 17, 2013, 12:44:38 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
3d6f78f
Parents:
1a47469
Message:

PLAYER messages are handled in the NEW_GAME state and players are added to the client's Game instance

Location:
client/Client
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • client/Client/GameRender.cpp

    r1a47469 rb4c5b6a  
    6363   ALLEGRO_COLOR color;
    6464
    65    for(it = mapPlayers.begin(); it != mapPlayers.end(); it++)
     65   for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
    6666   {
    6767      p = it->second;
  • client/Client/main.cpp

    r1a47469 rb4c5b6a  
    472472            for (it = mapGames.begin(); it != mapGames.end(); it++) {
    473473               ossGame << it->first << " (" << it->second << " players)" << endl;
    474                al_draw_text(font, al_map_rgb(0, 255, 0), SCREEN_W*1/4-100, 120+i*15, ALLEGRO_ALIGN_LEFT, ossGame.str().c_str());
     474               al_draw_text(font, al_map_rgb(0, 255, 0), SCREEN_W*1/2-100, 120+i*15, ALLEGRO_ALIGN_LEFT, ossGame.str().c_str());
    475475               ossGame.clear();
    476476               ossGame.str("");
     
    480480         else if (wndCurrent == wndNewGame)
    481481         {
     482            al_draw_text(font, al_map_rgb(0, 255, 0), 4, 4, ALLEGRO_ALIGN_LEFT, "Players");
     483
     484            map<unsigned int, Player*>& gamePlayers = game->getPlayers();
     485            map<unsigned int, Player*>::iterator it;
     486
     487            int playerCount = 0;
     488            for (it = gamePlayers.begin(); it != gamePlayers.end(); it++)
     489            {
     490               al_draw_text(font, al_map_rgb(0, 255, 0), 4, 19+(playerCount+1)*15, ALLEGRO_ALIGN_LEFT, it->second->name.c_str());
     491               playerCount++;
     492            }
     493
    482494            ostringstream ossScoreBlue, ossScoreRed;
    483495
     
    876888               string gameName(msg.buffer);         
    877889               game = new Game(gameName, "../../data/map.txt");
     890               game->addPlayer(mapPlayers[curPlayerId]);
    878891               cout << "Game name: " << gameName << endl;
    879892
     
    921934               
    922935               mapGames[gameName] = numPlayers;
     936
     937               break;
     938            }
     939            case MSG_TYPE_PLAYER:
     940            {
     941               cout << "Received MSG_TYPE_PLAYER" << endl;
     942
     943               Player* p = new Player("", "");
     944               p->deserialize(msg.buffer);
     945               p->timeLastUpdated = getCurrentMillis();
     946               p->isChasing = false;
     947               if (p->health <= 0)
     948                  p->isDead = true;
     949               else
     950                  p->isDead = false;
     951
     952               if (mapPlayers.find(p->id) != mapPlayers.end())
     953                    delete mapPlayers[p->id];
     954               mapPlayers[p->id] = p;
     955
     956               game->addPlayer(p);
    923957
    924958               break;
Note: See TracChangeset for help on using the changeset viewer.