B. Program Description for Developers

We assumed that the user would not try and break or hack in to the game. We also assumed that the user would not have any health issues with playing a game with a flashing screen (such as epilepsy), and we assumed that the user could turn the Proteus on.

Several important variables was x, y, j, k, which were each used in a function that required the user to touch the screen. These variables would be initialized at zero and then save the tap and release locations. For the x and y variables, the tap coordinates were saved here and then used to answer if and else if statements to see what the program should do next. The j and k variables were just thrown away after saving the release value.

Other important variables was the ‘score_quit variable’ which ended up being used in several scenarios to allow the user to back out of a screen or game. The variable ‘game’ was used to see if the entire program was running, and the variable ‘play’ was used in the actual game part of the program, and was used to end the program or continue running the while loop that it was a part of.

The variable touches was needed to set up the game, as the ball would not start bouncing around the screen until a side of the screen had been tapped, and this tap was counted using the touches function. The ‘highscore’ variable did not end up working very well – given more time, we could have ironed out these glitches but we were more focused on getting the bricks in our game to break when hit by the ball.

Several more variables were used, but these variables were not a part of the main() function and were instead initialized and used in the classes and functions called, and will be discussed in the next section.

Functions Used:

Block::Block()

  • Constructor for the block class
  • Initialized the positioned of the rectangle that would be drawn for the paddle

Ball::Ball()

  • Constructor for the ball class
  • Initialized the starting x and y position of the center of the ball, the radius, the x velocity, the y velocity, and the max and min distance the ball could travel in the x and y directions.
  • Drew the ball in its starting position
  • Set the time between redrawing the ball and set the initial score as 0.

Brick::Brick()

  • Constructor for the Brick class
  • Initialized the width, height, xstart, and ystart  properties of Brick to 0

void Brick::DrawBricks(int a[])

  • Function for class Brick
  • Set the Width property of Brick to 29
  • Set the Height property of Brick to 10
  • Used a for loop from 0 to 21 to create the x and y coordinates of each brick, then draw that brick
    • Used an if-else statement to create the top row of bricks starting with the first one having x and y coordinates of (0,34). Each brick thereafter in the first row was placed with the same x value, but one brick length to the right
    • The second row was created similarly, but with a value of 44 for each brick
    • The first brick of the second row needed its own else if statement due to QTcreator being unable to perform two relational operators at once. This prevented the use of p >= 11 in the third else if statement
  • The array Sphere.broken[] is passed in to use as part of the if statements, if the element of broken[] corresponding to that broken has not been changed to 1, it still gets drawn

void Block::BlockPlacement(float c, float d)

  • Uses conditional if statements to move the paddle object to the right or left depending on where on the Proteus the user taps with the stylus. If the user taps in a box with a ‘<‘, then the function will call the RedrawL() function. If the user taps in a box with a ‘>’, then the function will call the RedrawR() function.

void Block::RedrawL()

  • Clears the screen, then subtracts 20 from the x coordinate of the paddle called blockx. After doing this, it then redrew the paddle in the new position and redrew everything in the screen that was there previously.

void Block::RedrawR()

  • Clears the screen, then adds 20 from the x coordinate of the paddle called blockx. After doing this, it then redrew the paddle in the new position and redrew everything in the screen that was there previously.

void Ball::InitialTouch()

  • Waits for a touch to the screen. Depending on which half of the screen was touched, the x velocity will either be set to be positive or negative, and the y velocity will always be negative. These velocities will be used to tell the function how far it should redraw the new position of the ball after each wait_time variable has passed.

int Ball::RedrawBall(float a, float b, int c, int d, int *e)

  • Uses a for loop from 0 to 21 to check if the ball has hit a brick every time the ball moves. By using a for loop a general if statement can check the coordinates and broken counter of each brick by performing calculations based on the value of the iterator instead of writing out the coordinates of the bottom of every brick in an if statement.
    • For the bottoms of the bricks, it checks if the y coordinate of the ball is within a radius length of the y coordinate of the bottom of the brick, the x coordinate of the ball is within the frame of the brick, the ball is moving upwards, and the broken counter for that brick has not been changed to 1 yet
    • An if statement and two else if statements are used to check if the brick is in the top row, bottom row, or the bottom left brick, then checks the previously stated conditions
    • If all four of these conditions are true, the y velocity of the ball is flipped, the score is increased by 1, and the counter for that brick is changed to 1 to indicate it cannot be hit again
  • After all of these parts were complete, the Proteus would sleep for whatever the wait_time variable was at that moment.

Our program performed at a reasonable level; due to the limitations of the Proteus, redrawing the whole screen every time an object needed to move was frustrating and considerably slowed down the program. We did eventually implement bricks, which was one of our additional features, however the bricks could not be bounced against their side. Additionally, due to how the position of each brick was checked, it was possible for the ball to glitch through some bricks to hit bricks that should be impossible to hit. Finally, as two functions can not be running at the same time on the Proteus, if the user were to hold down the stylus on the screen, the game would freeze until the user let go. Finally, it was possible for the paddle to continue on forever in each direction (an oversight on our part), and even though it would show up on the screen again, it would not interact with the ball. We are incredibly proud that we could create make the bricks and program work at all however. If the user does not try and break the game, and plays the way we wished, then the game is an accurate representation of the real brick breaker game. We wish we had more time; we could have made something even more special.