You could do it something like this.
Set up a structure containing the top left and bottom coords. of each line and box. Something like:
TYPE coordinates
topleftx as INTEGER
toplefty as INTEGER
bottomrightx as INTEGER
bottomrighty as INTEGER
Now, create an array for all those boxes and lines
DIM boxes(5) as coordinates
where the coordinates are the top left and bottom right coordinates of the box
DIM lines(3) as coordinates
where the coordinates are the end points of the lines.
If the player is currently in a box:
When the player moves, you now need to check that their intended new position (let's call it newx, newy) is legal. If it isn't, stop them moving in that direction.
So, for the box the player is current inside, see if newx is between the values topleftx and bottomrightx, AND newy is between the values toplefty and bottomrighty. If it is, the place the player wants to move to must be legal (ie. inside the box) and you can let them do it. If it is outside, don't allow them to move to the new coordinate.
The lines are slightly more complicated. The lines are like "rails" that the player moves along, and you want them to "stick" on to them. This involves knowing the equation for the line, which I think looks something like this:
y=mx+c

Stay with me.
To calculate m, the gradient of the line, you need to work out the distance between the two y coordinates - which is basically, m#=abs(bottomrighty-toplefty). (Make sure to set m to a floating point with the #.)
Now you know m, c can be calculated from rearranging the equation to: c=y-mx for either of the two coordinates, so c#=toplefty - (m*topleftx) (c needs to be floating point as well.)
Almost there.
If the player moved the joystick left/right, you need to make sure that the y-coordinate changes accordingly, so the player "sticks" to the line. You can do this by making newy = (m#*newx)+c#.
If they are moving their joystick up/down, you need to make x stick to the line: newx = (newy-c#)/m# (I think.)
I'm guessing there's probably an easier way, but I think that should work.
You would also need to have "junctions" betweens lines and boxes, so a player could move from one box to another, or from one box to a line. This isn't much harder than checking the player hasn't hit a coordinate where a line ends and meets a box. You'd probably have to check a "zone" rather than an individual pixel though; the chances of a player hitting a certain pixel on a 800x600 (or higher) screen is pretty slim.
Hope this wasn't too long winded. If any of this is wrong, feel free to abuse me, shoot me down in flames etc.