Exemplo n.º 1
0
// sets old coordinates, checks for collisions, then sets new
// coordinates based on collision data
void updateBallPos()
{
    // first get paddle position
    int paddlePos = getPaddlePosition();
    
    if(onPaddle)
    {
        oldball.x = ball.x;
        oldball.y = ball.y;
        
        ball.x = paddlePos + (PADDLE_WIDTH / 2);
    }
    else
    {
        oldball.x = ball.x;
        oldball.y = ball.y;
        
        checkBallCollisions(paddlePos);
        
        ball.x += xdir*speed;
        ball.y += ydir*speed;
    }
    
    drawBall();
}
Exemplo n.º 2
0
void MainState::update(Game* game)
{
	mPlayer1Sprite.update();
	mPlayer2Sprite.update();
	mBallSprite.update();

	checkPaddleScreenCollision(&mPlayer1Sprite);
	checkPaddleScreenCollision(&mPlayer2Sprite);

	checkBallCollisions(game);
}