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