User Tools

Site Tools


notes:cprog:spring2025:projects:mtb3

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:cprog:spring2025:projects:mtb3 [2025/03/05 04:11] – [pointers] tstricklnotes:cprog:spring2025:projects:mtb3 [2025/03/05 18:48] (current) – [array of bricks] bdildine
Line 17: Line 17:
 Game where you have a set of bricks that are breakable by the ball. You also have a paddle to bounce the ball towards the bricks. If the ball falls under the paddle, end game or lose lives. Game where you have a set of bricks that are breakable by the ball. You also have a paddle to bounce the ball towards the bricks. If the ball falls under the paddle, end game or lose lives.
 ====brick field==== ====brick field====
 +You can save yourself a lot of time and effort by using a for loop for the brick field. This way you can check for bounds and draw each box and then loop, rather than write the same code with a few numbers changed for as many times as you have boxes. The basic structure of a for loop in C is as follows:
 +<code>
 +for ( int counter = 0; counter < 10; counter++ ) 
 +{
 +//code
 +}
 +</code>
 +This tell the loop to initialize a counter variable as 0 in this case. It will check if the counter is less than 10 and continue with the code. The counter++ tells the loop to add one to the counter variable every time it loops, so eventually, counter will be 10 and the loop will stop.
  
 ====brick structure==== ====brick structure====
  
 ====array of bricks==== ====array of bricks====
 +You can use an array of boolean values to check if the box has had a collision or not. This would look something like:
 +<code>
 +bool[#ofboxes] Boxes;
 +</code>
 +You can make use of for loops to initialize every value in the array to true or false.
 +Then when drawing the boxes, use a for loop and only draw each box if the corresponding value in the boolean array is true or not
 +( This would assume when the ball collides with the box you set that boxes boolean value to false )
  
 ====brick ball collision detection==== ====brick ball collision detection====
notes/cprog/spring2025/projects/mtb3.1741147915.txt.gz · Last modified: 2025/03/05 04:11 by tstrickl