I read the first few pages of that tutorial, and from what I read the collision detection system seems more complicated than it has to be.
Here's some sliding 2d collision code I wrote but have yet to use.
`Sliding 2d Collision
`
box 0, 0, 65, 65
get image 1, 0, 0, 65, 65
sprite 1, 100, 100, 1
sprite 2, 0, 0, 1
sprite 3, 300, 300, 1
do
inc x, rightkey() - leftkey()
inc y, downkey() - upkey()
sprite 2, x, y, 1
if sprite collision(2, 1) then sliding_2d_collision(1, 2)
if sprite collision(2, 3) then sliding_2d_collision(2, 3)
x = sprite x(2)
y = sprite y(2)
loop
function sliding_2d_collision(moveable as integer, solid as integer)
`the heights, widths and coordinates of the sprites are recorded ahead of time for optiminization
`the moveable_center variables are the coordinates of the center of the sprite, not the corner
`mx is used in the algebra that calculates how to resolve the collision
local solid_x as integer
local solid_y as integer
local solid_width as integer
local solid_height as integer
local moveable_x as integer
local moveable_y as integer
local moveable_width as integer
local moveable_height as integer
local moveable_x_center as integer
local moveable_y_center as integer
local mx as integer
solid_x = sprite x(solid)
solid_y = sprite y(solid)
solid_width = sprite width(solid)
solid_height = sprite height(solid)
moveable_x = sprite x(moveable)
moveable_y = sprite y(moveable)
moveable_width = sprite width(moveable)
moveable_height = sprite height(moveable)
rem moveable center is relative to the soild coordinates
moveable_x_center =(moveable_x + moveable_width / 2) - solid_x
moveable_y_center = (moveable_y + moveable_height / 2) - solid_y
rem this is part of the algebraic equations, (solid_height / solid_width) is m, the slope, and moveable_x_center is the x
mx = (solid_height / solid_width) * moveable_x_center
rem the algebra creates two imaginary lines through the soild sprite, this divides the sprite into four parts.
rem Two inequalities, y > -mx + b (b is the height of the solid sprite) and y > mx are the equations for these two lines
rem it detects which quadrant the center is in by creating a linear inequality. The equations of the two lines are calculated,
rem and the x and y coordinates of the moveable sprite are plugged in to test if the sprite is below or above the line
rem Then for example, if the center of the moveable sprite is in the lower quadrant, the sprite will be pushed downward to resolve the collision
if moveable_y_center > -mx + solid_height
rem sprite is in lower right half
if moveable_y_center > mx
rem sprite is in lower quarter
rem the correct new y position for the sprite is simply the bottom of the solid sprite, sprite y + sprite height
sprite moveable, moveable_x, solid_y + solid_height, sprite image(moveable)
else
rem sprite is in right quarter
rem the correct new x position for the sprite is simply the right of the solid sprite, sprite x + sprite width
sprite moveable, solid_x + solid_width, moveable_y, sprite image(moveable)
endif
else
rem sprite is in upper left half
if moveable_y_center > mx
rem sprite is in left quarter
rem the correct new x position is just enough away from the x position of the solid sprite
rem if we subtract the width of the moveable sprite from the coordinate, the other side will barely touch, resloving the collision
sprite moveable, solid_x - moveable_width, moveable_y, sprite image(moveable)
else
rem sprite is in upper quarter
rem the correct new y position is just enough away from the y position of the solid sprite
rem if we subtract the height of the moveable sprite from the coordinate, the other side will barely touch, resloving the collision
sprite moveable, moveable_x, solid_y - moveable_height, sprite image(moveable)
endif
endif
endfunction
Use the arrowkeys to control one of the boxes. The only bug I found is that it doesn't calculate collision if you use your sprite to push another sprite into a third, like Mario would push a box into a wall.