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:39] – [structures] tkastne1 | notes:cprog:fall2024:projects:fwg1 [2024/10/24 03:46] (current) – [bounds checking] mwinter4 | ||
---|---|---|---|
Line 49: | Line 49: | ||
=====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>" |