当前位置: 首页>>代码示例>>C++>>正文


C++ Paddle::getWidth方法代码示例

本文整理汇总了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());
}
开发者ID:harman666666,项目名称:PONG,代码行数:10,代码来源:MAIN.cpp

示例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));
		}
	}
}
开发者ID:doug0102,项目名称:Assignment1,代码行数:15,代码来源:Game.cpp

示例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);
	}
}
开发者ID:doug0102,项目名称:Assignment1,代码行数:81,代码来源:Game.cpp

示例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;
				}
			}
		}
	}
开发者ID:Przemyslaww,项目名称:4rcanoid,代码行数:69,代码来源:Ball.hpp


注:本文中的Paddle::getWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。