Changeset 5c7f28d in network-game for client/Client


Ignore:
Timestamp:
Jan 26, 2014, 9:45:30 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
c51da03
Parents:
9ee50ce
Message:

The global projectile map and related code is gone from main.cpp, the client processes LOGOUT messages about other players from STATE_GAME, and the map drawing code in GameRender uses switches instead of ifs

Location:
client/Client
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • client/Client/GameRender.cpp

    r9ee50ce r5c7f28d  
    1616      for (int y=0; y<gameMap->height; y++)
    1717      {
    18          TerrainType el = gameMap->getElement(x, y);
     18         TerrainType terrain = gameMap->getElement(x, y);
    1919         StructureType structure = gameMap->getStructure(x, y);
    2020
    21          if (el == TERRAIN_GRASS)
     21         switch(terrain) {
     22         case TERRAIN_GRASS:
    2223            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));
    23          else if (el == TERRAIN_OCEAN)
     24            break;
     25         case TERRAIN_OCEAN:
    2426            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));
    25          else if (el == TERRAIN_ROCK)
     27            break;
     28         case TERRAIN_ROCK:
    2629            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));
     30            break;
     31         case TERRAIN_NONE:
     32            break;
     33         } 
    2734
    28          if (structure == STRUCTURE_BLUE_FLAG) {
     35         switch(structure) {
     36         case STRUCTURE_BLUE_FLAG:
    2937            al_draw_circle(x*25+12+mapPos.x, y*25+12+mapPos.y, 12, al_map_rgb(0, 0, 0), 3);
    3038            //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));
    31          }else if (structure == STRUCTURE_RED_FLAG) {
     39            break;
     40         case STRUCTURE_RED_FLAG:
    3241            al_draw_circle(x*25+12+mapPos.x, y*25+12+mapPos.y, 12, al_map_rgb(0, 0, 0), 3);
    3342            //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));
     43            break;
     44         case STRUCTURE_NONE:
     45            break;
    3446         }
    3547      }
  • client/Client/main.cpp

    r9ee50ce r5c7f28d  
    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);
     
    136135   bool key[4] = { false, false, false, false };
    137136   map<unsigned int, Player*> mapPlayers;
    138    map<unsigned int, Projectile> mapProjectiles;
    139137   unsigned int curPlayerId = -1;
    140138   ofstream outputLog;
     
    371369            case ALLEGRO_KEY_D:  // drop the current item
    372370               if (state == STATE_GAME) {
    373                   Player* p = NULL;
    374371                  try {
    375                      p = mapPlayers.at(curPlayerId);
    376                   } catch (const out_of_range& ex) {}
    377 
    378                   if (p != NULL) {
     372                     Player* p = mapPlayers.at(curPlayerId);
    379373                     int flagType = OBJECT_NONE;
    380374
     
    389383                        msgProcessor.sendMessage(&msgTo, &server);
    390384                     }
    391                   }
     385                  } catch (const out_of_range& ex) {}
    392386               }
    393387               break;
     
    428422               for(it = playersInGame.begin(); it != playersInGame.end(); it++)
    429423               {
    430                   // need to check if the right-click was actually on this player
    431                   // right now, this code will target all players other than the current one
    432424                  target = it->second;
    433425                  cout << "set target" << endl;
     
    459451
    460452      if (msgProcessor.receiveMessage(&msgFrom, &from) >= 0)
    461          processMessage(msgFrom, state, chatConsole, mapPlayers, mapProjectiles, curPlayerId);
     453         processMessage(msgFrom, state, chatConsole, mapPlayers, curPlayerId);
    462454
    463455      if (redraw)
     
    631623}
    632624
    633 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers,
    634                     map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId)
     625void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, unsigned int& curPlayerId)
    635626{
    636627   // this is outdated since most messages now don't contain just a text string
     
    790781               break;
    791782            }
    792             case MSG_TYPE_PROJECTILE:
    793             {
    794                cout << "Received a PROJECTILE message" << endl;
    795 
    796                unsigned int id, x, y, targetId;
    797 
    798                memcpy(&id, msg.buffer, 4);
    799                memcpy(&x, msg.buffer+4, 4);
    800                memcpy(&y, msg.buffer+8, 4);
    801                memcpy(&targetId, msg.buffer+12, 4);
    802 
    803                cout << "id: " << id << endl;
    804                cout << "x: " << x << endl;
    805                cout << "y: " << y << endl;
    806                cout << "Target: " << targetId << endl;
    807 
    808                Projectile proj(x, y, targetId, 0);
    809                proj.setId(id);
    810 
    811                mapProjectiles[id] = proj;
    812 
    813                break;
    814             }
    815             case MSG_TYPE_REMOVE_PROJECTILE:
    816             {
    817                 cout << "Received a REMOVE_PROJECTILE message" << endl;
    818 
    819                int id;
    820                memcpy(&id, msg.buffer, 4);
    821                
    822                mapProjectiles.erase(id);
    823 
    824                break;
    825             }
    826783            case MSG_TYPE_GAME_INFO:
    827784            {
     
    971928               else
    972929                  mapPlayers[p.getId()] = new Player(p);
     930
     931               break;
     932            }
     933             case MSG_TYPE_LOGOUT:
     934            {
     935               cout << "Got a logout message" << endl;
     936
     937               int playerId;
     938
     939               // Check if it's about you or another player
     940               memcpy(&playerId, msg.buffer, 4);
     941               response = string(msg.buffer+4);
     942
     943               if (playerId == curPlayerId)
     944                  cout << "Received MSG_TYPE_LOGOUT for self in STATE_GAME. This shouldn't happen." << endl;
     945               else
     946                  delete mapPlayers[playerId];
    973947
    974948               break;
Note: See TracChangeset for help on using the changeset viewer.