Changeset 7b43385 in network-game


Ignore:
Timestamp:
Feb 24, 2013, 1:31:44 AM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
3d81c0d, 60940f8
Parents:
ca44f82
Message:

Smooth player movement now works, albeit poorly.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • common/Message.cpp

    rca44f82 r7b43385  
    1919   int ret =  sendto(sock, (char*)msg, sizeof(NETWORK_MSG), 0, (struct sockaddr *)dest, sizeof(struct sockaddr_in));
    2020
    21    cout << "Sent message of type " << msg->type << endl;
    22 
    2321   return ret;
    2422}
     
    3129   int ret =  recvfrom(sock, (char*)msg, sizeof(NETWORK_MSG), 0, (struct sockaddr *)dest, &socklen);
    3230
    33    if (ret > -1)
    34       cout << "Received message of type " << msg->type << endl;
    35 
    3631   return ret;
    3732}
  • common/Player.cpp

    rca44f82 r7b43385  
    9898      cout << "We're already at our target" << endl;
    9999   else {
     100      cout << "equals test:" << endl;
     101      float f = 5.0;
     102      int i = 5;
     103
     104      if (f == i)
     105         cout << "test passed" << endl;
     106      else
     107         cout << "test failed" << endl;
     108
     109      cout << "Player about to be moved" << endl;
     110      cout << "cur pos x: " << this->pos.x << endl;
     111      cout << "cur pos y: " << this->pos.y << endl;
     112
    100113      float pixels = speed * (curTime-timeLastUpdated) / 1000.0;
    101114      cout << "We need to move " << pixels << " pixels" << endl;
     
    111124         pos.y += sin(angle)*pixels;
    112125      }
     126      cout << "new pos x: " << this->pos.x << endl;
     127      cout << "new pos y: " << this->pos.y << endl;
     128
    113129   }
    114130
  • common/WorldMap.cpp

    rca44f82 r7b43385  
    4141void WorldMap::setElement(int x, int y, TerrainType t)
    4242{
     43   cout << "getting element" << endl;
    4344   (*(*vctMap)[x])[y] = t;
    4445}
  • server/server.cpp

    rca44f82 r7b43385  
    109109   }
    110110
    111    WorldMap* gameMap = NULL; //WorldMap::createDefaultMap();
     111   WorldMap* gameMap = WorldMap::loadMapFromFile("../data/map.txt");
    112112 
    113113   sock = socket(AF_INET, SOCK_DGRAM, 0);
     
    157157               error("sendMessage");
    158158         }
    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);
    169169   }
    170170
     
    176176   DataAccess da;
    177177
    178    cout << "ip address: " << inet_ntoa(from.sin_addr) << endl;
    179    cout << "port: " << from.sin_port << endl;
    180178   cout << "MSG: type: " << clientMsg.type << endl;
    181179   cout << "MSG contents: " << clientMsg.buffer << endl;
     
    299297      case MSG_TYPE_PLAYER_MOVE:
    300298      {
    301          cout << "Got a move message" << endl;
    302 
    303299         istringstream iss;
    304300         iss.str(clientMsg.buffer);
     
    311307         memcpy(&x, clientMsg.buffer+4, 4);
    312308         memcpy(&y, clientMsg.buffer+8, 4);
    313          
     309
    314310         cout << "x: " << x << endl;
    315311         cout << "y: " << y << endl;
    316312         cout << "id: " << id << endl;
    317 
     313         
    318314         if ( mapPlayers[id].addr.sin_addr.s_addr == from.sin_addr.s_addr &&
    319315              mapPlayers[id].addr.sin_port == from.sin_port )
     
    323319               gameMap->getElement(x/25, y/25) == WorldMap::TERRAIN_GRASS)
    324320            {
    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
    326326               mapPlayers[id].target.x = x;
    327327               mapPlayers[id].target.y = y;
    328328               int xDiff = mapPlayers[id].target.x - mapPlayers[id].pos.x;
    329329               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;
    332332
    333333               // then we get the correct angle
    334334               double angle = atan2(yDiff, xDiff);
    335                cout << "angle: " << angle << endl;               
     335               cout << "angle: " << angle << endl;
    336336
    337337               // finally we use the angle to determine
    338338               // how much the player moves
    339339               // 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;
    344342
    345343               serverMsg.type = MSG_TYPE_PLAYER_MOVE;
Note: See TracChangeset for help on using the changeset viewer.