Moving my sprite in XNA using classes

Posted by Tom on Game Development See other posts from Game Development or by Tom
Published on 2011-02-03T16:43:41Z Indexed on 2011/02/03 23:35 UTC
Read the original article Hit count: 360

Filed under:

Hey, im a newbie at this programming lark and its really frustrating me. I'm trying to move a snake in all directions while using classes. Ive created a vector2 for speed and ive attempted creating a method which moves the snake within the snake class.

Now I'm confused and not sure what to do next.

Appreciate any help. Thanks :D

This is what i've done in terms of the method...

  public Vector2 direction()
        {
                Vector2 inputDirection = Vector2.Zero;

                if (Keyboard.GetState().IsKeyDown(Keys.Left)) inputDirection.X -= -1;
                if (Keyboard.GetState().IsKeyDown(Keys.Right)) inputDirection.X += 1;
                if (Keyboard.GetState().IsKeyDown(Keys.Up)) inputDirection.Y -= -1;
                if (Keyboard.GetState().IsKeyDown(Keys.Down)) inputDirection.Y += 1;

                return inputDirection * snakeSpeed;

        }

Appreciate any help. Thanks :D

EDIT:
Well let me make everything clear. Im making a small basic game for an assignment. The game is similar to the old snake game on the old Nokia phones. I've created a snake class (even though I'm not sure whether this is needed because im only going to be having one moving sprite within the game). After I written the code above (in the snake class), the game ran with no errors but I couldn't actually move the image :(

EDIT2: Thanks so much for everyones responses!!

© Game Development or respective owner

Related posts about XNA