User Tools

Site Tools


notes:cprog:fall2024:projects:fwg1

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:fall2024:projects:fwg1 [2024/10/24 03:40] – [bounds checking] mwinter4notes:cprog:fall2024:projects:fwg1 [2024/10/24 03:46] (current) – [bounds checking] mwinter4
Line 52: Line 52:
  
 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:  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: 
 +
 +<code>
 +void ourFunction(player* p){
 +    if(p->position_x > screen_width)
 +    {
 +        p->position_x -= screen_width;
 +    };
 +}
 +</code>
 +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>"position_x"</wrap> that is the X coordinate of the player as it is rendered on the screen. If we reach the <wrap hi>screen_width</wrap>, which would be the very right of the screen, then we render the player at the lowest x coordinate within our bounds, 0. 
notes/cprog/fall2024/projects/fwg1.1729741216.txt.gz · Last modified: 2024/10/24 03:40 by mwinter4