本文整理汇总了C++中Paddle::setSpeed方法的典型用法代码示例。如果您正苦于以下问题:C++ Paddle::setSpeed方法的具体用法?C++ Paddle::setSpeed怎么用?C++ Paddle::setSpeed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Paddle
的用法示例。
在下文中一共展示了Paddle::setSpeed方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateObjects
void WorldManager::updateObjects() {
Ball *ball = mWorld->getBall();
Paddle *leftPlayer = mWorld->getLeftPlayer();
Paddle *rightPlayer = mWorld->getRightPlayer();
if (isBallHitByLeftPaddle() || isBallHitByRightPaddle()) {
ball->reverseHorizontalDirection();
putBallAtPaddleEdge();
ball->setSpeed(ball->getSpeed() + SPEED_INC_STEP);
leftPlayer->setSpeed(leftPlayer->getSpeed() + SPEED_INC_STEP);
rightPlayer->setSpeed(rightPlayer->getSpeed() + SPEED_INC_STEP);
}
if (isBallCollideWithTopWall() || isBallCollideWithBottomWall()) {
ball->reverseVerticalDirection();
putBallAtWallEdge();
}
if (isBallCollideWithLeftWall() || isBallCollideWithRightWall()) {
ball->reset();
leftPlayer->reset();
rightPlayer->reset();
}
}
示例2: initGL
/* Initialize OpenGL Graphics */
void initGL() {
glClearColor(0.0, 0.0, 0.0, 1.0); // Set background (clear) color to black
GLfloat colorPaddle[4] = { 1.0f, 0.0f, 0.0f, 0.5f };
scoreLeft = 0;
scoreRight = 0;
ball.initBallSpeed(0.03, 0.0125);
ball.setColor(1.0f, 1.0f, 0.0f, 0.0f);
ball.setPaddleSpeedHitFactor(2.0);
paddleRight.setColor(colorPaddle);
paddleLeft.setColor(colorPaddle);
paddleRight.setLength(0.3f);
paddleRight.setWidth (0.1f);
paddleLeft.setLength(0.3f);
paddleLeft.setWidth(0.1f);
paddleRight.setSpeed(0.00f);
paddleRight.setMaxSpeed(0.02f);
paddleLeft.setSpeed(0.02f);
paddleLeft.setMaxSpeed(0.01f);
paddleLeft.setStartPos(0, 0);
paddleRight.setStartPos(0, 0);
}
示例3: specialKeys
/* Callback handler for special-key event */
void specialKeys(int key, int x, int y) {
switch (key) {
case GLUT_KEY_F1: // F1: Toggle between full-screen and windowed mode
fullScreenMode = !fullScreenMode; // Toggle state
if (fullScreenMode) { // Full-screen mode
windowPosX = glutGet(GLUT_WINDOW_X); // Save parameters for restoring later
windowPosY = glutGet(GLUT_WINDOW_Y);
windowWidth = glutGet(GLUT_WINDOW_WIDTH);
windowHeight = glutGet(GLUT_WINDOW_HEIGHT);
glutFullScreen(); // Switch into full screen
}
else { // Windowed mode
glutReshapeWindow(windowWidth, windowHeight); // Switch into windowed mode
glutPositionWindow(windowPosX, windowPosX); // Position top-left corner
}
break;
case GLUT_KEY_UP: // Up: increase y speed
paddleRight.setSpeed(paddleRight.getMaxSpeed());
break;
case GLUT_KEY_DOWN: // Down: decrease y speed
paddleRight.setSpeed(-paddleRight.getMaxSpeed());
break;
}
}
示例4: specialKeysUp
void specialKeysUp(int key, int x, int y) {
if (key == GLUT_KEY_UP || key == GLUT_KEY_DOWN)
paddleRight.setSpeed(0);
}