Changeset a1a3bd5 in network-game for common/Player.cpp
- Timestamp:
- Apr 23, 2013, 1:31:54 AM (12 years ago)
- Branches:
- master
- Children:
- 227baaa
- Parents:
- 054b50b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Player.cpp
r054b50b ra1a3bd5 83 83 } 84 84 85 void Player::move(void) {85 bool Player::move(WorldMap map) { 86 86 int speed = 100; // pixels per second 87 87 unsigned long long curTime = getCurrentMillis(); 88 bool moveCanceled = false; 88 89 89 90 // if we're at our target, don't move 90 91 if (pos.x != target.x || pos.y != target.y) { 91 92 float pixels = speed * (curTime-timeLastUpdated) / 1000.0; 93 double angle = atan2(target.y-pos.y, target.x-pos.x); 94 float dist = sqrt(pow(target.x-pos.x, 2) + pow(target.y-pos.y, 2)); 95 POSITION newPos; 92 96 93 double angle = atan2(target.y-pos.y, target.x-pos.x);94 95 float dist = sqrt(pow(target.x-pos.x, 2) + pow(target.y-pos.y, 2));96 97 if (dist <= pixels) { 97 98 pos.x = target.x; 98 99 pos.y = target.y; 99 100 }else { 100 pos.x += cos(angle)*pixels; 101 pos.y += sin(angle)*pixels; 101 newPos.x = int(pos.x + cos(angle)*pixels); 102 newPos.y = int(pos.y + sin(angle)*pixels); 103 104 switch(map.getElement(newPos.x/25, newPos.y/25)) { 105 case WorldMap.TerrainType.TERRAIN_OCEAN: 106 case WorldMap.TerrainType.TERRAIN_ROCK: 107 target.x = pos.x; 108 target.y = pos.y; 109 moveCanceled = true; 110 break; 111 } 102 112 } 103 113 } 104 114 105 115 timeLastUpdated = curTime; 116 return !moveCanceled; 106 117 }
Note:
See TracChangeset
for help on using the changeset viewer.