Basically, I'm trying to make a Metroid/Megaman X Camera Engine.

The camera should follow the player, but have boundaries to keep the camera from going "off track"

I made a video with annotations to show what I'm talking about:

http://www.youtube.com/watch?v=X_VzFRQ_dGY

The camera (a 256x224 square) is constantly trying to center over the player, but the orange boundary objects will push it in a direction to stay "on track". I've come close but I'm still having a few problems with it.

Here's the code:

http://i369.photobucket.com/albums/oo136/4Sweet2Leaf0/CamCode.jpg

So yeah. Not sure if I'm on the right track or not. Maybe I just need to add a few more objects? Or am I doing this entirely the wrong way? This is required for the game I'm working on now so I greatly appreciate any help!