This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:cprog:fall2024:projects:fwg1 [2024/10/23 13:08] – [gamepad] tkastne1 | notes:cprog:fall2024:projects:fwg1 [2024/10/24 03:46] (current) – [bounds checking] mwinter4 | ||
---|---|---|---|
Line 18: | Line 18: | ||
* B/A Buttons: ' | * B/A Buttons: ' | ||
To use player inputs you need to include [[https:// | To use player inputs you need to include [[https:// | ||
+ | |||
+ | gamepad_direction provides a simple way to read and store player D-Pad inputs | ||
+ | |||
+ | < | ||
+ | // | ||
+ | int xDirection; | ||
+ | int yDirection; | ||
+ | |||
+ | //The addressof operator is used because the gamepad_direction methods changes the value of its inputs | ||
+ | gamepad_direction(& | ||
+ | </ | ||
=====structures===== | =====structures===== | ||
+ | The Vircon32 c compiler uses different syntax to gcc, and has more limitations placed on structures. For more information see the [[https:// | ||
+ | < | ||
+ | //declare structure | ||
+ | struct exampleStructure | ||
+ | { | ||
+ | int myVariable; | ||
+ | int myValue; | ||
+ | }; | ||
+ | |||
+ | //declare a variable of type exampleStructure | ||
+ | exampleStrucutre somethingUseful; | ||
+ | |||
+ | //assign values to each property of variable | ||
+ | somethingUseful.myVariable = -30; | ||
+ | somethingUseful.myValue = 99; | ||
+ | </ | ||
=====bounds checking===== | =====bounds checking===== | ||
+ | Bounds checking is the process of checking to make sure a variable remains bounded by some defined limit. In our case, and as is the case for many games, we want to check to see if the character is going to coordinates off-screen so that we can regain the player' | ||
+ | |||
+ | To bound check, we can simply view the coordinates of our main player character to determine if they are at coordinates that rest outside of the screen height and width. Here is an example of how one might horizontally check bounds and wrap the player around to the opposite side: | ||
+ | |||
+ | < | ||
+ | void ourFunction(player* p){ | ||
+ | if(p-> | ||
+ | { | ||
+ | p-> | ||
+ | }; | ||
+ | } | ||
+ | </ | ||
+ | This assumes that we've passed in a pointer to our player structure that we will call p for this function. | ||
+ | |||
+ | There is also the assumption that there is a member variable of this structure called <wrap hi>" |