Changes in common/Player.cpp [60017fc:5806dc2] in network-game
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Player.cpp
r60017fc r5806dc2 4 4 #include <sstream> 5 5 #include <cstring> 6 #include <cmath>7 6 8 7 using namespace std; … … 13 12 this->name = ""; 14 13 this->password = ""; 15 this->pos.x = this->target.x =0;16 this->pos.y = this->target.y =0;14 this->pos.x = 0; 15 this->pos.y = 0; 17 16 } 18 17 … … 24 23 this->pos.x = p.pos.x; 25 24 this->pos.y = p.pos.y; 26 this->target.x = p.target.x;27 this->target.y = p.target.y;28 25 this->addr = p.addr; 29 26 } … … 34 31 this->name = name; 35 32 this->password = password; 36 this->pos.x = this->target.x =200;37 this->pos.y = this->target.y =200;33 this->pos.x = 200; 34 this->pos.y = 200; 38 35 } 39 36 … … 43 40 this->name = name; 44 41 this->password = ""; 45 this->pos.x = this->target.x =200;46 this->pos.y = this->target.y =200;42 this->pos.x = 200; 43 this->pos.y = 200; 47 44 this->addr = addr; 48 45 } … … 82 79 this->addr = addr; 83 80 } 84 85 void Player::move(void) {86 // timeLastMoved87 // pos88 // target89 int speed = 100; // pixels per second90 91 timespec curTS, diffTS;92 clock_gettime(CLOCK_REALTIME, &curTS);93 94 // get time elapsed95 diffTS.tv_sec = curTS.tv_sec - timeLastUpdated.tv_sec;96 diffTS.tv_nsec = curTS.tv_nsec - timeLastUpdated.tv_nsec;97 if (diffTS.tv_nsec < 0) {98 diffTS.tv_sec -= 1;99 diffTS.tv_nsec += 1000000000;100 }101 102 cout << "elapsed secs: " << diffTS.tv_sec << endl;103 cout << "elapsed nsecs: " << diffTS.tv_nsec << endl;104 105 // here we move 100 pixels per second106 float pixels = 100 * (diffTS.tv_sec+diffTS.tv_nsec/1000000000.0);107 cout << "We need to move " << pixels << "pixels" << endl;108 109 double angle = atan2(target.y-pos.y, target.x-pos.x);110 111 // we just need to check that we don't overjump the target112 pos.x += cos(angle)*pixels;113 pos.y += sin(angle)*pixels;114 115 timeLastUpdated.tv_sec = curTS.tv_sec;116 timeLastUpdated.tv_nsec = curTS.tv_nsec;117 }
Note:
See TracChangeset
for help on using the changeset viewer.