User Tools

Site Tools


notes:comporg:fall2023:projects:magx

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:comporg:fall2023:projects:magx [2023/11/15 17:55] – [Player Physics and Animations] walleynotes:comporg:fall2023:projects:magx [2023/11/15 18:07] (current) – [Player Physics and Animations] walley
Line 42: Line 42:
 Every good runner needs to have obstacles to avoid! For this runner, we'll have two building blocks: A block and a spike. Every good runner needs to have obstacles to avoid! For this runner, we'll have two building blocks: A block and a spike.
  
 +Our obstacles will be controlled by an integer flag. A zero means no obstacle is spawned, and any number higher corresponds with an obstacle pattern. This flag can be triggered by the console clock, RNG, or whatever.
 +
 +When an obstacle is spawned (the flag is turned from 0 to a number), A variable we'll call "Obstacle X" is set to be a little over 640. The Obstacle X variable is a reference position in which each building block of the obstacle pattern will be positioned relative to. We only need to set the X as the Y will remain constant at ground level. Obstacle X will move left at the same rate as the background layer until it reaches at least -640. At this point, the Obstacle flag will be set to zero again, and a new pattern can be spawned.
 +
 +Each obstacle pattern will essentially be an array/list for each building element. Each element will have three variables:
 +  - Object type ( 0=Block, 1=Spike )
 +  - Position X
 +  - Position Y
 +Again, the Position data will be updated relative to the Obstacle X reference point. Additionally, a size variable will be kept in the stack so that we know how many elements reside within each obstacle pattern.
 +
 +===Obstacle Collision and Rendering===
 +The processes for both collision checks and rendering are relatively the same. First, we check the Obstacle flag to see which pattern is currently spawned, and then grab the size variable associated with it. Secondly, we use that size variable to for-loop through each element in the obstacle to then either run collision checks on it, or render it.
 +
 +For Collision, we check if the element is either a Block or a Spike using the Object Type variable. If it's a block, we run checks to see if the Player is on top of it, so that the Player can run and jump along it, or if the Player is in it to trigger a game over. For Spikes, there are two boxes inside it that if the player enters 
 +also triggers a game over.
 +
 +For Rendering, the Object Type check is the same to select the right texture region, which gets printed at that position. Relatively simple.
  
notes/comporg/fall2023/projects/magx.1700070956.txt.gz · Last modified: 2023/11/15 17:55 by walley