Changeset 23559e7 in network-game for common/Player.cpp
- Timestamp:
- May 24, 2013, 1:23:49 AM (12 years ago)
- Branches:
- master
- Children:
- b81cea1
- Parents:
- 45b2750
- git-author:
- dportnoy <dmp1488@…> (05/24/13 01:14:53)
- git-committer:
- dportnoy <dmp1488@…> (05/24/13 01:23:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Player.cpp
r45b2750 r23559e7 89 89 90 90 bool Player::move(WorldMap *map) { 91 int speed = 100; // pixels per second 91 int speed = 100; // pixels per second. should probably be in the constructor 92 92 unsigned long long curTime = getCurrentMillis(); 93 bool moveCanceled = false;94 93 95 94 // if we're at our target, don't move 96 if (pos.x != target.x || pos.y != target.y) { 95 bool moving = (pos.x != target.x || pos.y != target.y); 96 97 if (moving) { 97 98 float pixels = speed * (curTime-timeLastUpdated) / 1000.0; 98 99 double angle = atan2(target.y-pos.y, target.x-pos.x); … … 107 108 newPos.y = pos.y + sin(angle)*pixels; 108 109 } 109 110 switch(map->getElement(newPos.x/25, newPos.y/25)) {111 case WorldMap::TERRAIN_NONE:112 case WorldMap::TERRAIN_OCEAN:113 case WorldMap::TERRAIN_ROCK:114 target.x = pos.x;115 target.y = pos.y;116 moveCanceled = true;117 break;118 default: // if there are no obstacles119 pos.x = newPos.x;120 pos.y = newPos.y;121 break;122 }123 124 // using moveCanceled in a hacky way just to indicate that the server125 // has updated some player info. Should change the variable name126 switch(map->getStructure(newPos.x/25, newPos.y/25)) {127 case WorldMap::STRUCTURE_BLUE_FLAG:128 hasBlueFlag = true;129 moveCanceled = true;130 break;131 case WorldMap::STRUCTURE_RED_FLAG:132 hasRedFlag = true;133 moveCanceled = true;134 break;135 }136 110 } 137 111 138 112 timeLastUpdated = curTime; 139 113 140 return !moveCanceled;114 return moving; 141 115 }
Note:
See TracChangeset
for help on using the changeset viewer.