Deprecated: Assigning the return value of new by reference is deprecated in /home/nicholas/public_html/ggnew/components/libraries/cmslib/spframework.php on line 101

Deprecated: Assigning the return value of new by reference is deprecated in /home/nicholas/public_html/ggnew/components/libraries/cmslib/spframework.php on line 644
Tutorial: Making a Game
Tutorial: Making a Game

<< Go Back to Other Tutorials

In this tutorial series, you'll learn how to make a videogame with the Propeller.  The game you'll make is the lightcycles game from Tron, here's a demo of the finished product;

This is the first of a 3 part series.  Stay tuned for parts 2 and 3!

Introduction

One of the important differences that sets the Propeller apart from most other microcontrollers is its ability to do video. The hardware connections are extremely simple. Three resistors connected between the Propeller and the AV-IN of your television and you are in business. If you haven't taken the time to configure your Propeller to do video and view the "Graphics Demo" included in the Propeller Tool, this would be a good moment to stop reading and do so.

People who know me, know that I'm almost as heavy into collecting old computers as I am into programming the Propeller. The game platforms from the 80's were extremely limited in their capabilities, but they provided something that modern gaming as left behind; an ability to understand of how things work. While modern gamers enjoy rich, powerful 3d graphics environments and games, actually being able to comprehend how the technology works would be a little like trying to learn Chinese in an afternoon.

The Propeller will allow us to "spin" the clock back twenty years to examine how basic graphics manipulation and gaming works. At the heart of every pulse pounding, 3D, multiplayer shooter, are the same concepts used by every game since the creation of PONG.

This tutorial will start with the fundamentals of game design. Through the course of this tutorial you will design a simple LIGHTCYCLES type game based on a popular movie. I will expect you to understand just enough Spin programming to be dangerous, so if you haven't completed some of the basic lessons, take the time to work through them before continuing.

Required Hardware

  1. A Propeller board capable of TV video out and keyboard or NES controller input
    I'll be using the Propeller Platform USB with the El Jugador Module, but a Parallax Propeller Demoboard with PS2 Keyboard (or equivalent) will also be fine.
  2. A couple NES controllers or PS2 keyboard
    We'll be creating a two player game, so if you are using NES controllers, you'll need a second one by part 3. If you are using a keyboard configuration, we'll squeeze both players in on either side of the keyboard.

A quick "Sanity Test"
Before we jump in, it is always wise to do a quick sanity test on the hardware. To make sure that our video connection is working correctly. Open the Propeller Tool and load the "Graphics Demo" to your Propeller using F10. Do you see moving graphics? If not take a few moments and check your connections. This simple test will insure that we have success in this lesson.

A preview of the objects
As you've seen in the Graphics Demo, the Propeller is capable of amazing video, but even the commands used in Graphics Demo can be a little daunting to a new user, so we're going to take one step backward and work with a text driver.

The microcomputers and game systems of the 80's had their graphics and sound capabilities hard-wired into the chips used in those systems. This meant that upgrading generally meant buying a new system every few years. Unlike those old systems, the Propeller is capable of a variety graphics and sound systems by simply changing the object code doing the work.

We'll be working with two objects; the first is a universal game control driver called, MIGS which allows us to create games which are compatible with a variety of game controllers like NES, N64, or keyboard without having to rewrite our code. The second is a video/text driver called AIGeneric which will power our display. These primitive 'drivers' will allow us to have a great time writing a game while understanding the concepts of game design.

Don't underestimate the power of the drivers we are going to be using. The systems of the 80's operated at single digit megahertz speeds. The Propeller will be operating at 80Mhz! This makes it possible to do amazing things with very little.

Setting up the environment

Download and extract the source code zip to an empty folder. Create a new spin program called "Demo1" and save it to this folder. This is the program we'll create.

We're almost ready to jump right in, but first let's look at the two possible configurations you might be using depending on your hardware.

Option 1: Propeller Platform w/ El Jugador Module
This platform takes advantage of video out as well as NES controllers for real gaming feel. Our program will start with the following configuration:

Video out starts with Propeller pin 12
NES controllers start with Propeller pin 23

game_tutorial_1

Type in the code above. The _clkmode & _xinfreq lines are pretty much standard in most Spin programs as they set the Propeller's speed to the 80MHz used by most boards.

(Compatibility Note: If you have a Parallax NES controller card plugged into a different board, the "controller = 23" line is simply the CLK pin. Adjust it to the pin number used accordingly, and the other lines should fall out fine.)

Option 2: Parallax Propeller Demoboard with PS2 Keyboard attached
This platform takes advantage of video out, as the keyboard to serve as input for both players. One player will use the cursor arrow keys. The other player will use F,S,E, and D, and [ENTER] will be used as Start.

Video out starts with Propeller pin 12
PS2 Keyboard starts with Propeller pin 26

game_tutorial_2

Type in the code above. The _clkmode & _xinfreq lines are pretty much standard in most Spin programs as they set the Propeller's speed to the 80MHz used by most boards.

The MIGS object is designed to take advantage of a variety of game control systems. An addendum will be provided to show you how to easily add a Nintendo 64 game controller to your Propeller.

What the heck did we just do?  All microcontrollers work internally with numbers, in fact they prefer them! Humans on the other hand prefer words and pictures. The CON section has the two lines to set the speed, but also the following two lines:

    video = 12
    controller = 23

We have told the program to consider the word, "video" equal to the number "12". This way any time we need to say "12", we can simply say, "video". Because these are located in the CON section, their values are set in stone the entire time the program is running. We could have used almost any word or number.

The OBJ (Object) section includes the AIGeneric & MIGS controller objects into our code. These two objects will do the "heavy lifting" of making the magic happen by calling on their available methods. Later as you get further into programming your Propeller, you can even make your own Objects defining the rules that your program uses.

When we call on the "methods" available in these objects we'll use text.{method} & migs.{method} as defined in the OBJ section. If your eyes are starting to glaze over right about now, don't worry, you'll see how it works in the code.

VARiably speaking
It's time to add a couple variables to our program. Type the following code below what we have already entered. As you start to type VAR, you'll notice the color change again.

game_tutorial_3

The VAR (Variable) section defines variables which can be used anywhere in our code. Unlike the words defined in the CON section variables in the VAR section can be assigned any value we want, anytime in our program. Think of variables as empty boxes which can store information. See the word, "byte"? In this case, the word "byte" defines the size of our box. Bytes are small boxes which are only big enough to store a single number or letter. We'll store some information in character_x, and character_y soon enough, but for now we'll set those empty boxes aside. Just like CON we could have called our byte-boxes almost anything we wanted.

It's time to go PUBlic
Type the following code below the VAR section. Again the color will adjust as you start to type in PUB.

game_tutorial_4

The PUB (Public) section of our code will contain the commands to actually do something interesting. The two lines we just entered kick start the objects we called in the OBJ section. Remember what we said about the words, "controller", and "video"? The Propeller sees this as migs.init(23) & text.start(12). Why do we do this? This makes it easy to adjust these settings in the top of our code without fishing through the program to adjust pin settings.

Continue to Page 2: Graphics & Controls >>>

 

Other Stuff