Changes in / [c51da03:1e250bf] in network-game


Ignore:
Location:
client/Client
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • client/Client/GameRender.cpp

    rc51da03 r1e250bf  
    1818      for (int y=0; y<gameMap->height; y++)
    1919      {
    20          TerrainType terrain = gameMap->getElement(x, y);
     20         TerrainType el = gameMap->getElement(x, y);
    2121         StructureType structure = gameMap->getStructure(x, y);
    2222
    23          switch(terrain) {
    24          case TERRAIN_GRASS:
     23         if (el == TERRAIN_GRASS)
    2524            al_draw_filled_rectangle(x*25+mapPos.x, y*25+mapPos.y, x*25+25+mapPos.x, y*25+25+mapPos.y, al_map_rgb(0, 255, 0));
    26             break;
    27          case TERRAIN_OCEAN:
     25         else if (el == TERRAIN_OCEAN)
    2826            al_draw_filled_rectangle(x*25+mapPos.x, y*25+mapPos.y, x*25+25+mapPos.x, y*25+25+mapPos.y, al_map_rgb(0, 0, 255));
    29             break;
    30          case TERRAIN_ROCK:
     27         else if (el == TERRAIN_ROCK)
    3128            al_draw_filled_rectangle(x*25+mapPos.x, y*25+mapPos.y, x*25+25+mapPos.x, y*25+25+mapPos.y, al_map_rgb(100, 100, 0));
    32             break;
    33          case TERRAIN_NONE:
    34             break;
    35          } 
    3629
    37          switch(structure) {
    38          case STRUCTURE_BLUE_FLAG:
     30         if (structure == STRUCTURE_BLUE_FLAG) {
    3931            al_draw_circle(x*25+12+mapPos.x, y*25+12+mapPos.y, 12, al_map_rgb(0, 0, 0), 3);
    4032            //al_draw_filled_rectangle(x*25+5+mapPos.x, y*25+5+mapPos.y, x*25+20+mapPos.x, y*25+20+mapPos.y, al_map_rgb(0, 0, 255));
    41             break;
    42          case STRUCTURE_RED_FLAG:
     33         }else if (structure == STRUCTURE_RED_FLAG) {
    4334            al_draw_circle(x*25+12+mapPos.x, y*25+12+mapPos.y, 12, al_map_rgb(0, 0, 0), 3);
    4435            //al_draw_filled_rectangle(x*25+5+mapPos.x, y*25+5+mapPos.y, x*25+20+mapPos.x, y*25+20+mapPos.y, al_map_rgb(255, 0, 0));
    45             break;
    46          case STRUCTURE_NONE:
    47             break;
    4836         }
    4937      }
  • client/Client/main.cpp

    rc51da03 r1e250bf  
    5757void initWinSock();
    5858void shutdownWinSock();
    59 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, unsigned int& curPlayerId);
     59void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers,
     60                    map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId);
    6061int getRefreshRate(int width, int height);
    6162void drawMessageStatus(ALLEGRO_FONT* font);
     
    134135   ALLEGRO_TIMER *timer = NULL;
    135136   map<unsigned int, Player*> mapPlayers;
     137   map<unsigned int, Projectile> mapProjectiles;
    136138   unsigned int curPlayerId = -1;
    137139   ofstream outputLog;
     
    368370            case ALLEGRO_KEY_D:  // drop the current item
    369371               if (state == STATE_GAME) {
     372                  Player* p = NULL;
    370373                  try {
    371                      Player* p = mapPlayers.at(curPlayerId);
     374                     p = mapPlayers.at(curPlayerId);
     375                  } catch (const out_of_range& ex) {}
     376
     377                  if (p != NULL) {
    372378                     int flagType = OBJECT_NONE;
    373379
     
    382388                        msgProcessor.sendMessage(&msgTo, &server);
    383389                     }
    384                   } catch (const out_of_range& ex) {}
     390                  }
    385391               }
    386392               break;
     
    421427               for(it = playersInGame.begin(); it != playersInGame.end(); it++)
    422428               {
     429                  // need to check if the right-click was actually on this player
     430                  // right now, this code will target all players other than the current one
    423431                  target = it->second;
    424432                  cout << "set target" << endl;
     
    450458
    451459      if (msgProcessor.receiveMessage(&msgFrom, &from) >= 0)
    452          processMessage(msgFrom, state, chatConsole, mapPlayers, curPlayerId);
     460         processMessage(msgFrom, state, chatConsole, mapPlayers, mapProjectiles, curPlayerId);
    453461
    454462      if (redraw)
     
    622630}
    623631
    624 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, unsigned int& curPlayerId)
     632void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers,
     633                    map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId)
    625634{
    626635   // this is outdated since most messages now don't contain just a text string
     
    780789               break;
    781790            }
     791            case MSG_TYPE_PROJECTILE:
     792            {
     793               cout << "Received a PROJECTILE message" << endl;
     794
     795               unsigned int id, x, y, targetId;
     796
     797               memcpy(&id, msg.buffer, 4);
     798               memcpy(&x, msg.buffer+4, 4);
     799               memcpy(&y, msg.buffer+8, 4);
     800               memcpy(&targetId, msg.buffer+12, 4);
     801
     802               cout << "id: " << id << endl;
     803               cout << "x: " << x << endl;
     804               cout << "y: " << y << endl;
     805               cout << "Target: " << targetId << endl;
     806
     807               Projectile proj(x, y, targetId, 0);
     808               proj.setId(id);
     809
     810               mapProjectiles[id] = proj;
     811
     812               break;
     813            }
     814            case MSG_TYPE_REMOVE_PROJECTILE:
     815            {
     816                cout << "Received a REMOVE_PROJECTILE message" << endl;
     817
     818               int id;
     819               memcpy(&id, msg.buffer, 4);
     820               
     821               mapProjectiles.erase(id);
     822
     823               break;
     824            }
    782825            case MSG_TYPE_GAME_INFO:
    783826            {
     
    927970               else
    928971                  mapPlayers[p.getId()] = new Player(p);
    929 
    930                break;
    931             }
    932              case MSG_TYPE_LOGOUT:
    933             {
    934                cout << "Got a logout message" << endl;
    935 
    936                int playerId;
    937 
    938                // Check if it's about you or another player
    939                memcpy(&playerId, msg.buffer, 4);
    940                response = string(msg.buffer+4);
    941 
    942                if (playerId == curPlayerId)
    943                   cout << "Received MSG_TYPE_LOGOUT for self in STATE_GAME. This shouldn't happen." << endl;
    944                else
    945                   delete mapPlayers[playerId];
    946972
    947973               break;
Note: See TracChangeset for help on using the changeset viewer.