Index: common/Common.h
===================================================================
--- common/Common.h	(revision 62ee2ceb8ecee33c00a41267ea1c22a94758a04d)
+++ common/Common.h	(revision 60017fc77171d89da05e3eaab5eb4a9c3d0a0f6e)
@@ -20,3 +20,9 @@
 } POSITION;
 
+typedef struct
+{
+   float x;
+   float y;
+} FLOAT_POSITION;
+
 #endif
Index: common/Player.cpp
===================================================================
--- common/Player.cpp	(revision 62ee2ceb8ecee33c00a41267ea1c22a94758a04d)
+++ common/Player.cpp	(revision 60017fc77171d89da05e3eaab5eb4a9c3d0a0f6e)
@@ -4,4 +4,5 @@
 #include <sstream>
 #include <cstring>
+#include <cmath>
 
 using namespace std;
@@ -12,6 +13,6 @@
    this->name = "";
    this->password = "";
-   this->pos.x = 0;
-   this->pos.y = 0;
+   this->pos.x = this->target.x = 0;
+   this->pos.y = this->target.y = 0;
 }
 
@@ -23,4 +24,6 @@
    this->pos.x = p.pos.x;
    this->pos.y = p.pos.y;
+   this->target.x = p.target.x;
+   this->target.y = p.target.y;
    this->addr = p.addr;
 }
@@ -31,6 +34,6 @@
    this->name = name;
    this->password = password;
-   this->pos.x = 200;
-   this->pos.y = 200;
+   this->pos.x = this->target.x = 200;
+   this->pos.y = this->target.y = 200;
 }
 
@@ -40,6 +43,6 @@
    this->name = name;
    this->password = "";
-   this->pos.x = 200;
-   this->pos.y = 200;
+   this->pos.x = this->target.x = 200;
+   this->pos.y = this->target.y = 200;
    this->addr = addr;
 }
@@ -79,2 +82,36 @@
    this->addr = addr;
 }
+
+void Player::move(void) {
+   // timeLastMoved
+   // pos
+   // target
+   int speed = 100; // pixels per second
+
+   timespec curTS, diffTS;
+   clock_gettime(CLOCK_REALTIME, &curTS);
+
+   // get time elapsed
+   diffTS.tv_sec = curTS.tv_sec - timeLastUpdated.tv_sec;
+   diffTS.tv_nsec = curTS.tv_nsec - timeLastUpdated.tv_nsec;
+   if (diffTS.tv_nsec < 0) {
+      diffTS.tv_sec -= 1;
+      diffTS.tv_nsec += 1000000000;
+   }
+
+   cout << "elapsed secs: " << diffTS.tv_sec << endl;
+   cout << "elapsed nsecs: " << diffTS.tv_nsec << endl;
+
+   // here we move 100 pixels per second
+   float pixels = 100 * (diffTS.tv_sec+diffTS.tv_nsec/1000000000.0);
+   cout << "We need to move " << pixels << "pixels" << endl;
+
+   double angle = atan2(target.y-pos.y, target.x-pos.x);
+
+   // we just need to check that we don't overjump the target
+   pos.x += cos(angle)*pixels;
+   pos.y += sin(angle)*pixels;
+
+   timeLastUpdated.tv_sec = curTS.tv_sec;
+   timeLastUpdated.tv_nsec = curTS.tv_nsec;
+}
Index: common/Player.h
===================================================================
--- common/Player.h	(revision 62ee2ceb8ecee33c00a41267ea1c22a94758a04d)
+++ common/Player.h	(revision 60017fc77171d89da05e3eaab5eb4a9c3d0a0f6e)
@@ -12,4 +12,5 @@
 
 #include <string>
+#include <sys/time.h>
 
 #include "Common.h"
@@ -32,9 +33,13 @@
    void setAddr(sockaddr_in addr);
 
+   void move();
+
    int id;
    string name;
    string password;
    sockaddr_in addr;
-   POSITION pos;
+   FLOAT_POSITION pos;
+   POSITION target;
+   timespec timeLastUpdated;
 };
 
Index: server/DataAccess.cpp
===================================================================
--- server/DataAccess.cpp	(revision 62ee2ceb8ecee33c00a41267ea1c22a94758a04d)
+++ server/DataAccess.cpp	(revision 60017fc77171d89da05e3eaab5eb4a9c3d0a0f6e)
@@ -81,7 +81,8 @@
    }
 
-   if ( ( row = mysql_fetch_row(result)) != NULL )
+   if ( ( row = mysql_fetch_row(result)) != NULL ) {
+      cout << "Creating a new player" << endl;
       p = new Player(string(row[1]), string(row[2]));
-   else {
+   }else {
       cout << "Returned no results for some reason" << endl;
       p = NULL;
Index: server/makefile
===================================================================
--- server/makefile	(revision 62ee2ceb8ecee33c00a41267ea1c22a94758a04d)
+++ server/makefile	(revision 60017fc77171d89da05e3eaab5eb4a9c3d0a0f6e)
@@ -1,7 +1,7 @@
 CC = g++
-LIB_FLAGS = -lssl -lmysqlclient -lcrypt
+LIB_FLAGS = -lssl -lmysqlclient -lcrypt -lrt
 FLAGS = $(LIB_FLAGS)
 COMMON_PATH = ../common
-DEPENDENCIES = Common.o Message.o Player.o Map.o DataAccess.o
+DEPENDENCIES = Common.o Message.o Player.o WorldMap.o DataAccess.o
 
 server : server.cpp $(DEPENDENCIES)
@@ -17,5 +17,5 @@
 	$(CC) -c -o $@ $?
 
-Map.o : $(COMMON_PATH)/Map.cpp
+WorldMap.o : $(COMMON_PATH)/WorldMap.cpp
 	$(CC) -c -o $@ $?
 
Index: server/server.cpp
===================================================================
--- server/server.cpp	(revision 62ee2ceb8ecee33c00a41267ea1c22a94758a04d)
+++ server/server.cpp	(revision 60017fc77171d89da05e3eaab5eb4a9c3d0a0f6e)
@@ -6,4 +6,6 @@
 #include <sstream>
 #include <cstring>
+#include <cmath>
+#include <sys/time.h>
 
 #include <vector>
@@ -26,4 +28,5 @@
 #include "../common/Common.h"
 #include "../common/Message.h"
+#include "../common/WorldMap.h"
 #include "../common/Player.h"
 
@@ -32,5 +35,5 @@
 using namespace std;
 
-bool processMessage(const NETWORK_MSG &clientMsg, const struct sockaddr_in &from, map<unsigned int, Player>& mapPlayers, unsigned int& unusedId, NETWORK_MSG &serverMsg);
+bool processMessage(const NETWORK_MSG &clientMsg, const struct sockaddr_in &from, map<unsigned int, Player>& mapPlayers, WorldMap* gameMap, unsigned int& unusedId, NETWORK_MSG &serverMsg);
 
 void updateUnusedId(unsigned int& id, map<unsigned int, Player>& mapPlayers);
@@ -106,4 +109,6 @@
       exit(1);
    }
+
+   WorldMap* gameMap = WorldMap::createDefaultMap();
  
    sock = socket(AF_INET, SOCK_DGRAM, 0);
@@ -119,4 +124,15 @@
    set_nonblock(sock);
 
+   Player testP;
+   clock_gettime(CLOCK_REALTIME, &testP.timeLastUpdated);
+
+   cout << "Before sleep" << endl;
+   // wait some time
+   sleep(3);
+   cout << "After sleep" << endl;
+
+   testP.move();
+
+/*
    bool broadcastResponse;
    while (true) {
@@ -129,5 +145,5 @@
          cout << "Got a message" << endl;
 
-         broadcastResponse = processMessage(clientMsg, from, mapPlayers, unusedId, serverMsg);
+         broadcastResponse = processMessage(clientMsg, from, mapPlayers, gameMap, unusedId, serverMsg);
 
          // probably replace this with a function that prints based on the
@@ -158,9 +174,10 @@
       }
    }
+*/
 
    return 0;
 }
 
-bool processMessage(const NETWORK_MSG& clientMsg, const struct sockaddr_in& from, map<unsigned int, Player>& mapPlayers, unsigned int& unusedId, NETWORK_MSG& serverMsg)
+bool processMessage(const NETWORK_MSG& clientMsg, const struct sockaddr_in& from, map<unsigned int, Player>& mapPlayers, WorldMap* gameMap, unsigned int& unusedId, NETWORK_MSG& serverMsg)
 {
    DataAccess da;
@@ -199,4 +216,6 @@
       case MSG_TYPE_LOGIN:
       {
+         cout << "Got login message" << endl;
+
          string username(clientMsg.buffer);
          string password(strchr(clientMsg.buffer, '\0')+1);
@@ -287,4 +306,6 @@
       case MSG_TYPE_PLAYER_MOVE:
       {
+         cout << "Got a move message" << endl;
+
          istringstream iss;
          iss.str(clientMsg.buffer);
@@ -305,11 +326,39 @@
               mapPlayers[id].addr.sin_port == from.sin_port )
          {
-            memcpy(&mapPlayers[id].pos.x, clientMsg.buffer+4, 4);
-            memcpy(&mapPlayers[id].pos.y, clientMsg.buffer+8, 4);
-
-            serverMsg.type = MSG_TYPE_PLAYER_MOVE;
-            memcpy(serverMsg.buffer, clientMsg.buffer, 12);
-
-            broadcastResponse = true;
+            // we need to make sure the player can move here
+            if (0 <= x && x < 300 && 0 <= y && y < 300 &&
+               gameMap->getElement(x/25, y/25) == WorldMap::TERRAIN_GRASS)
+            {
+               // first we get the correct vector 
+               mapPlayers[id].target.x = x;
+               mapPlayers[id].target.y = y;
+               int xDiff = mapPlayers[id].target.x - mapPlayers[id].pos.x;
+               int yDiff = mapPlayers[id].target.y - mapPlayers[id].pos.y;
+               cout << "xDiff: " << xDiff << endl;               
+               cout << "yDiff: " << yDiff << endl;               
+
+               // then we get the correct angle
+               double angle = atan2(yDiff, xDiff);
+               cout << "angle: " << angle << endl;               
+
+               // finally we use the angle to determine
+               // how much the player moves
+               // the player will move 50 pixels in the correct direction
+               mapPlayers[id].pos.x += cos(angle)*50;
+               mapPlayers[id].pos.y += sin(angle)*50;
+               cout << "new x: " << mapPlayers[id].pos.x << endl;               
+               cout << "new y: " << mapPlayers[id].pos.y << endl;               
+
+               serverMsg.type = MSG_TYPE_PLAYER_MOVE;
+               
+               memcpy(serverMsg.buffer, &id, 4);
+               memcpy(serverMsg.buffer+4, &mapPlayers[id].pos.x, 4);
+               memcpy(serverMsg.buffer+8, &mapPlayers[id].pos.y, 4);
+               //memcpy(serverMsg.buffer, clientMsg.buffer, 12);
+
+               broadcastResponse = true;
+            }
+            else
+               cout << "Bad terrain detected" << endl;
          }
          else  // nned to send back a message indicating failure
@@ -328,4 +377,6 @@
    }
 
+   cout << "Got to the end of the switch" << endl;
+
    return broadcastResponse;
 }
