Friday, August 5, 2011

Let's Make A Game! Episode 3

I was going to try and explain what I know about programming, but it's complicated stuff. Anything I spit out here would sound like the ramblings of an above-average seven-year-old, so I'm just going to stick to what I know.

Instead, we're going to work off of XNA tutorials to learn the underpinnings of the language itself. Microsoft's site doesn't reveal tutorials unless you really go digging, but I finally found one that's been EXTREMELY helpful. Here's a link if you want to follow along with me.

The idea behind this tutorial is to give us all a better idea of how to build a simple game while walking alongside us with the code. We'll try and follow along.

I hope we're all familiar with the idea of a "variable." In case you're not, a variable is a value that can change over the course of our program. For example, let's take a video game character like Cloud Strife. When he starts out the game, he may have 200 hit points. Over time, that number can change. It can go up, down, or do whatever within certain limits. That's a variable.

There are couple main types of variables that we'll use: integers, Boolean expressions, vectors and textures. Cloud's hit points are an integer, or a whole number.

A boolean expression is something that's either true or false. For example, when Cloud has one or more hit points, he's alive. When he has zero hit points, he's dead. That's a boolean value.

Vectors are the location of an item in 2D or 3D space, and textures are what any given tile will look like, as far as I know. I could be way off on those definitions.

So, if we want to declare a variable, the tutorial suggests that we do something like this:
public int Health;
What I've done here is said that this variable is going to be an integer (or "int"). We're naming the variable "Health" and ending the statement with a semicolon to end the "sentence."

This goes hand in hand with the idea behind "methods," or "functions." The nearest analogy I can come up with is this:

During the day, you do several tasks repeatedly. Most boil down to a few basic things. For example, you eat, go to work, brush your teeth, use the bathroom, etc. Each of those individual things you do is comparable to a "method."

For example, when you eat, some of the possible variables could be:
  • The food you're eating
  • How much time you have to eat
  • What utensils you have
Using those variables, you will do the method that we'll call "Eat." After "Eat," you'll use the method "Work." Some of the possible variables for that could be:
  • How long you have to work
  • What tasks you must accomplish
  • Who you're working with
After you've done the method "Work," you may go back to "Eat." Maybe after "Eat," you'll do more "Work." Then you'll do the method "Drive," where you'll go home. Some of the variables may be:
  • What you need to do on the way home
  • What the traffic is like
  • If there are any roads closed
And so on. In the program from the example above, they've declared a few methods at the beginning which will form that basis of most of our programs:
  • Initialize
  • Update
  • Draw
"Initialize" appears to be the beginning of the game. "Update" asks the program what's changed. Has the player hit the left mouse button? Has he hit the space bar? Has an enemy moved to the left or right? Did the player shoot a gun? "Draw" puts the results of the update on the screen.

That should give us a good starting point. We'll complete the step called "Creating the Player" and then go from there.

No comments:

Post a Comment

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