本文整理汇总了C++中Joystick::enabled方法的典型用法代码示例。如果您正苦于以下问题:C++ Joystick::enabled方法的具体用法?C++ Joystick::enabled怎么用?C++ Joystick::enabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Joystick
的用法示例。
在下文中一共展示了Joystick::enabled方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void Vampire::update(double delta){
const timer_t timeElapsed = static_cast<timer_t>(delta * DELTA_MODIFIER);
if (state != BURNING){
VampireState oldState = state;
//movement through arrow keys
bool up = false;
bool down = false;
bool left = false;
bool right = false;
double distance = 0.0;
{
up |= isKeyPressed(SDLK_UP);
down |= isKeyPressed(SDLK_DOWN);
left |= isKeyPressed(SDLK_LEFT);
right |= isKeyPressed(SDLK_RIGHT);
if (up && down)
up = down = false;
if (left && right)
left = right = false;
distance = delta * SPEED;
if ((up || down) && (left || right))
//diagonal movement
distance *= INV_SQRT2; //for each of the two directions
if (up){
loc_.y -= distance;
lastUpDown = DIR_U;
}else if (down){
loc_.y += distance;
lastUpDown = DIR_D;
}
if (left){
loc_.x -= distance;
lastLeftRight = DIR_L;
}else if (right){
loc_.x += distance;
lastLeftRight = DIR_R;
}
}
// Movement through joystick
if (joystick.enabled())
{
const double JOY_SPEED = 0.55;
const double distanceX = joystick.getLeftRightAxis() * JOY_SPEED;
const double distanceY = joystick.getUpDownAxis() * JOY_SPEED;
up |= distanceY < 0;
down |= distanceY > 0;
left |= distanceX < 0;
right |= distanceX > 0;
const double dx = distanceX * delta * JOY_SPEED;
const double dy = distanceY * delta * JOY_SPEED;
if (up){
loc_.y += dy;
lastUpDown = DIR_U;
}
if (down){
loc_.y += dy;
lastUpDown = DIR_D;
}
if (left){
loc_.x += dx;
lastLeftRight = DIR_L;
}
if (right){
loc_.x += dx;
lastLeftRight = DIR_R;
}
}
if (loc_.x < gameState->leftBound)
loc_.x = gameState->leftBound;
if (loc_.x > gameState->rightBound)
loc_.x = gameState->rightBound;
if (loc_.y < gameState->topBound)
loc_.y = gameState->topBound;
if (loc_.y > gameState->bottomBound)
loc_.y = gameState->bottomBound;
if (state != ATTACKING)
state = MOVING;
if (up && right)
updateDirection(DIR_E);
else if (down && right)
updateDirection(DIR_F);
else if (down && left)
updateDirection(DIR_G);
else if (up && left)
updateDirection(DIR_H);
else if (up)
//.........这里部分代码省略.........