| Collision Detection |
|
spiff88
|
i believe lazy foo has a tutorial on this but from what i generally know is that, you use variables to check which keys are pressed such as bool keys(4) = {0,0,0,0}; array of 4 for each 4 direction then upon pressing/releasing whichever key you set the corresponding array value to either true or false then in your logic portion(which usually comes next from user interaction) is where you update all variable info and check for collisions
|
|||||||||||
|
|
||||||||||||
|
bala_48225
|
You need to keep the direction separate from the keys and then the collision is separate also. As time goes by you'll get better at breaking things down into these different parts, sort of 'abstracting' them from each other, because they are different things. I.e., your key presses affect the direction, which later causes a collision and change in direction as it bounces off or stops. Then when a key is pressed again, the logic has to decide if the sprite can indeed move in that direction because it may be stopped at the edge of a collision and trying to go that way.
|
|||||||||||
|
|
||||||||||||

