Changeset 402cf86 in network-game
- Timestamp:
- Dec 20, 2013, 1:41:49 AM (11 years ago)
- Branches:
- master
- Children:
- 6c9bcdd
- Parents:
- fef7c69
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Game.cpp
rfef7c69 r402cf86 88 88 } 89 89 90 // returns true if the movement should be canceled 91 bool Game::processPlayerMovement(Player* p, FLOAT_POSITION oldPos) { 92 93 // check if the move needs to be canceled 94 switch(this->worldMap->getElement(p->pos.x/25, p->pos.y/25)) 95 { 96 case WorldMap::TERRAIN_NONE: 97 case WorldMap::TERRAIN_OCEAN: 98 case WorldMap::TERRAIN_ROCK: 99 { 100 p->pos = oldPos; 101 p->target.x = p->pos.x; 102 p->target.y = p->pos.y; 103 p->isChasing = false; 104 return true; 105 break; 106 } 107 default: 108 // if there are no obstacles, don't cancel movement 109 return false; 110 break; 111 } 112 } 113 90 114 void Game::setRedScore(int score) { 91 115 this->redScore = score; -
common/Game.h
rfef7c69 r402cf86 42 42 bool removePlayer(unsigned int id); 43 43 bool startPlayerMovement(unsigned int id, int x, int y); 44 bool processPlayerMovement(Player* p, FLOAT_POSITION oldPos); 45 44 46 void setBlueScore(int score); 45 47 void setRedScore(int score); -
data/map.txt
rfef7c69 r402cf86 10 10 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2 11 11 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2 12 2,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,212 2,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,3,1,1,1,1,1,1,2 13 13 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2 14 14 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2 -
server/server.cpp
rfef7c69 r402cf86 138 138 while (!done) 139 139 { 140 141 140 usleep(5000); 142 141 … … 217 216 } 218 217 219 // move all players 220 // maybe put this in a separate method 218 // process players currently in a game 221 219 FLOAT_POSITION oldPos; 222 bool broadcastMove = false;223 220 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) 224 221 { 222 bool broadcastMove = false; 223 224 // move player and perform associated tasks 225 225 oldPos = it->second->pos; 226 if (it->second->move(gameMap)) { 227 228 // check if the move needs to be canceled 229 switch(gameMap->getElement(it->second->pos.x/25, it->second->pos.y/25)) 230 { 231 case WorldMap::TERRAIN_NONE: 232 case WorldMap::TERRAIN_OCEAN: 233 case WorldMap::TERRAIN_ROCK: 234 { 235 it->second->pos = oldPos; 236 it->second->target.x = it->second->pos.x; 237 it->second->target.y = it->second->pos.y; 238 it->second->isChasing = false; 239 broadcastMove = true; 240 break; 241 } 242 default: 243 // if there are no obstacles, do nothing 244 break; 245 } 246 226 if (it->second->move(it->second->currentGame->getMap())) { 227 228 if (it->second->currentGame->processPlayerMovement(it->second, oldPos)) 229 broadcastMove = true; 230 231 /* 247 232 WorldMap::ObjectType flagType; 248 233 POSITION pos; … … 397 382 } 398 383 } 384 */ 399 385 400 386 if (broadcastMove) … … 403 389 it->second->serialize(serverMsg.buffer); 404 390 391 // only broadcast message to other players in the same game 405 392 cout << "about to broadcast move" << endl; 393 394 map<unsigned int, Player*> playersInGame = it->second->currentGame->getPlayers(); 406 395 map<unsigned int, Player*>::iterator it2; 407 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)396 for (it2 = playersInGame.begin(); it2 != playersInGamePlayers.end(); it2++) 408 397 { 409 398 if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 )
Note:
See TracChangeset
for help on using the changeset viewer.