User Tools

Site Tools


notes:cprog:spring2025:projects:mtb4

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:mtb4 [2025/03/12 20:24] – [logic to implement] tstricklnotes:cprog:spring2025:projects:mtb4 [2025/03/13 03:45] (current) – [power ups] bdildine
Line 40: Line 40:
 }; };
  
-instead of literally typing 1, you could just write MATT, and it would automatically be replaced by the value 1.+instead of literally typing 1, you could just write MATT, and it would represent the value 1, but the type is enum, not int.
  
-Back to the context of powerups you could make an enum as such:+Back to the context of powerupsyou could make an enum as such:
  
 enum POWERUPS enum POWERUPS
 { {
- Duplicate = 1, + DUPLICATE = 1, 
- MoarDamage = 2, + MOARDAMAGE = 2, 
- Faster = 3+ FASTER = 3
 }; };
  
Line 56: Line 56:
 { {
  Point position;  Point position;
- int type;+ POWERUPS type;
 } }
  
-then define a struct with the desired powerup and position: +then create a struct with the desired powerup and position: 
 +<code>
 void main() void main()
 { {
- Powerup *ptrPowerup; + Powerup *ptrPowerup;                          //create a pointer to a powerup 
- ptrPowerup->position.x = screen_width / 2;+ ptrPowerup->position.x = screen_width / 2;    //set x and y values of the point struct within the powerup
  ptrPowerup->position.y = screen_height / 2;  ptrPowerup->position.y = screen_height / 2;
- ptrPowerup->type = DUPLICATE;+ ptrPowerup->type = DUPLICATE;                   //set the type variable within the powerup struct to DUPLICATE, which represent the underlying value of 1
 } }
 +</code>
 +now everytime that you call ptrPowerup->type it will return DUPLICATE, which under the hood, represents 1.
  
-after providing values, now everytime that you call ptrPowerup->type it will return 1, because DUPLICATE is defined as such. +Some Power-Ups you could make could range from trivial to more difficult. One could be a Power-Up that increases the size of your paddle. 
 +You can accomplish this by checking if the Power-Up is active, then selecting a different region before drawing the paddle and the given coordinates. 
 +You will of course need to change the boundaries in which the ball collides with the bigger paddle as well. 
 +If you are using an array to track your Power-Ups, it would look something like: 
 +<code> 
 +if ( PowerUpCollected[1] == true ) 
 +
 +    select_region( RegionLargePaddle ); 
 +} else { 
 +    select_region( RegionPaddle ); 
 +
 +draw_region_at( PaddleXPaddleY ); 
 +</code>
notes/cprog/spring2025/projects/mtb4.1741811049.txt.gz · Last modified: 2025/03/12 20:24 by tstrickl