Changeset 23559e7 in network-game for common/Player.cpp


Ignore:
Timestamp:
May 24, 2013, 1:23:49 AM (12 years ago)
Author:
dportnoy <dmp1488@…>
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)
Message:

Move player interaction with objects on the map from Player::move to the server

File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/Player.cpp

    r45b2750 r23559e7  
    8989
    9090bool Player::move(WorldMap *map) {
    91    int speed = 100; // pixels per second
     91   int speed = 100; // pixels per second. should probably be in the constructor
    9292   unsigned long long curTime = getCurrentMillis();
    93    bool moveCanceled = false;
    9493
    9594   // 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) {
    9798      float pixels = speed * (curTime-timeLastUpdated) / 1000.0;
    9899      double angle = atan2(target.y-pos.y, target.x-pos.x);
     
    107108         newPos.y = pos.y + sin(angle)*pixels;
    108109      }
    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 obstacles
    119          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 server
    125       // has updated some player info. Should change the variable name
    126       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       }
    136110   }
    137111
    138112   timeLastUpdated = curTime;
    139113
    140    return !moveCanceled;
     114   return moving;
    141115}
Note: See TracChangeset for help on using the changeset viewer.