- Timestamp:
- Feb 24, 2013, 1:31:44 AM (12 years ago)
- Branches:
- master
- Children:
- 3d81c0d, 60940f8
- Parents:
- ca44f82
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/server.cpp
rca44f82 r7b43385 109 109 } 110 110 111 WorldMap* gameMap = NULL; //WorldMap::createDefaultMap();111 WorldMap* gameMap = WorldMap::loadMapFromFile("../data/map.txt"); 112 112 113 113 sock = socket(AF_INET, SOCK_DGRAM, 0); … … 157 157 error("sendMessage"); 158 158 } 159 160 // update player positions 161 map<unsigned int, Player>::iterator it;162 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)163 {164 it->second.move();165 }166 167 broadcastPlayerPositions(mapPlayers, sock); 168 }159 } 160 161 // update player positions 162 map<unsigned int, Player>::iterator it; 163 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) 164 { 165 it->second.move(); 166 } 167 168 broadcastPlayerPositions(mapPlayers, sock); 169 169 } 170 170 … … 176 176 DataAccess da; 177 177 178 cout << "ip address: " << inet_ntoa(from.sin_addr) << endl;179 cout << "port: " << from.sin_port << endl;180 178 cout << "MSG: type: " << clientMsg.type << endl; 181 179 cout << "MSG contents: " << clientMsg.buffer << endl; … … 299 297 case MSG_TYPE_PLAYER_MOVE: 300 298 { 301 cout << "Got a move message" << endl;302 303 299 istringstream iss; 304 300 iss.str(clientMsg.buffer); … … 311 307 memcpy(&x, clientMsg.buffer+4, 4); 312 308 memcpy(&y, clientMsg.buffer+8, 4); 313 309 314 310 cout << "x: " << x << endl; 315 311 cout << "y: " << y << endl; 316 312 cout << "id: " << id << endl; 317 313 318 314 if ( mapPlayers[id].addr.sin_addr.s_addr == from.sin_addr.s_addr && 319 315 mapPlayers[id].addr.sin_port == from.sin_port ) … … 323 319 gameMap->getElement(x/25, y/25) == WorldMap::TERRAIN_GRASS) 324 320 { 325 // first we get the correct vector 321 cout << "valid terrain" << endl; 322 323 cout << "orig x: " << mapPlayers[id].pos.x << endl; 324 cout << "orig y: " << mapPlayers[id].pos.y << endl; 325 // first we get the correct vector 326 326 mapPlayers[id].target.x = x; 327 327 mapPlayers[id].target.y = y; 328 328 int xDiff = mapPlayers[id].target.x - mapPlayers[id].pos.x; 329 329 int yDiff = mapPlayers[id].target.y - mapPlayers[id].pos.y; 330 cout << "xDiff: " << xDiff << endl; 331 cout << "yDiff: " << yDiff << endl; 330 cout << "xDiff: " << xDiff << endl; 331 cout << "yDiff: " << yDiff << endl; 332 332 333 333 // then we get the correct angle 334 334 double angle = atan2(yDiff, xDiff); 335 cout << "angle: " << angle << endl; 335 cout << "angle: " << angle << endl; 336 336 337 337 // finally we use the angle to determine 338 338 // how much the player moves 339 339 // the player will move 50 pixels in the correct direction 340 mapPlayers[id].pos.x += cos(angle)*50; 341 mapPlayers[id].pos.y += sin(angle)*50; 342 cout << "new x: " << mapPlayers[id].pos.x << endl; 343 cout << "new y: " << mapPlayers[id].pos.y << endl; 340 //mapPlayers[id].pos.x += cos(angle)*50; 341 //mapPlayers[id].pos.y += sin(angle)*50; 344 342 345 343 serverMsg.type = MSG_TYPE_PLAYER_MOVE;
Note:
See TracChangeset
for help on using the changeset viewer.