Object Movement

Hi all! I have a circle which always stays in the center and rotates so that it always faces the mouse cursor (the red line on the circle indicates the direction of the cursor). What I want to do is when I hold the Up arrow key I want the red walls to start moving towards the circle at the angle indicated by the red line on the circle and when I hold Down arrow key I want the walls to move to the opposite direction. Can you please give me some ideas on how this can be achieved. Here is a screenshot of my application:

http://img856.imageshack.us/img856/948/application.jpg

Just create a vector that is the direction of the red line. Normalize the vector.
If you want to move the red closer, just move it in the direction of the negated vector. Otherwise, use the vector as it is.

But how do I find the x,y coordinates of the red wall to move it to that direction? How much the the x,y needs to be increased/decreased while the button is pressed?

Read up on vector math and find some vector math library. It’s not very hard and once you grasped the idea, a lot of possibilities will open for you.

A 2D-vector consists of x and y components. You can calculate a direction vector by subtracting the x and y components of starting point from x and y components of the target and normalize it. You can then multiply your direction vector with some velocity and a time to get the position of a moving object at the desired time.

Again, read up on vector math! It’s important for games!!

Thank you. I will do some reading on vectors.

I typically have a scrollAmount vector, then I just draw everything offset by that. So when you move the player, you are both updating the player’s position (which is used for collisions, location data, etc.) and you are also updating the scroll amount in the opposite direction. In effect this makes the player look stationary and everything else look like it’s moving.

A key concept is to always think of what’s drawn (the viewport) as totally separate from actual entity positions and what’s being used for game logic.