2D Topdown Shooter Mouse Movement

Posted by Jarmo on Game Development See other posts from Game Development or by Jarmo
Published on 2011-11-22T10:42:39Z Indexed on 2011/11/22 18:17 UTC
Read the original article Hit count: 228

Filed under:
|
|

I'm trying to make a topdown 2D space game for my school project. I'm almost done but I just want to add a few little things to make the game more fun to play.

if (keystate.IsKeyDown(Keys.W))
        {
            vPlayerPos += Vector2.Normalize(new Vector2(Mouse.GetState().X - vPlayerPos.X, Mouse.GetState().Y - vPlayerPos.Y)) * 3;

            rPlayer.X = (int)vPlayerPos.X;
            rPlayer.Y = (int)vPlayerPos.Y;
        }

        if (keystate.IsKeyDown(Keys.S))
        {
            vPlayerPos += Vector2.Normalize(new Vector2(Mouse.GetState().X - vPlayerPos.X, Mouse.GetState().Y - vPlayerPos.Y)) * -3;
            rPlayer.X = (int)vPlayerPos.X;
            rPlayer.Y = (int)vPlayerPos.Y;
        }

This is what i use to move towards and away from my mouse crossair. I tried to make a somewhat similar function to make it strafe with "A" and "D". But for some reason I just couldn't get it done.

Any thoughts?

© Game Development or respective owner

Related posts about XNA

Related posts about movement