Exemple #1
0
// update the game logic here
void updateGame() {
	updateBallPosition(ball);
	movePlayer(player1);
	if(ball.speed.x < 0)
		seek(player2, ball);
	
	if( testOnScreen(ball) ) {
		// ball hit side of screen
		if(ball.position.x < 50) {
			// player 1 lost
			player2Score++;
		}
		else {
			// player 2 lost
			player1Score++;
		}
	}

	if(g_gameOver == false) {
		if( abs(player1Score - player2Score) >= 3) {
			// Game Over
			g_gameOver = true;

			int highestScore = player1Score;
			if(player2Score > highestScore) {
				highestScore = player2Score;
			}

			for(int i=0; i<5; i++) {
				if(highestScore > g_highScores[i]) {
					g_highScores[i] = highestScore;
					break;
				}
			}

			// sort the high scores array
			sort(g_highScores, 5);
		}
	}

	if(ball.speed.x < 0) {
		if(checkPaddleCollision(ball, player1) == true)  {
			ball.speed.x *= -1;
		}
	}
	else {
		if(checkPaddleCollision(ball, player2) == true)  {
			ball.speed.x *= -1;
		}
	}


	RotateSprite(player1.sprite, 0);
	MoveSprite(player1.sprite, player1.position.x, player1.position.y);

	RotateSprite(player2.sprite, 0 );
	MoveSprite(player2.sprite, player2.position.x, player2.position.y);

	MoveSprite(ball.sprite, (int)ball.position.x, (int)ball.position.y);
}
Exemple #2
0
/* Game play loop */
void  loop(){
  
  if (continueGame){                                                      // If the game is still in play
    drawFrame();                                                          // Draw the frame
    drawScore();                                                          // Draw the score
    movePaddle();                                                         // Update the location of the paddle
    boolean paddleCollision = checkPaddleCollision();                     // Determine if the ball has hit the paddle or block
    boolean blockCollision = checkBlockCollision();
    if(score == numBlocks)                                                // If the score is equivalent to the number of blocks, game is over
      winner();                                                           // Display message to user
    else{                                                                 // The game is still in play
      if(paddleCollision || blockCollision)                               // Redraw screen to draw over any collisions
        drawFrame();
      delay(50);                                                          // Slight delay
      continueGame = updatePos();                                         // Update the position of the ball
    }
  }
  else                                                                    // The game is over, the ball fell off the screen. Display message to user.
    gameOver();
}
Exemple #3
0
//update the game logic here
void updateGame()
{
	if( g_bGameOver != true )
	{
	updateBallPosition(g_ball);
	}

	if( !g_bGameOver )
	{
		//player 1 on auto
		seek(g_player1, g_ball);
	
		//input for player 2
		movePlayer(g_player2);
	}

	if( testOnScreen(g_ball, SCREEN_X, SCREEN_Y) )
	{
		//ball hit side of screen
		if(g_ball.v2Position.fX < 100 )
		{
			//player 1 lost
			g_iPlayer2Score++;
		}
		else
		{
			//player 2 lost
			g_iPlayer1Score++;
		}
	}

	if( g_bGameOver == false )
	{
		if( abs(g_iPlayer1Score - g_iPlayer2Score) >= 3 )
		{
			//game over
			g_bGameOver = true;

			int iHighestScore = g_iPlayer1Score;
			if( g_iPlayer2Score > g_iPlayer1Score )
			{
				iHighestScore = g_iPlayer2Score;
			}

			for(int i = 0; i < 5; i++ )
			{
				if( iHighestScore > g_aiHighScores[i])
				{
					g_aiHighScores[i] = iHighestScore;
					break;
				}
			}

			//sort the scores array
			sort(g_aiHighScores, 5);
		}
	}

	if( g_ball.v2Speed.fX < 0 )
	{
		if(checkPaddleCollision(g_ball, g_player1) == true)
		{
			g_ball.v2Speed.fX *= -1;
		}
	}
	else
	{
		if( checkPaddleCollision(g_ball, g_player2) == true)
		{
			g_ball.v2Speed.fX *= -1;
		}
	}

	RotateSprite(g_player1.iSprite, 0);
	MoveSprite(g_player1.iSprite, g_player1.v2Position.fX, g_player1.v2Position.fY );

	RotateSprite(g_player2.iSprite, 0);
	MoveSprite(g_player2.iSprite, g_player2.v2Position.fX, g_player2.v2Position.fY);

	MoveSprite(g_ball.iSprite, (int)g_ball.v2Position.fX, (int)g_ball.v2Position.fY);
}