Make yer own!

Make yer own!

So you've decided you want to write a game…

  • Home

Remembering Important Things

Posted in Getting Started by J Artis
Sep 02 2009
TrackBack Address.

At the very heart and soul, programming a computer is nothing more than math, math, math. Don’t let that frighten you away, though, we’re not talking ridiculous amounts of super-calculus or anything (at least, not yet) – it’s all the same skills you use to balance a checkbook. Programming languages exist almost for the soul purpose of making it easier to read and understand, and keeping you as far away from the “nuts and bolts” math that drives a computer. However, we do have to make certain concessions to the machine – one of the important ones is deciding HOW to store information.

Programming languages can be categorized in a number of different ways, but one of the most important it “typing”. A language can be “Strongly typed” or “Weakly typed”. Both of the languages we’re working in here, C++ and C#, are Strongly Typed languages – some others, such as Actionscript, are not. This will be an important note shortly, but first I will explain what it means a little better.

Along with storing some information, programming languages allow, or encourage, our in our case REQUIRE, that you indicate what KIND of information you are storing. Is it a number, or a string of characters, or a true/false value? Let’s look at some of the “types” of variables we can have, specifically the ones we’ll use most often to begin.

  • int

Short for “integer”, this stores a whole number (no fractional part, no decimal point) – and it can only hold a certain range. The range can vary from environment to environment, and language to language. For now, let’s assume an int is 32 bits – it can hold any value from-2,147,483,648 to 2,147,483,647. Two billion is quite a lot, so we should be safe most of the time using one of these to store a number – like a score, a coordinate on the screen, a number of lives…

  • bool

Short for “boolean”, this holds either a “True” or “False” value. That makes it good for testing things (did I hit an enemy?), which we can use to change the behavior of the program. There are a number of ways we can combine boolean values, to make multiple checks, that we’ll touch on a bit later.

To add either of them to our program, somewhere inside our game’s code, we add:

int myNumber;
bool myBoolean;

To set a value from something else, use one equals sign:

myNumber = 3;
myBoolean = false;

And to test to see if it’s the same as something else, use TWO equals signs:

if (myNumber == 4)
if (myBoolean == true)

That’s it. Really. In theory we can make our whole game using almost nothing but those two types, and varying combinations of them. We will go back and touch on ways to bring them together, and strange things you can use them for, but for now, our space invaders design should contain two lists – A list of ints (numbers we need to keep track of), and a list of bools (yes/no questions about what’s going on in the game).

Share
Leave a Comment
Click here to cancel reply.

Recent Posts

  • My Bad Habit
  • Number names in Scrabble scoring
  • Analysis of Sinister Sudoku
  • Finding words for HexWords
  • Considering control schemes
Powered by WordPress | “Blend” from Spectacu.la WP Themes Club