Changeset d211210 in network-game for common


Ignore:
Timestamp:
May 9, 2013, 1:32:42 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
db58227
Parents:
227baaa
Message:

Add server-side checking of player movement

File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/Player.cpp

    r227baaa rd211210  
    9595      POSITION newPos;
    9696
     97      //cout << "pos.x: " << pos.x << endl;
     98      //cout << "pos.y: " << pos.y << endl;
     99      //cout << "target.x: " << target.x << endl;
     100      //cout << "target.y: " << target.y << endl;
     101
    97102      if (dist <= pixels) {
    98          pos.x = target.x;
    99          pos.y = target.y;
     103         newPos.x = target.x;
     104         newPos.y = target.y;
    100105      }else {
    101106         newPos.x = int(pos.x + cos(angle)*pixels);
    102107         newPos.y = int(pos.y + sin(angle)*pixels);
     108      }
    103109
    104          switch(map->getElement(newPos.x/25, newPos.y/25)) {
    105          case WorldMap::TERRAIN_NONE:
    106          case WorldMap::TERRAIN_ROCK:
    107             target.x = pos.x;
    108             target.y = pos.y;
    109             moveCanceled = true;
    110             break;
    111          }
     110      //cout << "newPos.x: " << newPos.x << endl;
     111      //cout << "newPos.y: " << newPos.y << endl;
     112      //cout << "newPos.x/25: " << newPos.x/25 << endl;
     113      //cout << "newPos.y/25: " << newPos.y/25 << endl;
     114
     115      switch(map->getElement(newPos.x/25, newPos.y/25)) {
     116      case WorldMap::TERRAIN_NONE:
     117      case WorldMap::TERRAIN_ROCK:
     118         cout << "Encountered invalid terrain" << endl;
     119         target.x = pos.x;
     120         target.y = pos.y;
     121         moveCanceled = true;
     122         cout << "move canceled" << endl;
     123         break;
     124      default: // if there are no obstacles
     125         pos.x = newPos.x;
     126         pos.y = newPos.y;
     127         break;
    112128      }
    113129   }
    114130
    115131   timeLastUpdated = curTime;
     132
     133   if (moveCanceled)
     134      cout << "moveCancled == true" << endl;
     135
    116136   return !moveCanceled;
    117137}
Note: See TracChangeset for help on using the changeset viewer.