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


Ignore:
Location:
client/Client
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • client/Client/GameRender.cpp

    r1e250bf rc51da03  
    1818      for (int y=0; y<gameMap->height; y++)
    1919      {
    20          TerrainType el = gameMap->getElement(x, y);
     20         TerrainType terrain = gameMap->getElement(x, y);
    2121         StructureType structure = gameMap->getStructure(x, y);
    2222
    23          if (el == TERRAIN_GRASS)
     23         switch(terrain) {
     24         case TERRAIN_GRASS:
    2425            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));
    25          else if (el == TERRAIN_OCEAN)
     26            break;
     27         case TERRAIN_OCEAN:
    2628            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));
    27          else if (el == TERRAIN_ROCK)
     29            break;
     30         case TERRAIN_ROCK:
    2831            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         } 
    2936
    30          if (structure == STRUCTURE_BLUE_FLAG) {
     37         switch(structure) {
     38         case STRUCTURE_BLUE_FLAG:
    3139            al_draw_circle(x*25+12+mapPos.x, y*25+12+mapPos.y, 12, al_map_rgb(0, 0, 0), 3);
    3240            //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));
    33          }else if (structure == STRUCTURE_RED_FLAG) {
     41            break;
     42         case STRUCTURE_RED_FLAG:
    3443            al_draw_circle(x*25+12+mapPos.x, y*25+12+mapPos.y, 12, al_map_rgb(0, 0, 0), 3);
    3544            //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;
    3648         }
    3749      }
  • client/Client/main.cpp

    r1e250bf rc51da03  
    5757void initWinSock();
    5858void shutdownWinSock();
    59 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers,
    60                     map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId);
     59void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, unsigned int& curPlayerId);
    6160int getRefreshRate(int width, int height);
    6261void drawMessageStatus(ALLEGRO_FONT* font);
     
    135134   ALLEGRO_TIMER *timer = NULL;
    136135   map<unsigned int, Player*> mapPlayers;
    137    map<unsigned int, Projectile> mapProjectiles;
    138136   unsigned int curPlayerId = -1;
    139137   ofstream outputLog;
     
    370368            case ALLEGRO_KEY_D:  // drop the current item
    371369               if (state == STATE_GAME) {
    372                   Player* p = NULL;
    373370                  try {
    374                      p = mapPlayers.at(curPlayerId);
    375                   } catch (const out_of_range& ex) {}
    376 
    377                   if (p != NULL) {
     371                     Player* p = mapPlayers.at(curPlayerId);
    378372                     int flagType = OBJECT_NONE;
    379373
     
    388382                        msgProcessor.sendMessage(&msgTo, &server);
    389383                     }
    390                   }
     384                  } catch (const out_of_range& ex) {}
    391385               }
    392386               break;
     
    427421               for(it = playersInGame.begin(); it != playersInGame.end(); it++)
    428422               {
    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
    431423                  target = it->second;
    432424                  cout << "set target" << endl;
     
    458450
    459451      if (msgProcessor.receiveMessage(&msgFrom, &from) >= 0)
    460          processMessage(msgFrom, state, chatConsole, mapPlayers, mapProjectiles, curPlayerId);
     452         processMessage(msgFrom, state, chatConsole, mapPlayers, curPlayerId);
    461453
    462454      if (redraw)
     
    630622}
    631623
    632 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers,
    633                     map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId)
     624void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, unsigned int& curPlayerId)
    634625{
    635626   // this is outdated since most messages now don't contain just a text string
     
    789780               break;
    790781            }
    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             }
    825782            case MSG_TYPE_GAME_INFO:
    826783            {
     
    970927               else
    971928                  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];
    972946
    973947               break;
Note: See TracChangeset for help on using the changeset viewer.