Changes in / [1e250bf:c51da03] in network-game
- Location:
- client/Client
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/GameRender.cpp
r1e250bf rc51da03 18 18 for (int y=0; y<gameMap->height; y++) 19 19 { 20 TerrainType el= gameMap->getElement(x, y);20 TerrainType terrain = gameMap->getElement(x, y); 21 21 StructureType structure = gameMap->getStructure(x, y); 22 22 23 if (el == TERRAIN_GRASS) 23 switch(terrain) { 24 case TERRAIN_GRASS: 24 25 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: 26 28 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: 28 31 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 } 29 36 30 if (structure == STRUCTURE_BLUE_FLAG) { 37 switch(structure) { 38 case STRUCTURE_BLUE_FLAG: 31 39 al_draw_circle(x*25+12+mapPos.x, y*25+12+mapPos.y, 12, al_map_rgb(0, 0, 0), 3); 32 40 //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: 34 43 al_draw_circle(x*25+12+mapPos.x, y*25+12+mapPos.y, 12, al_map_rgb(0, 0, 0), 3); 35 44 //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; 36 48 } 37 49 } -
client/Client/main.cpp
r1e250bf rc51da03 57 57 void initWinSock(); 58 58 void 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); 59 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, unsigned int& curPlayerId); 61 60 int getRefreshRate(int width, int height); 62 61 void drawMessageStatus(ALLEGRO_FONT* font); … … 135 134 ALLEGRO_TIMER *timer = NULL; 136 135 map<unsigned int, Player*> mapPlayers; 137 map<unsigned int, Projectile> mapProjectiles;138 136 unsigned int curPlayerId = -1; 139 137 ofstream outputLog; … … 370 368 case ALLEGRO_KEY_D: // drop the current item 371 369 if (state == STATE_GAME) { 372 Player* p = NULL;373 370 try { 374 p = mapPlayers.at(curPlayerId); 375 } catch (const out_of_range& ex) {} 376 377 if (p != NULL) { 371 Player* p = mapPlayers.at(curPlayerId); 378 372 int flagType = OBJECT_NONE; 379 373 … … 388 382 msgProcessor.sendMessage(&msgTo, &server); 389 383 } 390 } 384 } catch (const out_of_range& ex) {} 391 385 } 392 386 break; … … 427 421 for(it = playersInGame.begin(); it != playersInGame.end(); it++) 428 422 { 429 // need to check if the right-click was actually on this player430 // right now, this code will target all players other than the current one431 423 target = it->second; 432 424 cout << "set target" << endl; … … 458 450 459 451 if (msgProcessor.receiveMessage(&msgFrom, &from) >= 0) 460 processMessage(msgFrom, state, chatConsole, mapPlayers, mapProjectiles,curPlayerId);452 processMessage(msgFrom, state, chatConsole, mapPlayers, curPlayerId); 461 453 462 454 if (redraw) … … 630 622 } 631 623 632 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, 633 map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId) 624 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, unsigned int& curPlayerId) 634 625 { 635 626 // this is outdated since most messages now don't contain just a text string … … 789 780 break; 790 781 } 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 }825 782 case MSG_TYPE_GAME_INFO: 826 783 { … … 970 927 else 971 928 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]; 972 946 973 947 break;
Note:
See TracChangeset
for help on using the changeset viewer.