Changeset 62ee2ce in network-game for client/Client/main.cpp
- Timestamp:
- Feb 5, 2013, 7:02:32 PM (12 years ago)
- Branches:
- master
- Children:
- 384b7e0, 60017fc
- Parents:
- 60b77d2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
r60b77d2 r62ee2ce 29 29 #include "../../common/Message.h" 30 30 #include "../../common/Common.h" 31 #include "../../common/Player.h"_ 31 #include "../../common/Player.h" 32 #include "../../common/WorldMap.h" 32 33 33 34 #include "Window.h" … … 45 46 void shutdownWinSock(); 46 47 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player>& mapPlayers, unsigned int& curPlayerId); 48 void drawMap(WorldMap* gameMap); 47 49 void drawPlayers(map<unsigned int, Player>& mapPlayers, unsigned int curPlayerId); 50 POSITION screenToMap(POSITION pos); 51 POSITION mapToScreen(POSITION pos); 48 52 49 53 // callbacks … … 156 160 } 157 161 162 WorldMap* gameMap = WorldMap::createDefaultMap(); 163 158 164 wndLogin = new Window(0, 0, SCREEN_W, SCREEN_H); 159 165 wndLogin->addComponent(new Textbox(104, 40, 100, 20, font)); … … 306 312 msgTo.type = MSG_TYPE_PLAYER_MOVE; 307 313 308 memcpy(msgTo.buffer, &curPlayerId, 4); 309 memcpy(msgTo.buffer+4, &ev.mouse.x, 4); 310 memcpy(msgTo.buffer+8, &ev.mouse.y, 4); 311 312 sendMessage(&msgTo, sock, &server); 314 POSITION pos; 315 pos.x = ev.mouse.x; 316 pos.y = ev.mouse.y; 317 pos = screenToMap(pos); 318 319 if (pos.x != -1) 320 { 321 memcpy(msgTo.buffer, &curPlayerId, 4); 322 memcpy(msgTo.buffer+4, &pos.x, 4); 323 memcpy(msgTo.buffer+8, &pos.y, 4); 324 325 sendMessage(&msgTo, sock, &server); 326 } 327 else 328 cout << "Invalid point: User did not click on the map" << endl; 313 329 } 314 330 } … … 326 342 wndCurrent->draw(display); 327 343 328 drawPlayers(mapPlayers, curPlayerId);329 330 344 chatConsole.draw(font, al_map_rgb(255,255,255)); 331 345 … … 336 350 else if(wndCurrent == wndMain) { 337 351 al_draw_text(font, al_map_rgb(0, 255, 0), 4, 43, ALLEGRO_ALIGN_LEFT, "Message:"); 352 353 drawMap(gameMap); 354 drawPlayers(mapPlayers, curPlayerId); 338 355 } 339 356 … … 352 369 delete wndLogin; 353 370 delete wndMain; 371 372 delete gameMap; 354 373 355 374 al_destroy_event_queue(event_queue); … … 392 411 WSACleanup(); 393 412 #endif 413 } 414 415 POSITION screenToMap(POSITION pos) 416 { 417 pos.x = pos.x-300; 418 pos.y = pos.y-100; 419 420 if (pos.x < 0 || pos.y < 0) 421 { 422 pos.x = -1; 423 pos.y = -1; 424 } 425 426 return pos; 427 } 428 429 POSITION mapToScreen(POSITION pos) 430 { 431 pos.x = pos.x+300; 432 pos.y = pos.y+100; 433 434 return pos; 394 435 } 395 436 … … 498 539 } 499 540 541 void drawMap(WorldMap* gameMap) 542 { 543 POSITION mapPos; 544 mapPos.x = 0; 545 mapPos.y = 0; 546 mapPos = mapToScreen(mapPos); 547 for (int x=0; x<12; x++) 548 { 549 for (int y=0; y<12; y++) 550 { 551 WorldMap::TerrainType el = gameMap->getElement(x, y); 552 553 if (el == WorldMap::TERRAIN_GRASS) 554 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)); 555 else if (el == WorldMap::TERRAIN_OCEAN) 556 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)); 557 else if (el == WorldMap::TERRAIN_ROCK) 558 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)); 559 } 560 } 561 } 562 500 563 void drawPlayers(map<unsigned int, Player>& mapPlayers, unsigned int curPlayerId) 501 564 { 502 565 map<unsigned int, Player>::iterator it; 566 567 Player* p; 568 POSITION pos; 503 569 504 570 for(it = mapPlayers.begin(); it != mapPlayers.end(); it++) 505 571 { 506 Player *p = &it->second; 572 p = &it->second; 573 pos = mapToScreen(p->pos); 507 574 508 575 if (p->id == curPlayerId) 509 al_draw_filled_circle(p ->pos.x, p->pos.y, 15, al_map_rgb(0, 255, 0));576 al_draw_filled_circle(pos.x, pos.y, 12, al_map_rgb(255, 0, 0)); 510 577 else 511 al_draw_filled_circle(p ->pos.x, p->pos.y, 30, al_map_rgb(255, 0, 0));578 al_draw_filled_circle(pos.x, pos.y, 12, al_map_rgb(191, 0, 0)); 512 579 } 513 580 }
Note:
See TracChangeset
for help on using the changeset viewer.