I have these two methods to determine collisions on the x-axis and y-axis:
def horizontal_overlap(char, object)
char.x + char.width > object.x &&
char.x < object.x + object.width #Endl
end
def vertical_overlap(char, object)
object.y + object.height > char.y &&
object.y < char.y + char.height #Endl
end
In my code, there is one moving rectangle and several other (fixed) rectangles. I want to detect if the moving rectangle touches one of the other rectangles. In addition, I want to determine if it touches it horizontally or vertically.
How do I approach this?