コード例 #1
0
ファイル: MAIN.cpp プロジェクト: harman666666/PONG
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
0
ファイル: Game.cpp プロジェクト: doug0102/Assignment1
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
0
void Ball::onPaddleHit(Paddle& paddle)
{
	float x = getX() + getWidth() / 2 - paddle.getX();
	float range = 180 - PADDLE_ANGLE * 2;
	float degrees = (range * x / paddle.getWidth()) + PADDLE_ANGLE;

	m_angle = math::PI - math::to_radians(degrees); // Angles are inverted, flip Y
	SoundSystem::playSound("ball.ogg", 0.4f);

	if (paddle.isSticky())
	{
		m_glued_to = &paddle;
		m_glued_at = paddle.getX() - getX();
	}
	else
	{
		Effect::zoomAndRevert(*this, 1.8, 0.1);
	}
}
コード例 #4
0
ファイル: Game.cpp プロジェクト: doug0102/Assignment1
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);
	}
}
コード例 #5
0
ファイル: Ball.hpp プロジェクト: Przemyslaww/4rcanoid
	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;
				}
			}
		}
	}