本文整理汇总了C++中Paddle::getWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ Paddle::getWidth方法的具体用法?C++ Paddle::getWidth怎么用?C++ Paddle::getWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Paddle
的用法示例。
在下文中一共展示了Paddle::getWidth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: adjustPaddleAndBallCoordinates
void adjustPaddleAndBallCoordinates() {
paddleLeft.setCurrPos(clipAreaXLeft + 0.2f, 0);
paddleLeft.setYRestrictions(clipAreaYTop, clipAreaYBottom);
paddleRight.setCurrPos(clipAreaXRight - 0.2f - paddleRight.getWidth(), 0);
paddleRight.setYRestrictions(clipAreaYTop, clipAreaYBottom);
paddleLeft.setContactSurfaceX(paddleLeft.getCurrX() + paddleLeft.getWidth());
paddleRight.setContactSurfaceX(paddleRight.getCurrX());
ball.setYRestrictions(clipAreaYTop, clipAreaYBottom);
ball.setLoseBounds(paddleLeft.getCurrX(), paddleRight.getCurrX() + paddleRight.getWidth());
}
示例2: mouseMovementEvent
void Game::mouseMovementEvent(float aDeltaX, float aDeltaY, float aPositionX, float aPositionY)
{
// If the game isn't paused
if(!m_Pause)
{
//Set the paddle to the x position of the mouse
Paddle* paddle = (Paddle*)getGameObjectByType(GAME_PADDLE_TYPE);
//Safety check, paddle could be NULL
if(paddle != NULL)
{
paddle->setX(aPositionX - (paddle->getWidth() / 2.0f));
}
}
}
示例3: paint
void Game::paint()
{
// Show the title screen
if(m_ShowTitle)
{
OpenGLRenderer::getInstance()->drawTexture(m_Textures[21], 15.0f, 0.0f);
return;
}
// If the game is over
if(m_GameOver)
{
// Draw the game over texture
OpenGLRenderer::getInstance()->drawTexture(m_Textures[19], ScreenManager::getInstance()->getScreenWidth() / 2 - m_Textures[19]->getSourceWidth() / 2, ScreenManager::getInstance()->getScreenHeight() / 1.5);
return;
}
// Draw the texture for the game background
Paddle* paddle = (Paddle*)getGameObjectByType(GAME_PADDLE_TYPE);
if(paddle != NULL)
{
// Move the textures as the paddle moves
// Draw the background texture
OpenGLRenderer::getInstance()->drawTexture(m_Textures[0], (paddle->getX() / 8) - (m_Textures[0]->getTextureWidth() / 4), 0.0f);
// Only draw when player has lives
if(m_Lives > 0)
{
// draws the HP texture
OpenGLRenderer::getInstance()->drawTexture(m_Textures[10], paddle->getX() + paddle->getWidth() / 8, paddle->getY() + paddle->getHeight() * 1.55);
OpenGLRenderer::getInstance()->drawTexture(m_Textures[m_Lives], paddle->getX() + paddle->getWidth() / 3.5, paddle->getY() + paddle->getHeight() * 1.25);
}
// Only draw when within the maximum number of rounds
if(m_Round <= GAME_MAX_ROUNDS)
{
// draws the round texture
OpenGLRenderer::getInstance()->drawTexture(m_Textures[11], paddle->getX() + paddle->getWidth() / 1.5, paddle->getY() + paddle->getHeight() * 1.55);
OpenGLRenderer::getInstance()->drawTexture(m_Textures[m_Round + 1], paddle->getX() + paddle->getWidth() / 1.25, paddle->getY() + paddle->getHeight() * 1.25);
}
}
//Cycle through and draw all the game objects
for(int i = 0; i < m_GameObjects.size(); i++)
{
if(m_GameObjects.at(i)->getIsActive() == true)
{
// Painting bricks
if(m_GameObjects.at(i)->getType() == GAME_BRICK_TYPE)
{
// Paints a different texture for each round
m_GameObjects.at(i)->paint(m_Textures[12 + m_Round]);
}
// Painting balls
else if(m_GameObjects.at(i)->getType() == GAME_BALL_TYPE)
{
m_GameObjects.at(i)->paint(m_Textures[18]);
}
else
{
m_GameObjects.at(i)->paint();
}
}
}
//Draw the outer white walls
OpenGLRenderer::getInstance()->setForegroundColor(OpenGLColorWhite());
OpenGLRenderer::getInstance()->setLineWidth(4.0f);
OpenGLRenderer::getInstance()->drawLine(1.0f, 0.0f, 1.0f, getHeight());
OpenGLRenderer::getInstance()->drawLine(0.0f, 1.0f, getWidth(), 1.0f);
OpenGLRenderer::getInstance()->drawLine(getWidth() - 1, 0.0f, getWidth() - 1, getHeight());
OpenGLRenderer::getInstance()->setLineWidth(1.0f);
// If the game is paused
if(m_Pause)
{
// Draw the pause texture
OpenGLRenderer::getInstance()->drawTexture(m_Textures[9], ScreenManager::getInstance()->getScreenWidth() / 2 - m_Textures[9]->getSourceWidth() / 2, ScreenManager::getInstance()->getScreenHeight() / 1.5);
}
}
示例4: detectCollisions
void detectCollisions(Paddle& paddle) {
int startX = paddle.getBitmapX();
int startY = paddle.getBitmapY();
int paddleWidth = paddle.getWidth();
int paddleHeight = paddle.getHeight();
if (paddle.isHorizontal)
{
if (paddle.choosen) //down
{
if (x + moveX >= startX && y + moveY >= startY && x + moveX <= startX + paddleWidth) {
double position = paddle.getX();
double BALL_RADIUS = Ball::getWidth() / 2;
double radius = paddle.getWidth() / 2;
double velocity = sqrt((moveX*moveX) + (moveY*moveY));
double kx = ((position - getX()) / ((BALL_RADIUS + radius) / velocity));
double ky = sqrt((velocity * velocity) - (kx * kx));
moveX = -kx;
moveY = -fabs(ky);
}
}
else //up
{
if (x + moveX >= startX && y + moveY <= startY + paddleHeight && x + moveX <= startX + paddleWidth) {
double position = paddle.getX();
double BALL_RADIUS = Ball::getWidth() / 2;
double radius = paddle.getWidth() / 2;
double velocity = sqrt((moveX*moveX) + (moveY*moveY));
double kx = ((position - getX()) / ((BALL_RADIUS + radius) / velocity));
double ky = sqrt((velocity * velocity) - (kx * kx));
moveX = -kx;
moveY = fabs(ky);
}
}
}
else
{
startX = paddle.getX() - paddle.getHeight() /2;
startY = paddle.getY() - paddle.getWidth() /2;
int paddleWidthN = paddle.getHeight();
int paddleHeightN = paddle.getWidth();
if (paddle.choosen) // left
{
if (y + moveY >= startY && x + moveX <= startX + paddleWidthN && y + moveY <= startY + paddleHeightN) {
double position = paddle.getY();
double BALL_RADIUS = Ball::getWidth() / 2;
double radius = paddle.getWidth() / 2;
double velocity = sqrt((moveX*moveX) + (moveY*moveY));
double ky = ((position - getY()) / ((BALL_RADIUS + radius) / velocity));
double kx = sqrt((velocity * velocity) - (ky * ky));
moveX = fabs(kx);
moveY = -ky;
}
}
else // right
{
if (y + moveY >= startY && x + moveX >= startX && y + moveY <= startY + paddleHeightN) {
double position = paddle.getY();
double BALL_RADIUS = Ball::getWidth() / 2;
double radius = paddle.getWidth() / 2;
double velocity = sqrt((moveX*moveX) + (moveY*moveY));
double ky = ((position - getY()) / ((BALL_RADIUS + radius) / velocity));
double kx = sqrt((velocity * velocity) - (ky * ky));
moveX = -fabs(kx);
moveY = -ky;
}
}
}
}