I made a post earlier related to this project I'm working on, but the information I received wasn't enough, so I'm just putting this all out there on the plate. The project I'm working on is a game very similar to the one at http://cursors.io. The player controls an in-game cursor, which follows the mouse. However, the cursor can't move beyond objects such as walls and blocks.

the third approach, with the cursor getting stuck on an intersection
Terminology:
Cursor - The ingame object
Mouse - The player's actual cursor
I tried several approaches to this.
Approach 1
I tried moving the cursor on top of the player's mouse every frame, and if it was inside the shape object of a collideable, it wouldn't move that frame. However, this caused problems for if the user paused the game, moved the mouse to another location on the screen, and unpaused. Or, even if the user moved the mouse fast enough to travel across the distance of an object within a single frame, they'd be able to 'glitch' through it.
Approach 2
The next approach I tried was moving the cursor a set amount of pixels every frame in the direction of the player's mouse, applying the same checking method as approach 1. This resulted in jerky, slow movements, with the worry that if the set pixel movement was too high it would still jump over very thin obstacles.
Approach 3
The final approach I tried was by using line segment intersections. I would define a main line from the cursor to the mouse, then the boundary lines of every collideable object. When the mouse moved, I would check to see if the main line segment intersected with any boundary lines, and if so record it. After all boundary lines were checked, the closest intersection would be the one kept. I would move the cursor to that intersection point and call it done. If no intersections happened, I would just move the cursor to the mouse. The problem with this though is that once the cursor was moved to an intersection point, it was stuck. The intersection point stayed at the new location of the cursor, since it was still right on top of the boundary line. As well, I couldn't think of a way to get the cursor to slide around on the boundary line, following the mouse's x or y movements while not passing through.
Some example code:
# ============
# Approach 1
# ============
# Game loop {
if not any([i.contains(mousepos) for i in collideables]):
cursorpos = mousepos
# }
# ============
# Approach 2
# ============
speed = 5
# Game loop {
dx = copysign(1, mousepos[0]-cursorpos[0])
dy = copysign(1, mousepos[1]-cursorpos[1])
destx = dx*speed
desty = dy*speed
if not any([i.contains([destx, desty]) for i in collideables]):
cursorpos = [destx, desty]
# }
# ============
# Approach 3
# ============
def lineIntersection(line1, line2):
# intersection code to determine x and y of intersection, as well
# as the distance across line1 to the intersection
if intersection:
return [x, y, distance]
return None
# Game loop {
closestIntersect = None
for collideable in collideables:
for boundaryline in collideable:
intersect = lineIntersection(mainline, boundaryline)
if intersect:
if not closestIntersect or intersect[2] < closestIntersect[2]:
closestIntersect = intersect
if closestIntersect:
cursorpos = intersect[0], intersect[1]
# }