Game Development Reference
In-Depth Information
if (nextPosition.x < player->radius())
nextPosition.x = player->radius();
if (nextPosition.x > _screenSize.width -
player->radius())
nextPosition.x = _screenSize.width -
player->radius();
if (nextPosition.y < player->radius())
nextPosition.y = player->radius();
if (nextPosition.y > _screenSize.height -
player->radius())
nextPosition.y = _screenSize.height -
player->radius();
//keep player inside its court
if (player->getPositionY() < _screenSize.height*
0.5f) {
if (nextPosition.y > _screenSize.height* 0.5 -
player->radius()) {
nextPosition.y = _screenSize.height* 0.5 -
player->radius();
}
} else {
if (nextPosition.y < _screenSize.height* 0.5 +
player->radius()) {
nextPosition.y = _screenSize.height* 0.5 +
player->radius();
}
}
player->setNextPosition(nextPosition);
player->setVector(Vec2(tap.x -
player->getPositionX(), tap.y -
player->getPositionY()));
}
}
We check to see if the _touch property stored inside the player is the being
moved now. If so, we update the player's position with the touch's current posi-
tion, but we check to see if the new position is valid: a player cannot move out-
side the screen and cannot enter its opponent's court. We also update the player's
Search WWH ::




Custom Search