- Timestamp:
- Apr 23, 2013, 1:31:54 AM (12 years ago)
- Branches:
- master
- Children:
- 227baaa
- Parents:
- 054b50b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
r054b50b ra1a3bd5 75 75 bool doexit; 76 76 77 map<unsigned int, Player> mapPlayers;78 79 77 Window* wndLogin; 80 78 Window* wndMain; … … 226 224 } 227 225 else if(ev.type == ALLEGRO_EVENT_TIMER) { 228 redraw = true; 226 redraw = true; // seems like we should just call a draw function here instead 229 227 } 230 228 else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { 231 229 doexit = true; 230 231 // perform a check to see if it's time to send an update to the server 232 // need to store num ticks since the lst update for this 233 // also check how often each update actually happens and how much it deviates from 60 times per second 232 234 } 233 235 else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { … … 264 266 if (receiveMessage(&msgFrom, sock, &from) >= 0) 265 267 processMessage(msgFrom, state, chatConsole, mapPlayers, curPlayerId); 266 267 // update player positions 268 map<unsigned int, Player>::iterator it; 269 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) 270 { 271 it->second.move(); 272 } 273 274 if (redraw && al_is_event_queue_empty(event_queue)) 268 269 if (redraw) 275 270 { 276 271 redraw = false; … … 286 281 else if(wndCurrent == wndMain) { 287 282 al_draw_text(font, al_map_rgb(0, 255, 0), 4, 43, ALLEGRO_ALIGN_LEFT, "Message:"); 283 284 // update player positions 285 map<unsigned int, Player>::iterator it; 286 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) 287 { 288 it->second.move(); // ignore return value 289 } 288 290 289 291 drawMap(gameMap); … … 382 384 { 383 385 string response = string(msg.buffer); 386 387 cout << "Processing message" << endl; 388 cout << response << endl; 384 389 385 390 switch(state) … … 419 424 cout << "Got a valid login response with the player" << endl; 420 425 cout << "Player id: " << curPlayerId << endl; 426 cout << "map size: " << mapPlayers.size() << endl; 421 427 } 428 429 break; 430 } 431 case MSG_TYPE_PLAYER: // kind of hacky to put this here 432 { 433 cout << "Got MSG_TYPE_PLAYER message in Start" << endl; 434 435 Player p("", ""); 436 p.deserialize(msg.buffer); 437 p.timeLastUpdated = getCurrentMillis(); 438 mapPlayers[p.id] = p; 439 440 cout << "new player id: " << p.id << endl; 441 cout << "map size: " << mapPlayers.size() << endl; 422 442 423 443 break; … … 437 457 case MSG_TYPE_LOGIN: 438 458 { 459 cout << "Got a login message" << endl; 460 439 461 chatConsole.addLine(response); 440 462 cout << "Added new line" << endl; 463 464 break; 465 } 466 case MSG_TYPE_LOGOUT: 467 { 441 468 cout << "Got a logout message" << endl; 469 442 470 if (response.compare("You have successfully logged out.") == 0) 443 471 { … … 446 474 wndCurrent = wndLogin; 447 475 } 448 else449 {450 cout << "Added new line" << endl;451 }452 453 break;454 }455 case MSG_TYPE_LOGOUT:456 {457 cout << "Got a logout message, but we don't process it" << endl;458 476 459 477 break; … … 461 479 case MSG_TYPE_PLAYER: 462 480 { 481 cout << "Got MSG_TYPE_PLAYER message in Login" << endl; 482 463 483 Player p("", ""); 464 484 p.deserialize(msg.buffer); 465 485 p.timeLastUpdated = getCurrentMillis(); 466 486 mapPlayers[p.id] = p; 487 488 break; 489 } 490 case MSG_TYPE_PLAYER_MOVE: 491 { 492 cout << "Got a player move message" << endl; 493 494 unsigned int id; 495 int x, y; 496 497 memcpy(&id, msg.buffer, 4); 498 memcpy(&x, msg.buffer+4, 4); 499 memcpy(&y, msg.buffer+8, 4); 500 501 mapPlayers[id].target.x = x; 502 mapPlayers[id].target.y = y; 467 503 468 504 break; … … 498 534 { 499 535 WorldMap::TerrainType el = gameMap->getElement(x, y); 536 WorldMap::ObjectType obj = gameMap->getObject(x, y); 500 537 501 538 if (el == WorldMap::TERRAIN_GRASS) … … 505 542 else if (el == WorldMap::TERRAIN_ROCK) 506 543 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)); 544 545 if (obj == WorldMap::OBJECT_RED_FLAG) 546 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)); 547 else if (obj == WorldMap::OBJECT_BLUE_FLAG) 548 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)); 507 549 } 508 550 }
Note:
See TracChangeset
for help on using the changeset viewer.