Changeset 402cf86 in network-game for common


Ignore:
Timestamp:
Dec 20, 2013, 1:41:49 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
6c9bcdd
Parents:
fef7c69
Message:

The server checks player movement in individual games and stops players who hit obstacles

Location:
common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • common/Game.cpp

    rfef7c69 r402cf86  
    8888}
    8989
     90// returns true if the movement should be canceled
     91bool Game::processPlayerMovement(Player* p, FLOAT_POSITION oldPos) {
     92
     93   // check if the move needs to be canceled
     94   switch(this->worldMap->getElement(p->pos.x/25, p->pos.y/25))
     95   {
     96      case WorldMap::TERRAIN_NONE:
     97      case WorldMap::TERRAIN_OCEAN:
     98      case WorldMap::TERRAIN_ROCK:
     99      {
     100         p->pos = oldPos;
     101         p->target.x = p->pos.x;
     102         p->target.y = p->pos.y;
     103         p->isChasing = false;
     104         return true;
     105         break;
     106      }
     107      default:
     108         // if there are no obstacles, don't cancel movement
     109         return false;
     110         break;
     111      }
     112}
     113
    90114void Game::setRedScore(int score) {
    91115   this->redScore = score;
  • common/Game.h

    rfef7c69 r402cf86  
    4242   bool removePlayer(unsigned int id);
    4343   bool startPlayerMovement(unsigned int id, int x, int y);
     44   bool processPlayerMovement(Player* p, FLOAT_POSITION oldPos);
     45
    4446   void setBlueScore(int score);
    4547   void setRedScore(int score);
Note: See TracChangeset for help on using the changeset viewer.