• Lucid Dreaming - Dream Views




    Results 1 to 8 of 8
    1. #1
      A Natural The Invisible Man's Avatar
      Join Date
      Nov 2008
      Gender
      Posts
      365
      Likes
      8

      Tell me about XNA and help me make a game!

      Actually I'm quite a beginner with XNA, but I'm a decent C# programmer. I have experience using Visual Studio. This is for my high-school programming class, but the teacher gave us two days to actually develop this game. It's due on Thursday.

      I just got an XNA book. However, there are quite a few things it fails to explain to my satisfaction.

      Here's my objective: Create a Windows game using XNA where two players shoot back and forth with tanks. This is meant to demonstrate trajectories.
      ================================================== =======
      Game Requirements:
      ~ There will be an obstacle to shoot around.
      ~ Players can select the power and angle to shoot at. (Text input probably)
      ~ Turn-based
      ~ Probably best to use a mouse and two textboxes to set the power and angle. I'm using one set of controls for both players.
      ~ Random wind to change the trajectories, only two directions (left/right).
      ~ If the shell goes out of the screen or hits the obstacle, it detonates harmlessly.
      ~ Saving wins and losses between player one and player two.
      ================================================== =======
      What I need:
      ~ I know I'll just create a few classes like a tank class, an artillery shell class, and probably something for the obstacle in the center.
      ~ I need to figure out the Vector2, Velocity, and Position classes, as well as any other class I might need. Also I need to know how to use the update method in relation to key inputs and positions for objects.
      ================================================== =======
      What I have:
      ~ Artwork, like a tank gif and shell gif.
      ================================================== =======
      That's it. Nothing too complicated, I can add multiplayer capability for fun when I don't have finals riding my ass.

      Responses are appreciated, just giving me links are not as helpful to me since this is supposed to be a learning experience for me.

      .cs files are semi-appreciated too.


      Can you see me now?

    2. #2
      Member Achievements:
      1 year registered 1000 Hall Points Veteran First Class
      SomeDreamer's Avatar
      Join Date
      Jul 2007
      Gender
      Location
      Denmark
      Posts
      670
      Likes
      44
      I need to figure out the Vector2, Velocity, and Position classes, as well as any other class I might need. Also I need to know how to use the update method in relation to key inputs and positions for objects
      hehe, it'll be a lot easier to help if you got more specific questions regarding those areas as you move along with the game

      If you're a decent C# programmer then trust me, XNA will be an easy and good choice.

    3. #3
      A Natural The Invisible Man's Avatar
      Join Date
      Nov 2008
      Gender
      Posts
      365
      Likes
      8
      Well, start by telling me just what the hell a Vector2 is. I know what velocity and position is (I'm in Physics) but I don't start with vector calculus until next term.


      Can you see me now?

    4. #4
      Member Achievements:
      1 year registered 1000 Hall Points Veteran First Class
      SomeDreamer's Avatar
      Join Date
      Jul 2007
      Gender
      Location
      Denmark
      Posts
      670
      Likes
      44
      Well, in XNA both 3D and 2D space revolves around the use of vectors to control position and velocity of game objects... and so much more, but just to start off with the basics here.

      When you work with 2D in XNA, think of the game window as a coordinate system starting in the top left corner of the window, like this:



      Both arrows representing the left and top side of the window. Say you want to position a sprite somewhere on the screen, you'd make a Vector2 class describing the position the image should use, like this:

      Vector2 imagePos = new Vector2(30, 30);

      When applying that vector to the image position, starting from point zero in the coordinate system (top left corner) you'd have a point 30 units out on the x axis and 30 units down on the y axis where your image would be positioned. You apply these vectors to your images in the draw method. When making movements to your sprite you simply take your sprites position and apply additional changes to it. Like if you press the down arrow on the keyboard, you could keep adding 5 units to the sprites position vector to make it move downards.

      Vector2 is simply the 2D vector class in XNA. You also have a vector3 etc.

      [EDIT]

      Here's a small code snippet from one of my projects showing simple player control using timerbased movement (which you really should use!)
      elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

      keyboardState = Keyboard.GetState();

      //Player movement
      if (keyboardState.IsKeyDown(Keys.D))
      {
      position.X += 250.0f * elapsedTime;
      }

      if (keyboardState.IsKeyDown(Keys.A))
      {
      position.X -= 250.0f * elapsedTime;
      }

      playerCollision = new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);

      lastKeyboardState = Keyboard.GetState();
      Last edited by SomeDreamer; 03-11-2010 at 09:19 AM.

    5. #5
      A Natural The Invisible Man's Avatar
      Join Date
      Nov 2008
      Gender
      Posts
      365
      Likes
      8
      Okay, I understand that. I used that cooridnate system with GameMaker and UI Designing. Vector2 is essentialy a point, which I can control because I can use it's mutators for the X and Y values. I assume that code snippet would go in the Update method in the main game loop?


      Can you see me now?

    6. #6
      Member Achievements:
      1 year registered 1000 Hall Points Veteran First Class
      SomeDreamer's Avatar
      Join Date
      Jul 2007
      Gender
      Location
      Denmark
      Posts
      670
      Likes
      44
      Vector2 is essentialy a point, which I can control because I can use it's mutators for the X and Y values
      Correct. You can do it other ways too obviously, like adding or substracting vectors etc. It's more than a point though, it also describes lengths and direction.

      http://en.wikipedia.org/wiki/Euclidean_vector

      I assume that code snippet would go in the Update method in the main game loop?
      Yeah it would. In the case of that snippet it comes from a player class with its own update method, which gets called from the main update loop.

    7. #7
      A Natural The Invisible Man's Avatar
      Join Date
      Nov 2008
      Gender
      Posts
      365
      Likes
      8
      Ah. So essentially, I have a Draw() method in the main game loop that calls all of the Draw() methods of the objects in game? Likewise for the Update() method? How do I handle when there isn't an instance to draw or update? Try/Catch NullReference?


      Can you see me now?

    8. #8
      Member Achievements:
      1 year registered 1000 Hall Points Veteran First Class
      SomeDreamer's Avatar
      Join Date
      Jul 2007
      Gender
      Location
      Denmark
      Posts
      670
      Likes
      44
      So essentially, I have a Draw() method in the main game loop that calls all of the Draw() methods of the objects in game?
      Yes, the draw method is where you make all the drawings to your GPU, and the Update method is your main game loop.

      How do I handle when there isn't an instance to draw or update?
      Well if you mean running through an array of objects and only draw the active ones, you can simply make an Active property in the object class and only set it to true when you spawn them, and inactive when you despawn/kill them. Then simply have an if statement that checks for that bool before drawing/updating. If that's what you mean.

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •