Google+

Monday, August 8, 2011

Let's Make A Game! Episode 4: Rumble In The Jumble (Of Code)

So we continue onward with our exploration into programming C# with XNA. I want to draw our attention to a couple of different loops that I forgot to mention last time around.

First, we have Initialize. Think of this one as putting everything in order to begin the game. In this loop, we're going to set all of our starting points: How much health your guy has, how fast he's going, and all that other fun stuff.

In the next loop, we have Update. In this loop, we determine if anything has changed. For example, did the player press a button? How far did a bullet travel? Is an enemy moving across the screen? How far did he move? This step is pure math.

Next, the fun loop: Draw. This is where all of the changes that we've figured out in the Update loop get written on the screen. After this loop, we drop back to Update.

That's the crux of most games. It's setting the table, seeing what's different, and then displaying the difference to the player.

Going back to our program, they want us to enter in these lines of code:
// Load the player resources
Vector2 playerPosition = new Vector2(GraphicsDevice.Viewport.TitleSafeArea.X,GraphicsDevice.Viewport.TitleSafeArea.Y +GraphicsDevice.Viewport.TitleSafeArea.Height / 2);
player.Initialize(Content.Load("player"), playerPosition);
What does this all mean? I dunno. I kind of wish I did. I mean, I added it, and I got the result they were looking for. Anyone out there have a good explanation as to what this all means?

In the meantime, here's what we've got after finishing the lesson:
MY GOD IT'S FULL OF STARS

So not entirely impressive yet, but these things take time. In the next lessons, we'll be learning about input, so it should be much more exciting.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.