This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
notes:cprog:spring2025:projects:mtb4 [2025/03/10 15:12] – created - external edit 127.0.0.1 | notes:cprog:spring2025:projects:mtb4 [2025/03/13 03:45] (current) – [power ups] bdildine | ||
---|---|---|---|
Line 15: | Line 15: | ||
=====power ups===== | =====power ups===== | ||
+ | It might be a good idea to implement structs to represent powerups. Within this struct, it would have an x and y value (this could be a struct in and of itself called point, which has two ints: x and y). The struct could also have a variable called type that represents what type of powerup it is, e.g., type = 1 for damage, and type = 2 for duplicating that ball. One easy way to represent all the possible powerups as integer values is through the use of enums (enumerations). | ||
- | ====logic to implement==== | + | struct Powerup |
+ | { | ||
+ | Point position; | ||
+ | int type; | ||
+ | } | ||
+ | struct Point | ||
+ | { | ||
+ | int x, | ||
+ | int y | ||
+ | }; | ||
+ | |||
+ | What is an enumerator? | ||
+ | Microsoft definition: An enumeration type (or enum type) is a value type defined by a set of named constants of the underlying integral numeric type. | ||
+ | this means that you can define named constants that have an underlying numeric value. | ||
+ | |||
+ | Example: | ||
+ | enum Teachers | ||
+ | { | ||
+ | MATT = 1, | ||
+ | JOE = 2 | ||
+ | }; | ||
+ | |||
+ | 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: | ||
+ | |||
+ | enum POWERUPS | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | }; | ||
+ | |||
+ | then make a struct: | ||
+ | |||
+ | struct Powerup | ||
+ | { | ||
+ | Point position; | ||
+ | | ||
+ | } | ||
+ | |||
+ | then create a struct with the desired powerup and position: | ||
+ | < | ||
+ | void main() | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | </ | ||
+ | now everytime that you call ptrPowerup-> | ||
+ | |||
+ | 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: | ||
+ | < | ||
+ | if ( PowerUpCollected[1] == true ) | ||
+ | { | ||
+ | select_region( RegionLargePaddle ); | ||
+ | } else { | ||
+ | select_region( RegionPaddle ); | ||
+ | } | ||
+ | draw_region_at( PaddleX, PaddleY ); | ||
+ | </ |