Esempio n. 1
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();
}
Esempio n. 2
0
//check collision between blocks and bottom edges
bool CheckCollision()
{
	bool Collision=false;
	for(unsigned int i=0; i< CurPiece->GetBlocks().size();i++ )
	{
		Block B1 = CurPiece->GetBlocks()[i];
		Collision |= (B1.GetY() >= (outlineRect.y+outlineRect.h));
		for(unsigned int j=0; j< blocks.size();j++ )
		{
			if(checkBlockCollision(B1,blocks[j]))
			{
				Collision = true;
				break;
			}
			if(Collision)
				break;
		}
	}
	return Collision;
}