Board Thread:Questions and Answers/@comment-24386245-20140810124810/@comment-5483792-20140812231004

Alright. So, there are two ways of doing this.

Either you check for colisions first and move after, or you move before and then check for collision.

In the first case, you will need subroutines to move exactly one pixel in every direction. In these subroutines you will check ahead to make sure that there is nothing where you intend to go before commiting to the movement. Then, using the speed variable, you call the subroutine a couple of times to match the movement offset by the speed. You can also use the difference between the speed and the actual position if you are going to use decimals in your movement. This will make it more precise.

In the second case, you move a step ahead and then revert back to a safe position if a collision is detected. This method does not require subroutines for moving in each direction, though the for loop might contain a bit more code. Again, the speed variable will tell you how many steps to take, and you can take the difference between position and speed for greater decimal acuracy.

Both techniques are valid and have their tradeoffs. You can choose between either one you want.