Creating Arcade Games On The VIC (1984)
Creating Arcade Games On The VIC (1984)
Robert Camp
ARCADE
GAMES ON THE
Robert Camp
COMPUTEr Publications,lnc.<
One of the ABC Publishing Companies
Reproduction or translation of any part of this work beyond that permitted by Sections
107 and 108 of the United States Copyright Act without the permission of the copyright
owner is unlawful.
ISBN 0-942386-25-6
10987654321
111
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
Foreword
Most people who play arcade games take them for granted. But
when you try to program such a game on your VIC, you quickly
learn to appreciate the amount of work and creativity behind
every game. Figures on the screen, movements or collisions,
sounds all must be fit together into a complex, yet harmonious
whole. It can easily seem impossible, especially if you're just
starting.
Until now, most game books for personal computers have
been simple listings of programs which could be typed in and
run. Now you can learn the principles and techniques of writing
your own games.
Be Patient
Your learning process won't be just like mine. You'll grasp some
things faster than I did; other things may take more effort. One
thing is sure — unless you're already an expert programmer, pro
gramming a game is going to take time. Not only the time to type
the program lines in the first place, but also the time it takes to fig
ure out why the game isn't working. Because unless you're a
miracle worker, your program is going to have some bugs in it,
some places where things aren't happening the way you
planned.
So be patient with yourself. Even with the help of this book,
programming takes a while to learn. Don't expect to learn every
thing in a few hours one night. And don't expect your first pro
gram to run smoothly. If you're like me, there'll be more than a
few nights when you sit there staring at some program lines, try
ing to figure out why the program crashes whenever it gets there,
only to discover that you typed a zero instead of the variable O; or
that you forgot to have your countdown FOR-NEXT loop STEP
-1, so it's only executing once; or that you put the wrong variable
as the subscript of an array; or that your GOSUB refers to a line
that you deleted in your last series of revisions.
That sort of thing happens to everybody. It's just one of the
realities of working with a computer. Your VIC will always do ex
actly what you say — not what you really meant to say.
improve it
Just because the program rims doesn't mean the game is perfect
— it only means the program is perfect. After your own tests and
the neighborhood-kid tests, what can you think of that would
make the game more fun, or make it stay interesting longer?
If you can think of some things, analyze your program and
see how easy it would be to make the changes. If it's feasible, go
ahead and try the improvement. But make sure you save a couple
of tape or disk copies of the program that ran correctly, in case
your improvements go so far off track that it's easier to go back
and start over.
Market it
This might be a little premature, since your game isn't written yet,
but it doesn't hurt to know in advance what the market possibil
ities are.
A lot of commercial software companies are eager for games,
and they're especially eager for games for the VIC. Also, quite a
few magazine and book publishers have discovered that their
leaders enjoy typing in and playing games. Once your game is
ready, there might well be a software distributor or a publisher
who'll be glad to purchase the publication or software rights from
you.
1
The vic is a
Game Machine
10
1
The VIC is a
Game Machine
RAM
The more I get to know the VIC, the more I realize what a power
ful computer it really is. Its RAM (Random Access Memory) starts
at 5K (about 5000 bytes) and can be expanded to 32K (32,768
bytes). Every letter or symbol you see on the screen, every pro
gram instruction, every number you use takes up at least one byte
of RAM. That means that the more RAM you have, the larger and
more complex the programs you can run.
Even the unexpanded VIC is a powerful computer — on the
original vacuum-tube computers at the beginning of the com
puter age, 5K would have taken 40,960 vacuum tubes. That little
box you have in front of your TV would have looked like a miracle
back then.
But it's only natural that the 5K VIC won't be able to handle as
complex and detailed a game as a VIC with more memory,
especially if the game is written in BASIC, which takes up more
memory than a machine language program. Since we're working
with the basics in this book, well deal exclusively with BASIC
programs, and since I want this book to be valuable to the largest
number of readers, almost everything we do here can be done in
5K.
That means that the sample programs here will be pretty sim
ple. But you'll be learning all the principles of VIC game program
ming, so that if you have more than 5K on your computer, there's
11
1
The Vic is a
Game Machine
nothing to stop you from combining all the things you learn into
really dazzling 32K games.
And if you are working with only 5K, you'll soon find that
while your graphics displays might not be as pretty as those in
the arcade games, and your animation might not be as detailed,
you can make games that play very well and stay fun and interest
ing for a long time.
Besides, limited memory just forces you to be more creative,
finding ways to fit as many features into that 5K as you can. You
don't have to rush out and get an expander right away. It might
even be a good idea to work with the 5K for a while, learning
methods of shortening your programs. It can help you develop
good programming habits that you'll find useful even with larger
memory. You'll know when you really need the expander — and
by then the price will probably be half what it is right now.
The Screen
The VIC screen is 22 columns wide and 23 rows from top to bot
tom. That's fewer rows and columns than many other home com
puters, which is why each letter is bigger and takes up more
space. In effect, this means that each display screen is "smaller"
than with other computers — the screen displays fewer characters
at a time.
But that isn't necessarily a disadvantage. A 22-by-23 screen
means you have 506 squares to work with. That's a lot.
Besides, each square is really an 8-by-8 grid of 64 smaller
squares. That's how letters are made — by putting one color in
some of those squares, and another color in the rest of them. The
pattern makes the letter shape. Since the VIC displays 506 blocks
of 64 pixels, you really have 32,384 pixels at your command.
That's high-resolution graphics!
With the VIC, you can design your own character shapes.
And since each character block is bigger than those on most com
puters, you can change larger areas of the screen display with
each single command. What you may lack in fine-line drawing
you have gained in speed and memory space.
colors
With a color TV or monitor, the VIC can produce 16 different
screen colors and 8 character colors. The background, border, and
characters can have different colors, and in multicolor mode the
characters don't all have to be the same color, either, allowing you
hundreds of possible color combinations.
12
1
The Vic is a
Game Machine
Graphics Characters
You can redefine characters — but that does use up memory.
Don't forget that the VIC provides 62 built-in graphics characters.
You can save a lot of memory by using as many of those existing
characters as you can before you start defining new ones. Many a
great game can be designed without a single character
redefinition.
Sound
With the VICs four voices, you can get a variety of sounds and
sound effects, from explosions and lasers to a Bach fugue.
Sounds are not really extras in a game. They serve several vital
purposes, and the VIC gives you plenty of sound resources to
work with.
Languages
The VIC has two languages easily available, BASIC and machine
language.
Machine language consists of eight-digit binary codes that
give instructions to the CPU (central processing unit), which is
the real brain of the machine. The binary number 10000101 (deci
mal 133) tells the CPU to store a certain value in a certain location.
Since machine language is the CPU's native tongue, so to
speak, the computer understands it very quickly. That's why
games written in machine language are very fast and run very
smoothly.
The trouble is that numbers like 10000101 aren't too easy for
human beings to work with. Even when they're translated into
hexadecimal (base 16) numbers, they don't carry much meaning.
So machine language programmers usually write their programs
with an assembler program, which uses a series of three-letter
mnemonics which stand for the machine language commands.
STA is the mnemonic for 10000101. The assembler program then
translates symbols like STA into machine language numbers. It's
that translated program that becomes the finished game.
However, machine language programming is very tedious
and very complex. Especially for beginners, BASIC is by far the
t easier language for programming. The commands are more like
English, they're easier to remember, and it takes fewer commands
to perform each operation.
What you get in ease of programming, however, you pay for
in running time. While your BASIC program runs, BASIC has to
13
1
The vic is a
Game Machine
The 6502
The VIC has a brain made of silicon. The CPU (central processing
unit) is the famous 6502 microprocessor. MOS Technology, the
company that created the 6502, is now a subsidiary of Commo
dore, the company that made your VIC. The 6502 is now the CPU
in the Apple, the Atari, and other microcomputers. Because
Commodore owns the 6502 and many of the other special chips
in the VIC, they can offer the VIC at a lower price than if they had
to buy the 6502 from somebody else.
Program Translation
Just because Apple, Atari, and Commodore all use the same CPU
doesn't mean that you can run programs written for those
machines on your VIC.
For one thing, VIC BASIC is different in small but important
ways from the BASIC used by the other machines.
Also, the CPU doesn't control everything going on in the com
puter. Each computer has its own way of communicating with
cassette recorders, disk drives, keyboards, and the screen.
Each memory location can mean different things on different
computers. When the 6502 stores a 1, for instance, at location 50
in RAM, that might tell one computer to turn off the TV screen,
while another computer would take that as a command to erase
memory and start over.
However, as long as a BASIC program sticks to generally
accepted BASIC commands and doesn't PEEK and POKE into
14
1
The vic is a
Game Machine
15
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
2
Game Design
If you don't know where you're going, how will you knc 1OW
words
Let's look at Joust in detail. When you put in a quarter, what hap
pens? There are words on the screen, telling you what to do next.
When you choose the one- or two-player option, there are more
words. Remember, too, that there are instructions written on the
outside of the game machine. All of these, combined, tell you
how to operate the controls.
This is documentation. If it is written down on paper or on the
machine, it is printed documentation. If it appears as part of the
19
2
Game
Design
The Display
Then the words disappear from the main display area. What is on
the screen? The playfield — the area where the game action will
take place — consists of brown, rocklike islands. The bottom is
land rises from the base of the screen, with a lake of fire on either
side. The other islands, though, float in midair. Several of them
have white strips near the surface — these, the player will soon
discover, are the platforms where new player-figures and new
enemy knights will appear.
Besides the playfield, there are several other things on the
screen. The score is constantly displayed, for either one or two
players, so you can keep track of how many points you have to
earn before the next bonus knight. Also, there is a little box that
displays how many knights you have left; this lets you see at a
glance how many more turns you'll have.
Collisions
Now other knights start appearing on the screen. They're
computer-controlled characters that fly according to their own
20
2
Game
Design
One oddity is that if you glide into contact with the surface of
an island along an almost exactly horizontal path, the legs of your
mount won't come down. Youll just bounce along without walk
ing, belly-flopping your way across the screen.
When you collide with another knight, one of three things
can happen. First, if your knight and the other one are on almost
exactly the same level, you will simply rebound from each other
with a loud noise.
If your knight is lower on the screen than the other knight,
your knight will disappear, and a new one will come to life at one
of the creation platforms.
If your knight is higher, it is the enemy that disappears. In his
place, a large egg flies away from the mount, as the mount flaps
quickly off the screen.
Your knight has a certain amount of time in which to go col
lide with the egg before a new enemy knight hatches out of the
egg, and his mount flies out to join him. The egg trembles a bit
before it hatches, and the enemy's mount does take a while to
arrive and get in place, so there's plenty of warning — but if the
new enemy knight gets mounted, he is more formidable than the
one before. And the sooner you get the egg, the more points you
get.
intelligent Enemies
The enemy knights start out relatively slow and stupid, but even
at the start they tend to notice where your knight is and home in
on him. Also, the red and blue enemy knights are faster and
harder to beat. They have a habit of maneuvering right under the
edge of an island, or right along the top of the screen, so that it's
hard for you to get above them. They also use the island and
screen for rebounding — they fly quickly upward and then re-
21
2
Came
Design
bound downward so they come at you faster than you expect and
from a direction you weren't prepared for. If you follow their
strategies, you'll do better against them.
Other Hazards
From the third level onward, the sea of lava at the bottom of the
screen is uncovered. If your knight falls in, he is consumed. If he
comes too dose while moving too slowly, the lava troll reaches up
and seizes him, pulling him downward into the lava. The hand
sometimes seizes the other knights, but, after holding them
awhile, always lets them go. While they are being held, however,
they are vulnerable to you.
Creation
What happens after one of your knights has disappeared? One of
the platforms turns yellow, and your knight rises into view. Un
like the enemy knights, yours does not immediately fly away. If
you don't move, you have a few seconds in which your knight
cannot be harmed, to wait for enemy knights to leave you a clear
section of sky in which to take off.
You'll also notice that usually your new knights arise from a
platform in the area where the fewest enemy knights are flying.
Likewise, when enemy knights are being created, they will not
usually appear at a platform if your knight is hovering too close.
increasing Difficulty
The longer you play, the harder it gets. The most noticeable
change is that at higher levels there are more enemy knights.
Also, the knights move faster and make more erratic, unpredict
able movements. They also get smarter and evade you better.
If you take too long at any one level, a pterodactyl appears
(though I prefer to think of it as a phoenix). The pterodactyl flies
back and forth across the screen and doesn't home in on you very
accurately, but if you're careless it will get you — and then it
doesn't help you to be above it, for the pterodactyl is
''indestructible."
Or is it? The message on the screen says, "Beware the inde
structible (?) pterodactyl." That question mark leaves some doubt,
and you eventually learn that if you meet the pterodactyl head-
on, with your knight's lance exactly at the level of the monster's
mouth, you can kill it. At later stages, the pterodactyl comes on
the screen almost at once, and homes in on you faster and more
accurately.
22
2
Came
Design
increasing interest
If a game stays the same from beginning to end, except for getting
harder, it soon becomes dull. Joust adds some new elements to in
crease interest. There is a Survival Wave. If you can keep the same
knight alive throughout that wave, you get a substantial bonus. If
you are playing with someone else, you have waves of competi
tive play and cooperative play, in which you get bonuses for hit
ting each other or for not hitting each other.
There is also an Egg Wave, in which, instead of enemy
knights, all their eggs are strewn on the platforms. It is difficult
but not impossible to get all the eggs before they hatch. But when
the enemy knights hatch, they are significantly better fighters than
they were in the round before.
The pterodactyl, the lava troll, and the disappearing islands
also serve to change the game and add interest.
incentives
To encourage you to play again, improving each time, Joust gives
you a score for your achievements in the game. Each egg you get
is worth 250 points more than the last one, starting with 250
points and peaking at a maximum of 1000 points per egg. You also
get a bonus if you get the egg quickly.
If your knight is destroyed and a new one appears, the scor
ing starts over at 250. Likewise, the egg scoring starts over with
each new wave.
You get 1000 points for killing a pterodactyl.
Every 20,000 points, you get a bonus knight. This means that
the better you play, the more chances you have to play even
longer.
If your score is higher than the lowest score on the vanity
board (list of best players), you get to enter your initials at the end
of the game.
Sounds
Each event has its own sound. A collision in which you win has a
different sound from a collision in which you lose. Bumping into
different surfaces makes different sounds. There are sounds for
knights arising from platforms, for eggs hatching and birds com-
23
2
Came
Design
ing in, for the pterodactyl's arrival, and for collisions with eggs.
There are different sounds for walking and for flying. There is a
sound to tell you when you get a bonus knight.
Even while you're concentrating on your own knight, trying
to keep him alive, the sounds tell you a lot about what's going on
elsewhere on the screen.
Story
Everything we've analyzed so far is detail, the bits and pieces that
come together to make up the whole effect. But much of the fun
in Joust is the story. You get to be a knight on a fantastic steed, fly
ing rapidly among floating islands, jousting with dangerous
opponents and evading or attacking mythical monsters. It's a fas
cinating world, a fantasy tale that you are acting out as you play.
Whether you get a hundred thousand points or a tenth of that,
you still get the pleasure of doing something with the computer
that you could never do in real life. It is a pleasure just to visit the
world of Joust, and that sort of pleasure can also be part of your
game.
24
2
Came
Design
25
2
Game
Design
Characters
On your VIC, a whole set of shapes already exists. Every char
acter on the screen is a pattern of pixels that you recognize as let
ters or numbers or other symbols. None of them looks like a
spaceship or a gorilla, but that's all right — you can design your
own characters to replace some or all of the regular characters.
When your program PRINTs the letter A, for instance, what ap
pears on the screen will be the pattern you designed. Or several
new characters can be put together to make part of a larger picture
on the screen.
26
2
Came
Design
I Animation
The pictures are just pictures until they move. It is when the
wings of your steed start to flap that Joust comes alive. And half
the fun of Donkey Kong Jr. is making Junior climb up or slide down
the ropes and chains.
It is possible to make your animation as smooth and realistic
as the best cartoon movie. But you also face the same problems
that a cartoon animator faces. Each slight movement of a character
requires a new picture of that character. Each direction a character
faces, each action the character performs requires another draw
ing. And that takes memory.
So game designers compromise. They simplify the anima
tion. The gorilla in Donkey Kong stamps his feet and grimaces —
but that requires only two drawings per leg (stamping and not
stamping), two drawings for the face (grimacing and not grimac
ing), and a single drawing for the body. When Kong is rolling bar
rels, there are new drawings to show him doing that. But since he
rolls barrels to only one side, the programmer hadio create the
shape for only that side. And there's no attempt to make the
gorilla walk realistically — he just bounces, without moving his
legs. Ifs far from a classic Disney animated film, but it's good
enough to make a great game.
Remember that anything on the playfield that changes dur
ing a game requires the same sort of memory considerations. If a
trap door opens or a cup of milk empties, you'll need new char
acters for every new shape you show.
27
2
Came
Design
I Player Movement
When players press a key or move a joystick, something needs
to happen on the screen. And here is where the "feel" of a game
comes in. Pushing on the joystick only causes a movement on the
screen when your game program checks the joystick and makes
changes according to what it finds there. If your program checks
the joystick only once every second, the player-figure can't move
any more often than once every second. And that's going to feel
awfully sluggish to players.
As long as you're programming in BASIC, you'll want to de
sign your program so that it checks the joystick and allows move
ment as often as possible. (That isn't so important in machine lan
guage games, however — everything happens so fast that you
often need to insert timer routines to slow down the action.)
So when you're planning your program, you'll probably
build it around a central loop, a series of commands that repeat
over and over. At the heart of that loop will be a joystick-reading
routine. If the player isn't pushing the stick, then you can skip on
to other things. But if some action is requested, your program
needs to be able to perform it as quickly as possible after the
player asks for it.
This means that you want to have as few things happening
on the main loop as possible. If the computer-controlled enemy-
figures move as often as the player, then they will all have to be
moved every time you go through that loop. And in BASIC, that
will make your program crawl.
The solution is to compromise. Either have fewer computer-
controlled opponents, have them move less often, or give them
simple, regular actions. The back-and-forth movement of the
aliens in Space Invaders is a good example of this. They don't aim
when they shoot; they don't have to figure out a path when they
move. They just do the same thing, over and over. Nothing could
be simpler — or faster.
And as you design your program, move as much as possible
off the main loop. Using IF/THEN GOSUB or ON/GOSUB state
ments, you can have the program decide during the main loop
whether a particular routine is necessary. If it is, the program can
jump to the subroutine and then come back; if it isn't, the pro
gram can ignore it and go on, without wasting much time.
Eventually you may even start looking for books on machine
language, so that your game programs can perform some of these
functions much faster than BASIC allows. Still, don't despair if
28
2
Game
Design
your first version of a program runs more slowly than you want.
You'll soon learn tricks to streamline your program and make it go
faster. As long as you don't expect the impossible, you'll be able to
get your game to play smoothly and well.
I intelligent Opponents
It's one thing to have the aliens in Space Invaders move mind
lessly back and forth across the screen, or a centipede mindlessly
dropping downward according to a set of rules. It's something
else again to have the computer operate seemingly intelligent
opponents that maneuver to try to get the better of you.
In a primitive form, like Berserk, it's a simple homing instinct
— the robots tend to move up if your player-figure moves up.
In Joust, however, the programming is much more complex.
The opponents have a general homing pattern — but they also
have built-in strategy. If you're near, they'll maneuver to gain alti-
29
2
Game
Design
tude on you; they'll hover under the lip of a floating island; they'll
fly upward and rebound down on you. The algorithms to control
that kind of behavior are pretty complex, both as mathematics
and as programming — it verges on artificial intelligence.
But don't worry. Most arcade games aren't nearly so complex.
In Donkey Kong, for instance, the flames do have a tendency to
home in on Mario, but they also follow certain basic patterns.
When you learn them, you realize that the flames are only slightly
more complicated than the robots in Berserk.
There are three levels of intelligence in computer-controlled
figures: the mindless pattern, the homing pattern, and artificial
intelligence.
Mindless Patterns
Here, the figures move in a set pattern, regardless of what the
player does. Examples are the aliens in Space Invaders and the
birds in Donkey Kong Jr. Once you see the pattern, you can plan on
it and work around it. However, the computer usually makes up
for its lack of subtlety by having lots of opponent-figures for you
to cope with. One alien moving back and forth across the screen
would be a picnic; a few dozen, and it's suddenly a challenge.
Artificial intelligence
With this kind of opponent, the computer anticipates what you
will do and plans strategies accordingly. Sports simulations often
require this, as the computer lines up a football team in a pattern
that it thinks will cope with whatever you have planned. The
complex knight movements in Joust require some anticipation.
But games that rely heavily on artificial intelligence algorithms are
30
2
Game
Design
I Other complications
Besides the computer-controlled opponents, you'll probably
want to have other hazards. Most games have them.
In Vac-Man, for instance, the maze itself is a complication be
cause players have to keep turning and dodging, and can get
trapped in long corridors with ghosts at both ends.
In Joust, the lake of fire and the demon hand make the game a
bit trickier, while the islands make it impossible to have many
long, smooth flights. The eggs are one more thing to worry about
while you try to battle the other knights.
Donkey Kong makes you cope with ladders and elevators and
gaps between girders. Kangaroo makes you climb or leap from
level to level. Rally-X not only has a maze, but also puts random
rocks in the road and keeps you worrying about running out of gas.
The basic principle of complication is to make sure the player
has to think of several things at once. Not only do you have to
dodge the pickles, hot dogs, and fried eggs in Burger Time, but
you also have to make hamburgers and Egg McMuffins. The more
things going on at once, the busier the player has to be.
But, again, don't make it impossible. The complications
should come at a rate a human being can cope with. It isn't fun to
find out that a computer is quicker than you are. What's fun is
feeling like you're a match for the computer, at least for a while.
31
2
Came
Design
I Maintaining interest
One of the elements in games like Monopoly or Poker or Chess or
Go that has made them classics is that they remain a challenge, no
matter how often you play. You may not come up with a Monopoly
your first time, but you certainly don't want to create a game that
people will play once and then discard. So what is it about a
game that brings people back to play again and again?
Unpredictability
No game is completely unpredictable — the rules are designed, in
fact, so that it will play pretty much the same every time. What
32
2
Game
Design
good would baseball be if you never knew what order to run the
bases from one game to the next, or where the bases would be, or
the size of the ball? Yet every baseball game is different because
there are, within the framework of the rules, some things that can
never be predicted. The speed and spin of the pitch, the force and
direction of the bat, the angle and speed of the ball off the bat, the
arrangement of runners on the bases and players in the outfield
and the infield — these are never twice the same, even though the
rules never vary.
You'll notice that all those variables depend on what human
beings do. The trouble with computer games is that the computer
is absolutely predictable — it will always obey your program com
mands. The computer has only two ways of being unpredictable.
One is to generate a random number and use it in your program.
The other is to let the player's input change the way the program acts.
Space Invaders has very little unpredictability. The aliens will
tend to shoot more where the player is, and if you wipe out col
umns of aliens at the edges, it will take longer for them to reach
the edge and drop down to the next level. That's about it.
Missile Command uses the random method of being unpre
dictable. While the enemy always aims at the same targets, the
missiles never start at the same place and in the same pattern at
the top of the screen.
Dig-Dug depends on the player for its unpredictability. The
player, in effect, draws the playfield by carving a maze through
the rock. Even though the placement of the creatures at the be
ginning of each level is always the same, and their movement
starting times never vary, the levels can be as different as the
player wants to make them, because everything they do depends
on where the player has cut the maze and where the player hap
pens to be.
increasing Difficulty
Another way of keeping interest high is to make the game increas
ingly difficult. If you're a tennis player, you know that it's most
fun to play with an opponent who's just a little better than you.
And most arcade games use the same principle — no matter how
good you are, at some point the computer is going to be just a
little better.
How do you make a game harder from level to level? Speed,
accuracy, and complication are the keys.
Speed. At low levels, opponents move slowly and are easy to
catch or evade. Just by changing the timing, however, opponents
33
2
Game
Design
can be made to move faster, bit by bit, until they zip around the
screen. Players can also be allowed to move faster, so they have to
make decisions more quickly. And if opponents throw rocks or
shoot bullets, those projectiles can move faster so they're harder
to dodge.
Accuracy. At low levels, opponents can be programmed to
miss. In Asteroids, for instance, the big enemy ship fires some
where in the space around you — you usually have to practically
try to get hit for it to harm you. But the small ship, which comes
on later, fires much more accurately, predicting your future course
so that it's much harder for you to dodge in time.
Complication. Keeping track of four enemy knights is hard
enough at the beginning of Joust, when you're just starting out.
But in later levels, you have dozens to worry about, and the eggs
and pterodactyls, too.
Most games use a combination of these three, gradually in
creasing the speed, accuracy, and complications from level to
level. It's easy to do if you design your programs with some key
variables, so that you only have to change their values at the be
ginning of a level to have the game get faster and harder to play.
There's a problem, though, with having games get increas
ingly more difficult as you go from level to level. You have to get
through a lot of boring stuff that's easy to do before you can get to
the part of the game thafs challenging.
The solution is to let players choose their starting levels at the
beginning of the game. However, this might cause their total
score to drop, and those who care about high scores will be frus
trated. The designers of Tempest found one solution. If you decide
to start at a higher level, you get a progressively larger bonus
when you successfully complete that starting level. It's impossible
for someone who starts at level 1 to get as high a score as someone
who starts at level 11, even if both players end up at level 15, be
cause the bonus for starting at a high level is so large. In the
arcade, this also serves the purpose of encouraging players to
play harder, shorter games, so the quarters flow faster, but even at
home it's nice not to be penalized for starting out at a high level.
New Scenery
One thing that keeps players going with many games is the desire
to find out what awaits them at the next level. The changes can be
major ones, like the new screens introduced at each new level of
Donkey Kong, or they can be minor, like the succession of bonus
34
2
Came
Design
I incentives
Beating the machine and finding out what happens next are cer
tainly incentives to keep playing longer, better, and more often.
But you need to make sure that your game encourages players to
accomplish the tasks the game sets out for them.
Negative incentives are usually the first things people think
of. If you don't shoot the rockets out of the sky in Missile Com
mand, your cities will be blown up and the game will end. If you
don't punch out the monkeys and keep climbing in Kangaroo,
you'll be decked by a piece of fruit or a gorilla.
There need to be positive incentives, too, to keep the player
doing the right things. In Monopoly, for instance, you are encour
aged to buy properties early in the game because, if you do, you
get more rent later. You are encouraged to try for monopolies be
cause your rent is doubled and you can make property improve
ments. You are discouraged from mortgaging property because
you get no rent. That same kind of reward structure will help the
player of your game to do the things your game requires.
Scoring
Scoring is the easiest way to let players know how they are doing.
Each time players accomplish a goal, there should be a reward in
points. It doesn't matter if the players know exactly how the
points are awarded, but they should be given consistently, and
harder accomplishments should be rewarded with more points.
In Pac-Man, for instance, you get points for each dot you eat.
You also get points for each ghost you collide with after eating a
power pill. And each ghost you collide with on the same power
pill is worth progressively more points. The bonus for eating fruit
and keys increases with each screen, too, rewarding you more for
surviving farther and farther into the game.
35
2
Game
Design
But how many points? That's a tricky question, and it's really
up to you. The general rule is that easy things get few points and
hard things get lots of points. But no one accomplishment should
get so many points that it completely overbalances the game.
Point inflation. Also, you should keep "point inflation" in
mind. In Asteroids, you can't get less than ten points for anything.
The score always ends with zero. You could get rid of that last
zero, and it wouldn't affect anything, except that 1000 points
would only be 100 points, and so on. Your score would be just as
accurate.
So why does Asteroids multiply your "real" score by ten? Be
cause it feels a lot better to get 10,000 points than to get 1,000
points. The game inflates your score so that you feel like you've
accomplished more. After Asteroids, a game like Super Breakout,
which rarely lets you get above 4,000 points, feels rather tame, in
part because the score is lower.
But point inflation has limits. It's hard for players to visualize
a billion points, so if scores get into the billions and trillions, and
most of the score is meaningless zeros, players will tend to drop
off the zeros anyway, and talk about getting 15 or 30 instead of
15,000,000,000 or 30,000,000,000.
Vanity board. Part of the fun of scoring is to see if you can get
on the vanity board. Vanity boards began as a record of the high
score. Gradually, games began including the top three or top five
or top ten scores, and allowed the players to enter their initials or
even their names. Players quickly learned to use these for graffiti,
getting exactly the right scores so they could spell out messages of
varying degrees of cleverness. However, the vanity board was
erased when the machine was turned off. Now games often have
methods of storing part or all of a vanity board even when the
power is off. Most such games have split vanity boards. Half the
high scores are permanent and do not disappear; the other half
revert to zero when the game is off.
There are other variations, too. Some machines have default
values when they power up, so that your score won't show on the
vanity board until you get a minimum of, say, 10,000 points.
Others come up with phony initials and plausible but low default
scores, so that it looks like other players have left their initials and
scores even when no one has played the machine that day.
Ifs often a good idea, if your game has scoring at all, to have a
high score display at the end of a game, so that players can keep
track of the top score earned since the program started running.
36
2
ne
Design
You can easily keep the top three or five scores, with initials, or
the top score for each player. And it's not hard to include a perma
nent vanity board as part of the program, which is automatically
saved each time the game ends.
However, vanity boards use up memory, and when things get
tight in your game program, the vanity board is expendable; it
just isn't a vital part of game play, the way scoring can be.
Bonus Turns
Games like Vac-Man and Donkey Kong never allow more than one
bonus turn, but Dig-Dug, Asteroids, Galaxians, Joust, and others re
ward players with bonus turns at regular intervals. Limiting the
number of bonus turns helps the arcade owners because it means
people can't play as long on a single quarter — but people playing
your game at home on their VIC don't need that restriction.
Of course, it can be carried to extremes, too. Endless games of
Asteroids that end up with scores in the millions are the result of
poor planning. The program should have been designed so that at
the higher levels a dozen little enemy ships come on the screen at
once. Then the game would have stayed challenging.
Story Rewards
There are rewards built into the story of the game. In Donkey Kong,
Mario saves the girl; in Donkey Kong Jr., Junior saves Papa. In Kan
garoo, the mother saves her child. In these games, you'll notice
that the objective is often achieved — the girl, Papa, and the baby
kangaroo are saved several times during the game.
In games like Defender, Missile Command, and Asteroids, the
win condition can never be achieved — there are always new
waves of enemies, and never any time when the computer says,
"Congratulations. You saved the earth." That makes these games
more frustrating than the games that allow the main objective of
the story to be achieved.
I Sounds
Sound isn't just decoration. It isn't just music to attract you to
the game when you hear it out on the street — though it does that
very well.
Feedback
e you ever played an arcade game with the sound turned off?
Have]
ade owners sometimes get so tired of the sounds from populai
Arcade popular
37
2
Came
Design
games that they turn the sound off entirely. When you play a
silent machine for the first time, it throws your timing off com
pletely. You rarely realize how much you depend on sound until
it's gone.
Whenever players do something, your program should pro
vide a sound that lets them know that the computer got the mes
sage. The walking and jumping sounds in Donkey Kong are a real
help — sometimes it takes a moment to realize that Mario isn't do
ing what you told him, especially if you're glancing elsewhere on
the screen at the time, and the sound can make a real difference
in your timing.
News
Sounds also tell you about things happening elsewhere on the
screen. An explosion, a collision, an alarm going off, a sound for
having won a bonus round, a tune that tells you that the enemy is
vulnerable or to warn you that a new enemy is on the screen — all
these things help players keep track of what's going on while
they're concentrating on the player-figure.
Mood
And don't underestimate the importance of music for simply set
ting the mood for the game. Background music is something
chess never had. Videogame makers learned it from the movies.
Mysterious music can increase the suspense in a horror
movie — and in a videogame. Busy, tense music makes a chase
scene more exciting in an action film — and in a videogame. And
bright, cheerful music can be part of the reward for success.
However, unless you know how to put music into interrupts
— which can be done only in machine language — you'll have to
keep in mind that every use of sound takes up memory and slows
down the game. Most of the time, you'll probably use sound only
where it's really necessary — to give information to the player.
I Documentation
This is often one of the last things you'll add to a game program,
but it's the first thing a player will see. By the time you finish pro
gramming, you know your game intimately. You know every
thing that will happen at every level, and you are probably
already pretty good at beating the game. But other players won't
know anything at all, and you need to tell them enough that they
can have fun. If touching a balloon will blow them up, they
38
2
Came
Design
39
2
Came
Design
the machine and the programmer. Also, new ideas will occur to
you while you're programming. The plan you make before the
programming begins is to help you, not to limit you — to point
out needs, not to eliminate alternatives. Once the creativity starts
flowing, it can only help the game.
40
Setting up
Your screen
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
3
Setting up
Your Screen
The video display in your game is very important, because that
is where players have to "live" during the time they are playing
your game. If it is comfortable, showing the players all the in
formation they need to have, with attractive design and interest
ing graphics, they'll be glad to come back to that world again and
again. If it is cluttered and confusing and unattractive, the game
will be hard to play and they aren't likely to come back for more.
Changing colors
So let's start getting control of the screen. There are 128 possible
combinations of playfield and border colors. Instead of describing
them, 111 show them to you. Just type in this simple program:
10 FOR X = 0 TO 255.POKE 36879/X:NEXT
What does this program do? Location 36879 controls the back
ground and border colors. This program changes the number
stored at location 36879 by POKEing 256 different numbers there
— all the numbers from 0 to 255 — so each of the possible combi
nations is shown twice.
But this isn't very helpful. It all happens way too fast. So
here's a program that shows you the color combinations, but
more slowly. And the program will tell you what number is being
POKEd into 36879, so that if you like the colors, you can use them
in your game.
Anything between braces — { } — is the name of a special
VIC character. In line 10, you type the word PRINT, then a space,
then a quotation mark. But then you don't type { CLR }. Instead,
you press the SHIFT key and the CLR/HOME key. In line 30, you
don't type {2 DOWN} {8 RIGHT}. Instead, you type the
CURSOR DOWN key three times and the CURSOR RIGHT key
eight times. See Appendix B, "How to Type In Programs" for a
full explanation of all this.
10 PRINT "{CLR}11
20 FOR X=0 TO 255:POKE 36879,X
30 PRINT "{3 DOWN}{8 RIGHT}"X
40 FOR T=0 TO 1000:NEXT:NEXT
43
3
Setting up
Your screen
Now the screen changes more slowly, so you can see what's hap
pening. Also, line 30 shows you the number being POKEd into
36879.
Notice that when a value from 96 to 103 is POKEd in, the
numbers on the screen turn into blue boxes. And from 104 to 111,
the screen seems completely blank. The numbers are still there,
but they're invisible because they're the same color as the rest of
the screen. If you ever PRINT or POKE a character onto the
screen, and it doesn't show up, the first thing to do is POKE a dif
ferent value into 36879 — chances are the character is invisible be
cause it's the same color as the screen.
Invisible objects. That's an important thing to remember —
anything that is the same color as the background disappears on
the screen. That means that you could put invisible objects on the
screen, and then make them suddenly appear by changing their
color or the background color. Magic — with a single POKE.
Here's a program to show you how that works:
10 PRINT "{CLR}"
20 POKE 36879,110+104*(PEEK(36879)=110):GOSUB 30:G
OTO 20
30 FOR 1=0 TO 19:PRINT CHR$(32)"{DOWN}{RIGHT}";:NE
XT:RETURN
44
3
Setting up
Your screen
I Screen Memory
That principle applies to everything about screen graphics. The
VIC chip looks at a lot of different locations to find out what you
want the screen to look like. By changing what is in those loca
tions, you can get the VIC chip to display exactly what you want
— as long as you follow the rides.
Besides checking 36879 to get the background and border
colors, the VIC chip also scans an area called screen memory to
find out which characters to display on the screen, and another
area, called color memory, to find out what foreground and back
ground color each of those characters should have, and still an
other area, the character set, to find out what the character
actually looks like. It checks some other things, too, that we
won't worry about right now. It does all this 60 times a second.
And by changing what the VIC finds when it scans through
these areas of memory, you control what gets displayed on the
television screen.
45
3
setting up
Y&ur Screen
What can you POKE? The numbers you POKE don't always
have to be constants. They can be variables that contain the values
you want:
POKEADDR,NUM
POKEC(I),N(I)
In fact, you can even use expressions, like these:
POKE ADDR +X,INT((X*100)/256)
POKE SC +INT(I/256)*256,CHR$(N)
Everything to the left of the comma is calculated to decide the
address, and everything to the right of the comma decides what
value to POKE.
PEEK. You use this function to find out what is stored at a
certain location, without changing it at all. PEEK is not a com
mand — it can't stand alone. You can't just say PEEK 55 — the
computer won't know what to do. You have to have a command
that tells the computer to do something with the number it finds
when it PEEKs at a certain address. The address you are PEEKing
46
3
Setting up
Your Screen
47
3
setting up
Ybur screen
The CHR$ function uses the ASCII code. Almost every com
puter understands the ASCII character codes — that's why
BASIC uses them, so that your program can easily be trans
ported to another computer. But your VIC's operating system
has a harder time with them.
So you have two systems of code. But well go over character
sets in more detail in the next chapter.
10 POKE 36879,155:ADDR=7680:S$=MTHIS IS A TEST"
20 PRINT "{CLR}"S$
30 FOR X=l TO 14
40 A=PEEK(ADDR+X-1)
50 A$=MID$(S$,X,1)
60 PRINT A;TAB(5);A$;TAB(8);ASC(A$)
70 NEXT X
48
3
setting up
Your Screen
Line 100 takes the test message apart, one letter at a time, so that
in line 110 the program can convert it to its ASCII numeric value
(ASC(A$)). Then, if the ASCII value is greater than 32, the pro
gram subtracts 64 to get the screen code. This formula doesn't
work with all the characters, though — it's a bit more complex
than that. The character code tables in Appendices G and H show
the ASCII codes and screen codes for every character.
I Setting up a Screen
I Let's say we want to draw a cross (+) in the center of the screen.
The middle of the screen is character 11 in row 11 (counting from
0). To find x, the exact address in memory, multiply the row
49
3
setting up
Your Screen
If you type that in and RUN it, a small checkered square will ap
pear about the middle of the screen. (RUN this program each
time we add a new line to it, so you can see how each statement
affects the screen display.)
To put a character just to the left of that one, subtract 1 from
the value of COLUMN. Subtracting 1 always moves you to the
left, except when you are already at the left margin.
40 COLUMN=COLUMN-1:GOSUB 150
Borders
Now let's put a border around the screen. First, well fill the first
row:
Now, to keep the READY message from spoiling the screen, well
make it so the program never ends.
120 GOTO 30
51
3
setting up
Your screen
52
3
Setting up
Your screen
You'll notice that in line 30, the program scans the entire screen,
from position 0 to position 505, but the P character is POKEd only
if that spot on the screen does not contain the current Ncharacter.
Multiple READs. In line 40, the program READs two
numbers, N and P. That means that in the DAIA table, the num
bers for N alternate with the numbers for P. If you alter the table,
you need to make sure that your list comes out even, and that
there is a zero in the second-from-last position.
53
3
Setting up
Your Screen
54
3
setting up
Your screen
55
3
Setting up
Your Screen
I Color Memory
Color memory is a map of screen locations, just like screen
memory, only instead of interpreting the numbers stored there as
characters, the VIC chip interprets the numbers in color memory
as color codes.
Color memory is a perfect shadow of screen memory. For
every location in screen memory, there is a matching location in
color memory that controls the color of whatever character is dis
played on the screen. That means that the tenth byte of color
memory controls the color of the tenth character in screen
memory.
56
3
setting up
Your Screen
From then on, the variable SC (for SCreen) will contain the
address of the upper-left-hand corner of the screen.
The same system works for locating color memory, except
that the address of color memory must be found using a more
complicated formula:
CM =37888 +256*(PEEK(648)AND2)
Or, you can find out both addresses in the same program line:
SC =PEEK(648):CM =37888 +256*(SC AND 2):SC =SC*256
If you include this line at the beginning of your program, SC will
always be the address of the upper-left-hand corner of screen
memory, and CM will always be the address of the upper-left-
hand corner of color memory.
57
3
Setting up
Your screen
Line 900 establishes the values of CM and SC. Line 920 first gen
erates a random number in the range 0 to 7. It POKEs the screen
code for that number character (N + 48) into screen memory
(SC +1), and then POKEs the color code into the corresponding
location in color memory (CM +1). The same variable, I, leads us
to the corresponding locations in color and screen memory.
You'll notice that there are some blanks. These are the color
code that is identical to the background color. Whatever character
is being displayed there is invisible because there's no contrast
between the background color and the character color.
To see this working with graphics characters, try adding these
lines to 'Till In" (Program 3-2).
10 SC=PEEK(648):CM=37888+256*(SC AND 2):ADDR=SC*25
6
15 POKE 36879,233:PRINT "{CLR}":N=160:P=81
25 GOSUB 300
45 GOSUB 300
300 Q=INT(RND(9)*8):IF Q=PEEK(36879)AND 7 THEN 300
310 IF Q=PEEK(CM)AND 7 THEN 300
320 FOR 1=0 TO 505:POKE CM+I,Q:NEXT I:RETURN
Now the background color will change with each screen change.
The IF statement in line 300 protects us against having characters
the same color as the background. Line 310 protects us against
having the character color the same twice in a row.
Or start again with the original version of Fill In, and add
these lines:
10 SC=PEEK(648):CM=37888+256*(SC AND 2):ADDR=SC*25
6
15 POKE 36879,233:PRINT "{CLR}":N=160:P=81:GOSUB 3
00
Now the program assigns each location in color memory its own
random color value. What was once a completely regular, sym
metrical screen now looks completely unpredictable — and char
acters that used to fit together to make combined patterns now are
clearly separate.
If any of the material in this chapter is still unclear to you, it
58
3
Setting up
Your screen
might be a good idea to go back and review it, studying the exam
ple programs to see how they work. Without a clear understand
ing of screen and color memory and how to use them, it will be
harder to make use of the more advanced techniques presented
in the rest of the book.
59
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
Custom
Characters
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
4
Custom
Characters
The VIC comes with a complete character set, consisting of all
the numbers, letters, symbols, and graphics shapes that the
VIC can produce. These standard VIC characters offer plenty of
variety, and they can be combined to create many interesting
shapes and patterns, as weVe already seen in Chapter 3.
But there will be times when you need to draw a shape or a
figure that the character set just can't produce. Perhaps you need
a human figure, someone to live in the game world you've
created, to experience the problems and dangers your game will
present. The standard VIC graphics characters would produce a
stick-figure at best, and you want something better.
That is when you throw out the VIC character set and create
your own.
I Graphing a Character
I Once you've decided what kind of figures or patterns you want
to draw, you need to translate those shapes into a form your com
puter can understand. And your computer understands nothing
but numbers.
To see how shapes can become numbers, look at Figure 4-1.
This is the character matrix, a grid eight dots wide and eight dots
high. The matrix is not quite square because the dots are slightly
wider than they are tall.
Each character on the screen is created in this matrix. Dots, or
pixels, are either on (displaying the character color) or off (trans
parent, so the background color shows through). Figure 4-2
shows the pattern of on and off pixels that make up the @ char
acter on the VIC. If you compare Figure 4-2 to the @ character on
63
4
Custom
Characters
64
4
Custom
Characters
128 64 32 16 8 4 2 1 Total
0 28
1 34
2 74
Row 3 86
4 76
5 32
6 30
7 0
The second row has only two pixels on, the third and seventh
from the left, which form the binary number 00100010. The values
of this are 32 and 2, making a total of 34 for the second row. Check
the rest of Figure 4-2 to make sure the totals are correct.
You'll have noticed that the last row is completely empty and
has a value of zero. The reason for this is that the VIC produces
characters in the way outlined in Figure 4-3, but the 8x8 areas of
characters on the screen actually touch the adjoining characters.
This is what makes the screen a continuous field of dots. If you
want your characters to make one continuous pattern, draw them
right up to the edge of the matrix. If you want them to be clearly
separate, however, be sure to include spaces in your character de
sign, or one character will "bleed" into the next. If you leave space
at the bottom of the character, and on the left and/or right sides,
everything will work out fine. If all your characters have their left
column blank, you can fill in the right column and there'll still be
a separation. Note that this is what has been done with the @
character representation in Figure 4-3.
65
4
Custom
Characters
This running figure has 19 pixels on, while the other 45 are off. To
compute the value of each row of pixels, use the Character Work
Grid provided by Figure 4-5.
66
4
Custom
Characters
128 64 32 16 8 4 2 1 Total
0
1
2
Row 3
4
5
6
7
Figure 4-6 shows the running character laid out on the work
grid, with pixel values totaled on the right.
132 64 32 16 8 4 2 1 Total
0 24
1
2
H
■n LJ
■
24
18
Row 3 124
4 88
5
6
H wM 20
100
7 m i n 0
@ DATA 28,34,7436,76,32,30,0
Running Figure 1 DATA 24>24>18,124>88,20,100,0
67
4
Custom
Characters
I Memory Locations
I In Chapter 3, we worked with screen and color memory. These
are areas of Random Access Memory, or RAM; we could not only
PEEK to see what was stored in each location, but we could also
POKE them to change what was stored there. The character set,
however, is located in Read Only Memory, or ROM. You can PEEK
there, but you can't POKE. The character set is permanently
stored in your VIC.
The VTCs character memory begins at location 32768, with
the top row of the @ character. The second row of that character is
stored at location 32769, the third row at location 32770, and so on.
A formula for finding the location of a particular row for a given
character is:
Location Number = beginning of character memory (32768)
+ row + (8*screencode).
Note that the first row must be numbered 0 for this formula to
work. The screen codes for each character can be found in the Pro
grammer's Reference Guide or the VIC-20 User's Guide.
How can you create custom characters, if the character set
cannot be changed? The memory location that instructs the VIC
where to find the characters is in a RAM location. This can be
changed to point to several sections of memory. In fact, changing
where the VIC looks for character memory changes what is on the
screen at the time. By making the character memory pointer point
to the RAM of your VIC, you can begin to program your character
set.
The location from which the VIC gets its character informa
tion is 36869. Its value is normally 240, or 242, but it can be
changed. Although you can begin any custom character set in a
RAM location ranging from 4096 to 7168, the best place to start is
at 7168. To move the pointer to this RAM location, use the com
mand POKE 36869,255. Now the computer will look at location
7168 for character data, instead of at the location in ROM, 32768.
Doing this, however, presents problems. First of all, creating
your own character set by telling the VIC to get the data from
RAM makes the standard character set unavailable. This may not
be a problem if your game uses only custom characters. Then you
can simply create the necessary figures and PRINT or POKE
them into your game program. The following program does just
that.
68
4
Custom
Characters
Program Explanation
Line Function
10 POKE 36869,255 tells the computer to go to location 7168 to
get the data for characters, rather than looking in ROM
location 32768.
20 Locations 52 and 56 tell the VIC to change the pointers to
the top of the available RAM memory. The normal value in
the unexpanded VIC is 30. A value of 29 takes 256 bytes of
memory from BASIC, the smallest possible block. Ordi
narily, this would be enough for a small custom character
set.
30-50 Tell the VIC to replace the A and @ characters in the stand
ard set with the new figures by READing the DA3A
statements.
60-70 PRINT the new custom characters on the screen and keep
them there.
A program such as this produces only the custom figures you
instruct it to. You do not have any of the letters, numbers, sym
bols, or graphic characters in the VICs standard set. If you elimi
nate line 70, for instance, and press any key but the A or @, only
garbage will show on the screen.
If you need any other characters from the VICs standard set,
you'll have to copy the letters, numbers, or symbols you intend to
use into the new character memory in RAM. When you move
your character set to location 7168, the topmost section of BASIC,
you must also protect it from that program's actions. Fortunately,
both problems can be corrected easily.
The following program copies the first 64 characters of the
VIC to RAM location 7168 and then protects them from BASIC.
69
4
Custom
Characters
Program Explanation
Line Function
10 Again, POKE 36869,255 tells the computer to go to location
7168 to get the data for characters, rather than looking in
ROM location 32768. (To send the computer back to 32768
for character data, just POKE 36869,240, its normal value.)
20 As in the first program example, locations 52 and 56 change
the pointers to the top address of available RAM memory.
A value of 28 takes 512 bytes of memory from BASIC, just
enough for the data for the 64 characters you are moving to
RAM. This line also protects the character memory from
BASIC.
30 This line may look complicated, but actually it's not. The
VIC is told to look at the data numbers for the first 64 char
acters in ROM (32768 to 33280), look at what's there
(PEEK(I + 25600)), and then POKE those same numbers
into locations beginning at 7168 and ending at 7679. In
other words, the first 64 characters have been copied from
their ROM locations to your new RAM location. The
number 25600 is 32768 minus 7168. Another way of doing
this would be:
30 FORX =0 to 511:POKE 7168 +X, PEEK(32768 +X): NEXT
After you run Program 4-2, you'll notice several things. First
of all, the flashing cursor is lost. Second, only the first 64 char
acters are available. If you copied all 512 characters in the VIC, two
kilobytes of RAM would be used up. Since you will rarely need
more than a dozen custom characters, 64 is usually enough to
give you custom characters and all the letters and numerals.
Try pressing random keys and see what happens. You'll see
that the characters with screen codes from 0 to 63 (refer to the
screen code tables in your reference guide) are available. These are
the characters from the @ character to the ? character. If you press
SHIFT and then another key, you'll often get garbage that means
nothing to you. Continue to press keys and then sit back and
watch. Some of the characters are changing before your eyes.
What is happening here is that the VIC thinks character
memory is 2K, or 256 characters, even if you use only 64. When
you press keys that call for characters with screen codes greater
70
4
Custom
Characters
than 63, the VIC reads their patterns from screen memory, so that
the numbers stored there become patterns of the graphics char
acters. Your screen display is creating itself.
Now that your have the character set moved to RAM, avail
able for altering, and protected from BASIC, you can begin to
place your own custom characters in this set.
I Replacing Characters
Glance through the screen code table in either your Program
mer's Reference Guide or your VIC-20 User's Guide for a moment.
Remembering that the first 64 characters are available, decide
which of these you'll need for your game. How many of the letters
will you need for screen titles and other game indicators? If you
have the title "Lunar Lander" on the screen, as well as 'Time"
and "Fuel," you would not replace any of those letter characters
with your new custom characters.
You should make up a data sheet, using the blank provided
by Figure 4-7, to simplify the process of deciding which characters
to save and which to change to custom characters.
In the left columns, list the first 64 characters, then their
screen code values. You can find these values in the screen code
tables in your reference guide. The starting location can be found
by multiplying the screen code value by 8 and adding that to 7168,
the starting location. This gives you the starting location of each
character's eight bytes of data. The next column can be filled in
with the name of the new character, such as "Running figure,"
which will replace the old character of that row. If you wanted to
replace the @ sign with this new custom character, then write the
name in the first row. Next to this, list the eight data numbers for
the new character. In this example, the data numbers would read
24,24,18,124,88,20,100,0.
All this will take time, but it will be a valuable reference later
in your game designing and programming.
Now you're ready to actually replace certain characters with
your new custom characters. What you need to do is POKE your
new numbers where the old values are. The data sheet will make
this job easier, for it details the starting locations of each character,
as well as the new values.
As stated earlier, the most convenient way to replace the old
characters is with DATA and READ statements. You can put all the
numbers into the DATA statements and then have the VIC READ
71
4
Custom
Characters
72
4
Custom
Characters
them. The computer always READs the data in the order that it's
listed, so make sure the numbers are in the proper order, and that
there are eight numbers for each character. The DATA statements
can be anywhere in the program, and for this reason many pro
grammers put them at the end of the program, out of harm's way.
The standard format is:
FOR C(new character) =X to X +7:READ D:POKE C,D:NEXT
where X is the starting location of the new character from the data
sheet.
For example, if you wanted to replace the @ character with
the running figure, you would list it like this:
Using this same format, you can replace characters with your
own set of custom characters. Make sure you insert your data
numbers in the proper locations for all the replacements.
If your new characters are replacing old ones which are right
after each other in the screen code table, you can place more than
one in a READ statement. Figure 4-8 is a character data sheet for
five characters which can replace sequential characters in the
standard set.
Notice that two of the figures are split between two 8x8
squares. One is split between two squares horizontally, the other
is split between two vertically. When both 8x8 squares are
printed on the screen, the figure will appear complete.
To POKE all five figures, and READ all seven DAIA state
ments that make up those figures, you could write:
73
4
Custom
Characters
Running
! 33 7432 Figure #1 24,24,18,124,88,20,100,0
Running
34 7440 Figure #2 Lft 1,1,1,3,6,1,3,0
Running 128,128,32,224,128,
# 35 7448 Figure #2 Rt 64,32,0
Squatting
$ 36 7456 Figure 0,56,56,16,124,16,124,68
Rising
% 37 7464 Figure 56,56,16,124,16,124,68,68
Jumping
& 38 7472 Figure Top 0,0,0,56,56,84,124,16
Jumping
39 7480 Figure Bot. 56,40,40,0,0,0,0,0
74
4
Custom
Characters
The number displayed is the number of bytes available for the rest
of your program.
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
Getting Your
Figures
Moving
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
5
Getting Your
Figures Moving
Movement on the television screen is a series of still pictures.
They seem to move because each still picture is only slightly
changed from the one before, and each new picture comes on
the screen so quickly that the eye can't see the jump from one to
the next.
I Speed
Movies change their image 24 times per second — any slower,
and you begin to see flickering.
But the raster scan in your television refreshes the screen
image 60 times per second. That's almost four times faster than
the minimum for smooth animation. If you're programming in
machine language, that leaves you plenty of room to perform all
your calculations and still change the screen image often enough
to have smooth movement. In fact, most machine language
games have to insert delay loops or timing routines to slow them
down so you can see what's happening on the screen.
That's why, in arcade games, no matter how fast the game
goes, it can always go faster when you get to the next level. Even
when the computer is controlling dozens of figures on the screen
at the same time, it is probably marking time to stay slow enough
for you to play it.
Unfortunately, BASIC calculations are slower (but a lot easier
to program) than machine language calculations. It's sometimes
hard to perform all the calculations you need fast enough for
animation to be smooth. You need to make sure that your pro
gram performs as few calculations as possible between move
ments on the screen, or your game will run slower and slower
and slower.
79
5
Getting Your
Figures Moving
Even in BASIC, this program is so fast you can hardly follow the
movement, and your eyes probably fool you into seeing several
characters in a row instead of just one. So let's add a delay loop to
slow it down:
40 FOR X=0 TO 84:NEXT:NEXT:POKE 1-1,32:GOTO 20
80
5
Getting Your
Figures Moving
movement, and by the time you execute it, things have slowed
down enough that most of the gain in smoothness has been elim
inated. In machine language, of course, the speed problem is
eliminated, and smooth movement is relatively easy For our pur
poses right now, however, the direct character movement is good
enough.
81
5
Getting Your
Figures Moving
82
5
Getting Your
Figures Moving
Notice that this time we ANDed the value at 653 with 3; this was
just to make sure that if the CTRL key was accidentally pressed,
it wouldn't force a leftward movement, too, since the value at 653
will always be 4 or greater if CTRL is pressed.
Ifs just as easy to read the values at location 197. Let's read f5
83
Getting Your
Figures Moving
3 34 c
2 5 35 B
3 7 36 M
4 9 37
5 39 fl
6 £ 41 S
7 DEL 42 F
8 {left arrow} 43 H
9 W 44 K
10 R 45 :
11 Y 46 =
12 I 47 f3
13 P 48 Q
14 49 E
15 RETURN 50 T
17 A 51 U
18 D 52 O
19 G 53 @
20 J 54 {up arrow}
21 L 55. f5
22 56 2
23 {cursor left-right} 57 4
24 RUN-STOP 58 6
26 X 59 8
27 V 60 0
28 N 61 -
29 62 CLR/HOME
30 63 f7
31 {cursor up-down} 64 {No key pressed}
32 {space bar }
The following key codes cannot occur: 16,25,38,40.
84
5
Getting Your
Figures Moving
85
5
Getting Your
Figures Moving
Line Function
5 Set up the string array V$( n), in which each value of V$
PRINTs HOME and the same number of CURSOR-
DOWN characters as the subscript. In other words,
V$(10) PRINTS HOME and ten CURSOR-DOWN char
acters; V$(0) PRINTs HOME and no CURSOR-DOWN
characters.
10 The same as line 10 in Program 5-2, POKE Movement.
15 Set the string FG$ to the character that will be the figure
PRINTed on the screen. Set NV to the row and NH to
87
5
Getting Your
Figures Moving
89
5
Getting Your
Figures Moving
90
5
Getting Your
Figures Moving
91
5
Getting Your
Figures Moving
the problem, but it also stops your program. The best solution is
92
5
Getting Your
Figures Moving
93
5
Getting Your
Figures Moving
I Animation
Animation — making figures move smoothly and naturally — is
tedious to program and hard to do in BASIC. However, it can
make a great difference in the way your game affects players. The
more real the game world seems, the more intriguing it is to
watch, and the more fun the game is to play.
The movement routines we've used so far have given fairly
good movement, but to make the motion smooth, and especially
to give a lifelike quality to figures, you'll need redefined char
acters. Remember Mario in Donkey Kong? Each different position
he gets into is another character.
Animation in Place
The easiest sort of animation is movement within a single char
acter. This is done by POKEing or PRINTing different characters
in the same location on the screen. If the characters differ only
slightly from each other, the resulting figure will seem to be mov
ing in place. You might try this:
94
5
Getting Your
Figures Moving
If you'd like to see all these at once, change lines 30,40, and 50:
10 SC=256*PEEK(648):POKE 36879,8:PRINT "{CLR}":X=1
20 DIM N(40):FOR 1=1 TO 40:READ N(l):NEXT
30 X=X+1:IF X>4 THEN X=l
40 FOR T=0 TO 36 STEP 4:POKE SC+10+T*11,N(X+T):NEX
T
50 FOR 1=0 TO 20:NEXT:GOTO 30
100 DATA 123,126,124,108
110 DATA 76,79,80,122
120 DATA 73,75,74,85
130 DATA 115,114,107,113
140 DATA 71 ,66,72,103
150 DATA 103,77,100,100
160 DATA 100,111,121,98
170 DATA 73,93,85,93
180 DATA 126,97,127,226
190 DATA 95,160,223,32
95
5
G6ttln0 Your
Figures Moving
If we checked for player input only once in each cycle, this pro
gram would run faster and be easier to write, but the response to
the player's input would be much slower. Machine language
could do the same thing so fast you could hardly see what was
going on. This is one area where, even though the programming
can be done in BASIC, it just isn't worth the effort to get such
detailed animation.
All these demonstrations have used the abstract built-in
graphics characters. Here's a program that shows how to make
your VIC produce more humanlike motion. We'll use the char
acters we designed in Chapter 4 to create a running and jumping
athlete. To make the athlete run, press the CURSOR LEFT/RIGHT
96
5
Getting Your
Figures Moving
97
5
Getting Your
Figures Moving
The run subroutine at line 200 is the most complex part of the
program, since the figure must not only be PRINTed, but must
also wrap around when it reaches the end of the line. The delay
loops (FOR X=0 TO T:NEXT) are present to show how you can
change the smoothness and speed for different effects. By chang
ing the value assigned to T in line 50, you can make the runner's
movement slower but make the individual steps clearer, or you
can speed up the figure to a virtual blur. The value shown here,
130, emphasizes the individual steps. A value of zero will of
course be much faster.
The jump subroutine at line 250 is much simpler; even
though jumping requires five steps (FOR I=2 TO 6), jumping
never has to wrap around the end of a line.
The character set routine at line 900 is the one we used in
Chapter 4 to set up the athlete characters.
If you want to devote the programming time and have the
computer memory to do it, you could add many other intermedi
ate characters to get far more fluid, lifelike motion. Ifs a trade-off.
Especially when you're programming in BASIC, every feature
you decide to add will cost you something somewhere else. To get
speed, you must keep your figures small and your motions fairly
jerky. To get large, detailed figures, you must sacrifice speed,
memory, and smoothness. To get natural-looking animation, you
must give up speed and memory. It should always be decided on
the basis of what is more important for the game. Some games
need animation; with many others it would add nothing.
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
6
CoHsions
When Pac-Man eats dots, points get added to the score and the
dot disappears; when he eats a power dot, the ghosts change
color for a while. When Pac-Man touches a ghost, he dies —
unless he recently ate a power dot. Most of the things that hap
pen in a videogame happen because something on the screen
bumped into something else.
There are other things that can cause changes. In Donkey
Kong, for instance, if it takes you too long to get to the top of the
screen, you run out of time and Mario wipes out. In most games,
if your score reaches a certain level, you get a bonus player-figure,
an extra turn. But these are exceptions: the overwhelming
majority of events are caused by collisions.
101
6
Collisions
Line Function
10-90 This is the program initialization handler. Since pro
grams always start running at the lowest-numbered line,
you always have to have at least one initialization line at
the beginning of the program, even if all it does is say
GOTO 1000, where the real initialization takes place. You
might notice that this section ends with line 90, but there
are no line numbers from 30 to 90. This is so more initial
ization routines can be added later, either with a few
commands or a GOSUB to a more complex routine.
10 Set SC at the start of screen memory and CM at the start
of color memory. GOSUB 500 to draw the screen.
20 Set FG to the screen code of the character that will serve
as our spaceship figure — in this case, the diamond
shape. Set OC to the current color memory value (white)
and NC (new color) to the color of the spaceship, green.
30 Disable character set switching.
90 Go to the end of the movement loop to draw the space
ship on the screen and then wait for the player's
instructions.
100-190 This is the main loop of the program. Any command in
this section of the program will be executed every time
the program passes through the loop, whether the
player has called for movement or not. Opponents'
movements, timing, display changes, and so forth are all
controlled through this loop. As before, there is plenty of
space left for more lines.
100 Set A to show whether SHIFT or Commodore is
pressed. Set B to show if any other key has been pressed.
102
6
Collisions
103
6
Collisions
ship's color from red to cyan, purple, green, blue, and yellow.
Every time the ship collides with a nova (large star), the
player wins points, and the nova, all its important gases stripped
away, appears on the screen as a small star.
A new element will be introduced — a space station, which
will be a red checkerboard square (screen code 102). The space
ship changes back to red when it collides with the space station,
but gets no additional points. After a while, the spaceship gets
out into deep space and the space stations stop appearing.
When the spaceship moves onto a small star or the space sta
tion, the program must "pick up" the star and then put it back
when the spaceship leaves. With the novas, however, since the
spaceship has picked up all the gases surrounding them, the pro
gram will put a small star in their place when the spaceship
moves away.
104
6
Collisions
the bottom of the screen, and the VIC automatically makes our
scrolling display.
Creating new lines of random stars. One of the problems
now is to create those new lines of stars to PRINT at the bottom of
the screen. They have to be random, and yet they have to appear
almost instantly in order not to slow down the game.
The solution is to create one long string, 255 characters long,
which contains a random assortment of blanks, small stars, and
novas. Then, using the MID$ function, we can choose a segment
of that string to PRINT each time we need a new line of stars. By
generating a random number for the starting position of the
string segment, we can still keep up the randomness — but we
have to generate only one random number each time we scroll,
and then the built-in machine language MID$ function and
PRINT command will take care of the rest. There we have it —
machine language speed in a BASIC program.
105
6
Collisions
Line Function
10-90 Initialization. Most variables are assigned their starting
value here.
Variables Used
SC = starting address of screen memory
CM = starting address of color memory
FG = screen code of the character used for the player-figure
OC = the original color of every square in color memory
NC = the current color of the player-figure
Q = the difficulty level. This starts at 3, then decreases steadily
throughout the game.
QQ = the original difficulty level +1; Q is subtracted from QQ
several times during the game to set certain values that
must get larger rather than smaller as the game gets
harder.
NH = the new horizontal position (column number) of the
player-figure
NV = the new vertical position (row number) of the player-
figure
OH = the old horizontal position of the player-figure
OV=the old vertical position of the player-figure
C = the number of bytes to add to SC and CM to find the
player-figure's current location in memory
106
6
collisions
Subroutines Called
GOSUB 400 sets up the long random string that will create the
new lines added to the bottom of the screen.
GOSUB 500 sets up the screen display.
GOSUB 800 initializes the timer function that controls how
often the screen will scroll.
100-190 Main loop. Everything that happens constantly, whether
the player moves the player-figure or not, is controlled in
this section.
100 Set A and B to show what keys, if any, are pressed.
110 Check the timer to see if it's time to scroll the screen.
(The variable H$ is automatically changed by the operat
ing system to show how much time has passed since it
was last set to equal 0. If you don't know how to use H$
and can't figure it out from this line and the subroutine
at 800, see Programmer's Reference Guide to the VIC.) If it
is, jump to the scroll routine at 600.
111-189 Open lines, where other routines can be added.
190 Set H and V to equal the horizontal and vertical move
ment called for by the player. If no movement is called
for, go back to line 100.
200-290 Movement loop. This is where player movement is carried
out, along with any other routines that happen only
when the player moves.
200-210 Set NH and NV to the new player-figure location.
220 Set the old player-figure location back to its previous
values. POKE color memory with the nonplayer-figure
color, OC, and POKE screen memory with W, the char
acter that should be left behind when the player leaves
that spot. Then set C to equal the new player-figure off
set, and set Wto equal the character currently stored at
the new location.
230 If the character stored at the new location is something
other than a blank (32), go to the collision routine at line
700.
107
6
Collisions
108
6
Collisions
620 PRINT the updated score at the top of the screen. Notice
that the program PRINTs STR$(P) instead of simply
PRINTing P. This is because the VIC automatically skips
a space after PRINTing numeric variables. If a number
was already in that space, it will be left there, which
makes the score inaccurate if the number of digits in the
score changes. Perhaps the best way to see how this
works is to change the statement to PRINT
" {HOME }"1AB(8)F' POINTS " and see what
happens.
630 Add one to the Space Station Timer (TS); depending on
the difficulty level, if TS is beyond the limit, jump to the
space station routine at line 850.
700-730 Collision routine. There are four possible collisions.
If the spaceship has collided with a small star (46),
the score (P) is decreased by 100, and NC, the space
ship's color, is increased by one.
If the spaceship has collided with a new space sta
tion (102), NC, the spaceship's color, is set back to 2.
Then W is set to 104, a "used" space station, so that it
can't be used again.
If the spaceship has collided with a used space sta
tion (104), nothing happens.
If the spaceship has collided with a nova (the only
other possibility), the score is increased, with greater in
creases at the higher difficulty levels and at lower posi
tions on the screen. W is then set to 46, a small star, so
that it becomes another obstacle to the spaceship.
800 Timer reset routine. The variable 11$ is set back to 000000,
which starts it over again. Also, the difficulty level Q is
set to a slightly lower number. To make the game get
harder faster, change the 99 to a lower number; to make
it stay easy longer, change the 99 to 99.5 or 99.8 — any
number greater than 99 but less than 100.
850 Space station routine. This one-line subroutine puts a
space station in a random location on the bottom line of
the screen and sets its color to red.
900 End routine. This routine makes the spaceship flash
through the colors, prints the final score, and exits the
game.
109
6
Collisions
I star-Eater
I Here's a simple gobble game. You are a hungry dot, out to eat
stars (asterisks). You get points for eating them. The trouble is,
each one you eat turns into a plus — and if you accidentally eat a
plus, you lose points. Also, every plus you eat turns into a block of
stone, which you can't get past. Your task is to eat as many stars as
you can before time runs out. You can wrap around the screen
both horizontally and vertically; left-right movement is done with
the SHIFT and Commodore keys, and up-down movement is
done with f5 and f7.
With what you already know about game programming, you
should have little trouble figuring out exactly what's going on.
lines 0-99 are initialization; lines 100-199 are the main loop; lines
200-299 are the movement loop; lines 300-399 are the end routine;
lines 600-699 are the set level subroutine; and lines 700-799 are the
collision routine. It is all familiar ground.
Let me just call your attention to a few details.
Notice the variable M. During initialization, it is set to the
total number of stars on the screen by adding 1 to M each time a
star is POKEd to the screen (that is, each time the random num
ber X is a 3). Then, during the collision routine, M is decreased
by 1 each time the player eats a star. This means that when the last
star is eaten, M will equal zero — and that is one of the conditions
that will end the game. Upon entering the end routine at line 300,
you get different messages, depending on whether or not you ate
all the stars.
Another new feature is the choice of levels. At the beginning
of the game, you are asked what level you want. This is accom
plished in the subroutine starting at line 600. If you choose "easy,"
the variable N is set to 300; 200 if you choose "hard"; and 100 if
you choose "superhuman."
Notice how this variable is used throughout the program. In
the Collision Routine, the score is added toby an amount equal to
N minus the current value of the timer (11$), but when the player
eats a plus, the score is subtracted from by an amount equal to TI$.
That means that the later you get in the game, the fewer points
you get for each star you eat, and the more points you lose for
each plus you eat.
Also, the TIME message at the top of the screen (see line 100)
tells you how much time you have left. The countdown is created
by subtracting TI$ from N. And if you don't eat all the stars before
no
6
Collisions
the timer reaches the value of N, the game ends — with a dif
ferent message at line 300.
111
6
Collisions
720 P=P+INT(N-VAL(TI$))zW=CH(2):OC=CL(2):M=M-l:RET
URN
730 NH=OH:NV=OV:FL=OH+OV* 2 2:W=E:OC=PEEK(FL+CM):RET
URN
3345 IF B=ll THEN RUN
Collision Tracking
So far we have only used PEEKs to see whether a collision is tak
ing place. There is a good reason for this. Most of the time, you
will be creating games where there are random elements, things
on the screen that your program won't be keeping track of.
There'll be no way for the computer to know there's been a colli
sion without PEEKing.
In some games, however, the only things on the playfield be
sides the player-figure will be computer-controlled figures, and
your program will therefore be keeping track of the location of
every single item on the screen. Then you can find out about colli
sions by comparing the locations of the various items. The game
//Moonraker," Program 10-3, uses this method. But it only works
when there are few figures on the screen and no possibility of
random items to run into.
112
6
Collisions
how much time you had left when you got the spark off the wire.
As you examine the program, youll see that the spark never
exists in screen memory at all — it is only POKEd into color mem
ory. But the spark's movement routine in the main loop from lines
100 to 190 PEEKs into screen memory in order to see in what
direction it is supposed to go next. Using PRINT for screen
changes gives this game machine language speed in its response
to the player's keyboard input. This method won't work for all
programs, of course, but for this one, the computer is running a
fairly fast-moving figure through a fairly complex movement pat
tern, all in BASIC. If you program carefully enough, you can get
real speed in BASIC games.
113
6
Collisions
114
Sounds
and Music
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
7
Sounds and
Music
Just how important is sound in a videogame? Try playing a fa
vorite game with the sound turned off. You'll be amazed at
how much you'll miss the various tones, noises, and melodies
that you are accustomed to hearing while you play the game. Your
timing will probably be off, your score will be lower, and most
important, you won't enjoy the game as much. Why?
I uses of Sound
Sounds help you while you play a videogame by providing feed
back of your game actions. As you play Joust, for example, there
are sounds which give you information on almost every event
that occurs. A collision in which you defeat the other knight is dif
ferent from one in which you are defeated. Colliding with dif
ferent surfaces results in different sounds. When you receive a
bonus knight, there is yet another sound. These sounds aid you
as you play, for as you concentrate on keeping your own knight
alive, the sounds tell you what's going on elsewhere on the
screen. Vac-Man also provides sounds as information, although
to a lesser degree. Each dot that is eaten, and thus each point that
is awarded, produces a sound. You know you are gaining points
without having to actually look to check. When a power dot is
eaten, another sound is made which signals that ghosts can now
be chased. Sound as information is a valuable aid in a game.
Sounds also affect your mood as you play, drawing you into
the game's unique world. Imagine the loss you feel when your
Pac-Man is caught by one of the ghosts and the short "Sorry"
sound routine plays. The fierce stamping sounds at the opening
of Donkey Kong only urge you on to the top. Never mind the anger
of the ape, you tell yourself. Part of this mood is generated by the
pace of the sounds and music.
One of the most successful arcade games, Space Invaders, uses
a repetitive sound as the aliens move across the screen. As their
numbers decrease, the sounds become louder and faster. The
effect is one of increasing excitement and anxiety.
117
7
Sounds
and Music
I Creating sounds
The VIC creates sounds by addressing five memory locations,
called sound registers. The sound output is created and con
trolled by POKEing values to these memory locations. The
memory locations and corresponding sound registers are:
118
7
sounds
and Music
produce a sound. You also must set one or more of the tone regis
ters for sound to be created.
There are numerous sources for small routines that duplicate
various sounds or sound effects. One such source is Personal Com
puting on the VLC-20, the manual that came with your computer.
Appendix G in the back of the manual has a number of sound
effects already worked out. In COMPUTED Second Book of VIC,
John Heilborn's article, "Making Sound with Blips/7 shows you
how to do really convincing sound effects and includes some
excellent examples. Such prewritten routines are useful if you
experiment with them, changing values or adding time delays to
slow the sounds down.
The two following routines can be used in just this way. Type
each in and save, so you can later load them for alteration.
119
7
Sounds
and Music
PTOgran17-2. Blip
100 POKE VI, 15
110 FOR Bl=l TO 5
120 FOR B2=250 TO 240
130 POKE H1,B2
140 NEXT B2
150 POKE H1,0
160 NEXT Bl
170 POKE VI, 0
Program Explanation
Line Function
10 Create a dark, cleared screen
120
7
sounds
and Music
With this one simple program, you can quickly see several
different applications and create varying effects, just by altering a
line or two. For example, by changing line 50 to:
50 POKE HI,Y:FOR T=0 TO 1:NEXT:NEXT Y
you will create a slight delay after each of the sound increments.
Changing it to read T = 0 TO 1000 will separate the notes even
more. Can you think of an application in a game (preferably your
own)?
Change line 50 back to its original state and then alter line 40
to read:
40 FOR Y=128 TO 255 STEP 2
This new program will keep running until you hit the RUN/
STOP key. At that point you'll hear another tone which you can
stop only by pressing the RUN/STOP key along with the RESTORE
key. This resets the volume value to zero.
The sound made by this program is a type of noise often
made by games using spacecraft, such as a UFO. To get even
121
7
Sounds
and Music
closer to such a sound, change both 128 values to 240. A good Pac-
Man imitation can be obtained by changing the value in line 40
from 128 to 210.
You'll notice that most of the changes made were in the lines
containing the FOR-NEXT loops. These loops are essential in
most sound effects, and you should be familiar with this com
mand's operation before you attempt to write any detailed sound
effects routines. Once you are comfortable with the format of a
sound routine, you should be able to create almost any sound you
want.
You now have the background needed to create sound effects.
What do you do with them? Place them in a game program, your
game program.
I Background Sound
One possible use for sound or music in a game program is as
background, which can be useful as a mood producer. Remember
the importance of sound in affecting the mood of a player during
a game. It is important, and your game will certainly be better for
its inclusion. Although the music you choose for your game will
probably be different from the following example, once youVe
looked through this section, you should be able to apply its
techniques.
If you want this sound to be continuous throughout your
game, the routine will have to be included as part of the main
loop of the game program. If you want a high-pitched drone that
alternates between two pitches during the game, for example,
you might set up something like this:
122
7
sounds
and Music
I Sound Subroutines
I Many sounds in a game will not occur throughout the entire
game program, but will instead be heard only at the time of a cer
tain event. The music which plays when a game character is lost,
for example, would fit in this category. Perhaps you want sound
when the fire button on the joystick is pressed, or a loud tone
from the noise register when a target is hit. In these situations,
the sounds are called upon as subroutines.
Unfortunately, when a program goes to a subroutine, it leaves
123
7
Sounds
and Music
the main loop and everything comes to a stop until the program
returns. Sometimes this is very noticeable, for you can see the
characters on the screen stop as a noise or sound is executed by
the subroutine. Although this is a drawback, it is often used be
cause of the complexity of incorporating a sound routine into the
main program loop. Many programmers use the subroutine tech
nique since it is relatively simple to program. Perhaps in some
games the visual delay will not be as noticeable. As the game
designer and programmer, you must make the decision. Will the
delay harm the overall game execution? Will it lessen the player's
enjoyment of the game? If you think not, try the subroutine
technique.
The following example program uses a subroutine to access
the sound only when it is called for. A character moves back and
forth on the screen, which also displays a time clock. Every five
seconds the sound subroutine is called, and you will see the char
acter stop as the routine is performed.
Program Explanation
Line Function
10 Volume control is set to maximum, and the screen is
124
7
sounds
and Music
125
7
Sounds
and Music
INo-stop Subroutines
Although adding sound to your game by using subroutines does
stop the action for a short moment, it is a simple way to program.
Some games, however, would benefit from having sound which
does not cause the game action to stop. It is more difficult to add
sound using this technique, but it is often preferable to using sub
routines which halt a character every time they are executed.
Remember that each time a routine is added into a program's
main loop, the game action will slow down. Sometimes this will
have little or no effect on the game's appearance and play. Other
times it will be noticeable. Again, as game designer and program
mer, you must make the decision.
The example program which follows uses this subroutine
technique. The sound executes without stopping the game
action, and in fact is heard only when the two characters on the
126
7
sounds
and Music
Program Explanation
Line Function
10 This program starts out much like the other examples in
this chapter. The screen is changed, and the volume is
set to the maximum level of 15.
20 Variables are set as follows:
L = starting location of randomly moving character
M = starting location of user-controlled character
H = POKE value for the random character
S =POKE value for a character space to erase any
previous images of moving characters
P=POKE value for user-controlled character
X = sound register value
N = tone value of the sound register. Note that this starts
127
7
Sounds
and Music
128
7
Sounds
and Music
129
7
Sounds
and Music
130
7
sounds
and Music
131
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
introductions,
instructions,
and Farewells
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
8
introductions,
instructions,
and Farewells
Introductions, instructions, and farewells add an element that
every player appreciates, another dimension to the game world
youVe created. Just like sound effects or custom characters,
they are not absolutely necessary, but without them your game
will seem pale and one-dimensional. Introductions and farew<ells
make the game more interesting, entertaining a player while a
screen display is set up, or providing incentive to play again for a
higher score at game's end. Without instructions, a player could
be confused or frustrated at the outset while trying to discover
cursor directions, scoring procedures, or the goals of the game.
Even though introductions and instructions appear at the
opening of a game, this part of game design is best approached
after your program has been written. It is only then that you know
the amount of remaining memory available for these extras.
Through the constant changing and revising of your program, it
is probably not until this point that you know exactly how your
game will appear. Of course, there are exceptions, for you may
have your design well-outlined before you begin to program.
I Memory
After your program is completed, and before the introductions
and instructions are written, you have to find out how much
memory is still available. This is important with the unexpanded
VIC, for its 3583 available bytes can be quickly used in a program
with a custom character set, sound effects, and animation. It is
little use to create a complex introduction, with involved music
and graphics, if it will not run because of memory limitations. At
times you'll be forced to use every available byte, for you may
have only several hundred bytes left after the program. You need
an accurate idea of what you have to work with.
After you have your program written and loaded, use the
135
8
introductions, instructions,
and Farewells
I introductions
Introductions can take many forms and shapes. Perhaps you
want another sound effect, or a short piece of music, to entertain
the players while they wait for the game screen to set up. If the
memory is available, a brief description of the game situation can
be inserted. This can heighten the player's involvement in the
world youVe created. At the very least, you'll want to display the
title before the game begins.
Since you've already written your program, you probably
won't be able to place the introduction at the beginning without
renumbering the entire program. A simple way to solve this prob
lem is to place the introduction in a subroutine that is called by
the first line of the program. In the sample game from Chapter 6,
Mission: Nova!, it would look like this:
5GOSUB1300
The program would then move to the subroutine and execute the
introduction, returning to the opening of the program. The fol
lowing example subroutine can be inserted into the Mission:
Nova! program to serve as an introduction.
136
8
introductions, instructions,
and Farewells
would print the line one column from the left, in the second col
umn. You could replace line 1310 in the sample subroutine with
this line, for instance.
Although you have only one screen so far, often you'll use a
lengthy introduction, with several screens of print. Instead of
scrolling the introduction or printing it one line at a time at a slow
speed, it may be easier to display each screen full of print
separately. At the end of each screen, as in Program 8-1, you could
add the line:
followed by:
137
8
introductions, instructions,
and Farewells
will display the next screen. At the end of the PRINT statements
for the last screen, be sure to include a RETURN command.
Our sample subroutine takes up only one screen so far. If that
is all you're using, to return to the game program you need only
add a line such as this:
1346 FOR 11 =0 TO 5000:NEXT:RETURN
I instructions
Depending on the memory still left, you may be restricted to
using a short introduction in order to include instructions. Of the
two, the instructions are more important to the player's under
standing of the game. At the very least, you'll want to tell the
player how to move user-controlled characters. If it's a joystick-
controlled game, a note that a joystick is needed would be suffi
cient. If the keyboard is used to control the character, more expla
nation is necessary.
If the keys are not next to each other, this may be the best way
to tell the player which keys move the character each direction.
Note that the GET A$ statement is used again to hold the screen
138
8
introductions, instn ctlons,
and Farewells
H or
V /
139
8
introductions, instructions,
and Farewells
Setting Difficulty
At times, you'll want to allow the player to set the level of diffi
culty in the game. If your game lends itself to this, a player can be
gin at the easiest level and progress to the more difficult. A game
such as Tempest, which lets the player choose the starting level, is
a good example. It will seem that there are actually several games
in one if the levels are considerably different. An ideal place to do
this is in the instructions, before the game begins. The INPUT or
INPUT #1 commands can be used to do this.
Again, a subroutine called at the program's outset is one way
to do this. The game "Spark" from Chapter 6 is one in which
levels could be set using the statement:
5CLR:GOSUB800
and the following subroutine:
140
8
introductions, instructions,
and Farewells
Line Function
800 Clear the screen and POKE in a screen color change.
810-850 Print the instructions for setting the different levels of
play. Note the [control] [blue] keystroke in line 810. This
sets the character color back to blue. The program will
alter the character color after it has run once if this is
omitted.
860 Used to create the INPUT #1 command in the next line so
that a ? prompt will not appear on the screen.
870 The INPUT #1 command delays the program until the
player provides a response. This command is very useful
when asking for information from the player. The
CLOSE #1,0 statement completes the instruction begun
in line 860.
880-900 Test for the number pressed by the player, and then set
the value of P accordingly. P is the time remaining before
the game ends. In other words, the most difficult level
begins with less time for the player to complete the
game. Notice that each line has a RETURN statement at
its end. The program then moves back to line 5, and the
game program begins setting up its screen.
I Farewells
Assuming that memory is available, the final addition to your
game should be a farewell, or end routine. As with the introduc
tions and instructions, this can be as elaborate or simple as you
want. Some farewells are strictly entertaining, nudging the player
back into the game, persuading the player to try it again, perhaps
just to see the end routine. Other farewells are more informative,
giving the final score, showing a high score, ranking the player, or
asking if another game is wanted. Just as with the introductions
and instructions, you can insert this as a subroutine.
A simple farewell, which records the final score, prints a
short message, and allows the player to begin a new game, would
take only a few lines in a program. In the example game Spark,
the score was assigned the variable P in the program. If the player
141
8
introductions, instructions,
and Farewells
won, the user-controlled character exited the maze, and the game
was over. Running out of time caused P to equal 0, and so ended
the game. There were only two possible ways to end. Placing a
GOTO command at both program lines could be done this way:
170 IF CHG < 4 THEN GOTO 610
and
When the character exits the maze, then, the program shifts
to line 610. If the player loses the game by running out of time, the
program goes to line 600. At that point, the following routine
could be used:
Line Function
600 Print the message that the player ran out of time and
scored 0 points. The first PRINT command is used to
force the message to print below the maze. Program
then shifts to line 620.
610 If P > 0, then the player has won and this message is
printed on the screen, along with the final score.
620 Drop two lines to display the message allowing the
player to try again.
625 This POKE is necessary to clear the keyboard buffer of
any characters typed in during the preceding game. If
this is omitted, the next line will execute immediately, for
the VIC will read the buffer and assume a key was
pressed for line 630.
630 GET A$ simply waits for a key to be pressed by the
player before continuing.
640 Return the program to the beginning. Notice that the
player is returned to the level-setting routine, so that the
level of difficulty can be changed.
142
8
introductions, instructions,
and Farewells
Line Function
900 Set the volume register to maximum.
910 The values in the READ statement are set and the space
ship is flashed by the POKE CM + C,X. IF Nl = 0 (the
sound register is then turned off), the music ends and
the program shifts to line 930.
920 POKEs the high tone register with the values in the
DAIA statement in line 950, and holds the tones at vary
ing lengths (El = 1 TO 150*Dl). The program then moves
back to line 910 to READ the next values in the DAIA
statement.
930 Print final score and ask the player whether another
game is to be played.
940 The delay allows the player time to decide if he or she
wants to play another game. If so, the PEEK command
reads the keyboard and sends the program to the appro
priate lines. If another game is not wanted, the program
will end in line 945 after the delay.
950 The DAIA statement creates the dirge music which plays
at the end of a game.
143
8
introductions, instructions,
and Farewells
I Design Notes
Programming introductions, instructions, and farewells can be
challenging and exciting, for each addition to your game will
make it that much more professional in appearance, as well as
more playable and entertaining. As long as the memory is avail
able, use it to your advantage to enhance your game. Although
we've considered a number of different concepts to include in
your game introductions, instructions and farewells, there are a
few more suggestions for your use.
Be personal. If the player is asked to INPUT his or her name
and then sees it printed in the instructions, or even beside the
user-controlled character, the player will be drawn deeper into the
game's world. Within the farewell, the player's name could also
be printed alongside the final score. These human touches add to
any game, as you've probably noticed when you've played video
arcade games.
Make use of the color abilities of the VIC. Changing screen
colors certainly adds to the game, but reversed or colored char
acters will add even more, especially in the introduction and in
structions. With memory available, you can alter the screen and
character colors with every new screen display.
Urge the player to play another game by including a friendly
ending. It doesn't have to be something cute, just enough to make
another game worth the time. Proclaim the player's victory, hand
out promotions or rankings. Your imagination as the game de
signer can come into play here. Creativity is what makes one
game stand above all others.
Your game program is almost completed. You've gone from
the idea to writing the end routine. There are a few more things to
consider, however, in the next chapters.
144
The Shape
of the Came
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
9
The Shape of
the Game
We've gone through most of the techniques you'll need to
create your own games. Now all you really need to do is hack
through the actual programming. The word "hack" is pretty
accurate for most of our programming. No matter how logical you
are, chances are pretty good that the computer is even more logi
cal, and you'll write many a routine that should work — but
doesn't. At least I certainly program that way sometimes, like a
clumsy woodcutter taking one hack after another until finally he
splits the log.
And it works. Eventually, even the most stubborn program
ming problem will yield to your constant work.
There are ways you can make things easier for yourself, and
in the meantime make your programs run as smoothly and
quickly as possible. However, the programming techniques in
this chapter are not "rules" — the/re just advice. Good advice, I
think, that has helped me in my programming, but remember:
any game that plays well is a good game, even if the programming
isn't pretty. So don't be concerned if you fudge a bit here and
there. If it works, it's correct.
I Program structure
In most of the programs in this book, I've tried to structure my
code with three purposes in mind:
1. Make it easy to understand.
2. Make it run fast.
3. Use up the least possible memory.
Ease of understanding
Why should you make your programs easy to follow? After all,
you're writing a game for yourself, not example programs in a
book. Nobody's ever going to see your programming, just the
results.
There's one exception. You.
You will look at your program again and again. Sometimes
147
9
The Shape
of the Came
148
The Shape
of the Game
Line 320 checks for collisions with the player-figure and checks to
see if the figure has reached the end of its journey:
320 ON -(PEEK(L(I)) =FG) -2*(L(D =E(I) )GOSUB 400,490
Line 330 actually carries out the movement by POKEing the
figures onto the screen in the new locations:
330 POKE L(I),FG(I):POKE CL(I),C(I):NEXT
Vital parts of this are the subroutines at 400 and 490. Since we
haven't created an entire program here, I won't try to create the
collision subroutine, but the routine at 400 would need to change
the score, decide whether the player-figure should win or lose the
encounter, and assign new addresses, if necessary, to both the
player-figure and the computer-controlled figure.
We can be more specific with the miniroutine at 490. Remem
ber that the program only reaches this line if the figure's screen
location matches its ending location. Therefore, all we need is:
490CL(I) =CL(I) -(L(I) -S(I) ):L(I) =S(I):RETURN
And that's it. By giving all your onscreen figures the same
name, with subscripts, you can assign all their values in loops
using DAIA statements, and you can handle their movements
and their collisions in a single routine. You have saved memory,
you have probably saved running time, but above all you have
kept the routine simple and easy to follow.
Label your work. Just because you're using a computer
doesn't mean you can't write things down on paper. It's a good
idea to keep a list of what each variable is used for in each pro
gram you work on. That way you won't accidentally use a variable
149
9
The Shape
of the Came
You can write down where each major subroutine is. You can
write down key line numbers or areas where you plan to put
subroutines.
Most important of all, however, is simply to label your tapes
and disks, both externally and internally. There's nothing more
frustrating than working for hours on a program only to realize
that the version you're working on is not the most recent one, that
all of the improvements from your last programming session are
saved somewhere else. I've made it a habit to put the date at the
beginning of my program. Some people put the date in REM
statements, so you'll see it when you LIST the program. I put it
right in a PRINT statement, so the date of this version will be
flashed on the screen. That way I can keep track of which version
of my game I am working on.
150
9
The Shape
of the Came
Be selective. That's a short list, but it can still be far too long.
To keep up the illusion of speed, you need to be selective — not all
those things need to happen every time through the loop.
For instance, suppose you wanted to control the ten
computer-figures whose movement we just programmed. In
stead of putting them in a FOR-NEXT loop and moving all ten of
them every time, why not access 300 as a subroutine with a ran
dom value? If the main loop contained this line, you'd get a very
interesting effect:
1201 =INT(RND(9)*10):GOSUB 300
151
9
The Shape
of the Game
Now, whether TI$ is 7 or 70, this line will snag the program and
send it out to 500 at nearly the right time.
Stop the action. Sometimes you can stop the action com
pletely to carry out some task, and the player won't feel that the
game has been slowed down at all. For instance, when the player-
figure collides with something, you can stop for an elaborate colli
sion routine, with animation and sounds, and the player won't
feel like it slows down the game — it will actually make it more ex
citing, and it will feel faster. Likewise, when the player fires a
missile, or when an opposing figure first comes on the screen,
you can take some time with it.
Stopping the action is fine; what you must avoid is a long
time-lag between the player giving an instruction and the player-
figure carrying it out. If the player is getting a quick response dur
ing the action phases of the game, you can take as long as you like
in the other sections.
152
9
The Shape
of the Game
Each space you leave out is one byte saved. The trouble is, it
makes the program harder to read.
153
9
The Shape
of the Game
• REM statements. REMs are nice because they help you label
what's going on in sections of a program — they make it easier for
you or someone else to understand what your program is doing.
But when you're dealing with limited memory, REMs are all
expendable.
• Multiple statements per line. Each new line number is extra
bytes used up in memory. You can save some memory by putting
several statements per line, separated by colons (:). However,
remember that everything on a line after an IF statement will be
executed only if the condition is true. However, anything after an
ON-GOSUB statement will be executed whether the condition is
true or not. Anything on a line after an unconditional GOTO will
never be executed at all.
• Use short variable names. Since the first two characters of a
variable name are all that count, you might as well use only those
two characters and save bytes.
• Change numbers to variables. Numbers take several bytes
to store in memory, because the computer reserves enough mem
ory for each number to store large numbers in that space. Thus a 0
uses up as much memory as 33999. However, a short variable
takes up less space. Remember that you have to use up some
bytes assigning a value to the variable — A = 55. That statement
takes up some bytes, too, so you'll only save memory by assigning
variable names to numbers that are used more than once. The
most commonly used numbers are 0 and 1 — it's often a good idea
to use ZO and Zl or NO and Nl as the variable names for these
numbers.
• Use arrays, loops, and ON. The program used as an exam
ple in the discussion of speed also saves memory because of the
use of an array. You can do ten operations in a single FOR-NEXT
loop instead of using ten separate lines. You can make five tests
on a single ON statement instead of using five separate IF state
ments. By programming carefully, you can develop tighter code.
• Trim introductions and farewells. Important as they are,
introductions, instructions, and farewell comments do eat up
bytes. You may have to choose between having a really explicit in
troduction and having some important features in a game.
Remember that you can often give the same amount of informa
tion in fewer words.
• Use subroutines for any operation performed more than
oncee. If you have line after line that does almost the same thing
except that a few numbers are different, you might consider using
154
9
TheShape
of the Came
a subroutine for the meat of the operation, and having each of the
other lines set variable values and access that subroutine in order
to perform the operation. This can sometimes slow down a game
by adding extra GOSUBs and implied LETs, but if you're up
against the end of memory, you sometimes have no choice.
• Don't use redefined characters. If you can make do with the
built-in character set, you will save hundreds of bytes.
• Delete features. Sometimes a feature just isn't going to fit in
an unexpanded VIC. If you can't or don't want to expand mem
ory, you may just have to accept a limitation on what your game
can include.
After all this talk of crunching memory, it's good to remember
this: there are a lot of fantastic games that run on the unexpanded
VIC. Yours can be one of them.
155
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
Missiles and
"Moonraker
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
10
Missiles and
"Moonraker
There is a kind of figure that is partly under the player's control
and partly under the computer's. When a baseball player in a
videogame throws the ball, the player might control when the
ball is released and the angle at which it is thrown, but rarely will
the player control the ball's actual trajectory, its path across the
screen. That is almost always controlled by the computer.
The same thing happens with missiles in Asteroids, bombs
and bullets in Scramble, the juggler's ball in Mr. Do, and the air
hose in Dig-Dug. They all seem to emerge from the player-figure,
but once they are launched, their path and the distance they
travel are usually controlled by the computer.
The principle of firing missiles is simple enough: when the
player presses the joystick button or a designated key on the key
board, the program jumps to a missile subroutine. A missile-
figure is put on the screen one character away from the player-
figure in the direction in which the player is shooting, then the
missile is moved across the screen as far as you want it to go.
In machine language games, the missile is moved in steps
along with the player-figure, so that the player-figure can keep
going after it shoots. In BASIC, however, it is usually better to let
the whole game freeze until the shot is completed. That way
when the other objects on the screen move at all, they move as
quickly as ever. Trying to move a missile along with everything
else will tend to slow down the program.
Add a Laser
Here are some lines to add to Program 6-2, "Mission: Nova!" If
you have added in the new lines for sound routines in Chapter 7
and for introductions and farewells in Chapter 8, this missile rou
tine won't fit in an unexpanded VIC. Just delete the introductory
display and you'll have no problem. If you have an expanded
VIC, you can add these lines directly to the full program.
159
10
Missiles
and "Moonraker"
Line Function
40 Set the intial value of DI to -1, for a leftward shot.
100 If a key with a value less than 55 (f5) has been pressed,
jump to the subroutine at 300.
285 If a horizontal move has been made, set DI to show the
direction of the move. DI will therefore always show the
direction of the last horizontal movement — and this will
be the direction of the next laser shot.
300 If the player-figure is at the edge of the screen, shooting
off the edge, return without doing anything.
305 Set MV and MH to the current vertical and horizontal
location of the player-figure, plus one step in the direc
tion of the shot, so that the laser beam will appear be
side, not on top of, the player-figure. Then set EM to 0
for leftward shots, 21 for rightward shots.
310-315 If the next character in the direction of the shot is a blank
(32), POKE the laser character (70) into that place. If the
next character is not a blank, set EM to the last location
where a 70 was POKEd and jump to the explosion sub
routine at line 330.
160
10
Missiles
and "Moonraker
320 Replace the laser with blanks (BB = 32) and return to the
main loop of the program.
330 Show an animated, twirling explosion.
340 If the laser hit a small star, turn it into a nova, but set BB
to 46, so that all the spaces between the player-figure and
the new nova are small stars. We wouldn't want the
player to rack up a million points by changing small stars
to novas and moving right over to them without any
obstacles.
350 If the laser hits a nova, add the appropriate number of
points and replace the nova with a small star.
360 If the laser hit anything else, change it to a used-up
space station (104) and subtract 1000 from the score. This
is because the only thing the laser can hit, besides a
blank, a small star, and a nova, is the space station itself.
Not the sort of thing that earns many points.
370 POKE the new character into place and go back to line
330 to erase the laser (or replace it with small stars).
A Missile version
If you don't like the continuous beam of the laser, it's a simple
matter to replace it with a missile. Basically, all you have to do is
erase the last missile character as soon as you POKE in the new
one. The tricky part with missiles is how to handle the end of their
flight. It has to be different if the flight ends with a collision or
simply with the edge of the screen. The virtue of this routine is
that it's very quick, very dartlike in its movement, in spite of being
in BASIC. This version still preserves the feature of not allowing
the player to change small stars right next to the ship into novas.
However, if you want to remove that feature, just replace line 340
with
340 IF X =46 THEN 380
Otherwise, use lines 40,100, and 285 from Program 10-1, and
replace lines 300-370 with this program:
161
10
Missiles
and'Moonraker
162
10
Missiles
ancTMoonraker"
No, I didn't write it that way. I left plenty of extra line numbers
while I was programming. But when I was through, I used a line-
renumbering utility to tighten down my program.
Since I was using an unexpanded VIC, I used 7680 directly as
the starting address of screen memory. I also found that I was
running out of memory with all my title screens. So I used a fairly
sophisticated technique for fooling BASIC into erasing the intro
ductory part of the program after it was entered. But that's a pro
gramming technique, not a game technique — the sort of thing
you'll want to start learning as you get better at game program
ming, but certainly not essential when you're just starting out.
So here's my first full-fledged game. I hope you like it. Who
knows? Maybe 111 get to play yours someday.
163
10
Missiles
and "Moonraker
25 DATA48,72,180,207,207,180,72,48,0,0,0,255,255,0
,0,0
26 DATA136,73,74,42,165,90,189,126,34,132,88,61, 60
,154,33,72
27 DATA36,36,24,24,60,60,36,24,6,136,152,124,62,25
,17,96
28 DATA0,0,0,0,36,36,24,24,8,8,28,34,62,62,85,85
29 DATA60,60,36,24,0,0,0,0,0,0,0,0,0,0,255,0,255,0
,0,0,0,0,0,0
30 DATA128,64,32,16,8,4,3,0,1,2,4,8,16,32,192,0,0,
128,127,0,0,0,0,0,0,1,254,0,0,0,0,0
31 PRINT"{CLR}":POKE36869,255:CLR:POKE36879,8
32 PRINT"{RED}{20 DOWNjz]T«£ZZZ]T«£][[[Ull£ Z"
33 L=7900:V=36878:S=36877::L1=7788:L2=7723:L3=7718
:L4=8112:L5=8116:TI$=II000000":U=32
34 M=22:O=23
35 PRINT" {HOME} {RVSHyEL,} {3 RIGHT}MOONRAKER{WHT}
{RIGHT}";X
36 POKEL3,21:POKEL3-M,U:POKEL1,0:POKEL2,M:POKEL4,2
4:POKEL5,24:POKEL,2:POKEL+1,3
37 POKEL2,U:N=255:IFL2=>8054THENL2=L2-M
38 IFL2<=7702THENL2=L2+M
39 P=INT(RND(1)*4):IFP=0THENL2=L2-44
40 IFP=lTHENL2=L2+44
41 IFP=2THENL2=L2+2
42 IFP=3THENL2=L2-2 ^
43 IFL3=L4ORL3=L5THENX=X-500:GOTO75
44 IFL3=>8098THEN75
45 POKEL3,O:POKEL3+M,25:L3=L3+M:F=Ll+21:POKEF,0:PO
KEL1,U:L1=F
46 IFF=>8098THENPOKEF,U:Ll=INT(RND(l)*O)+7702
47 IFL=L1ORL=L2ORL=L3THENX=X-250:GOTO77
48 IFL+l=LlORL+l=L2ORL+l=L3THENX=X-250:GOTO77
49 IFL>8076THENPOKEL,U:POKEL+1,U:L=L-M:GOTO35 ;
50 IFL<7724THENPOKEL,U:POKEL+1,U:L=L+M:GOTO35
51 IFPEEK(197)=46THEN59
52 IFPEEK(197)=45THEN60
53 IFPEEK(197)=53THEN63
54 IFPEEK(197)=UTHEN61
55 IFPEEK(197)=17THEN65
56 IFE<0THEN80
57 IFTI$>"000120"THEN79
58 GOTO35
59 POKEL,4:POKEL+1,6:POKEL+2,7:POKEL,U:POKEL+1,2:P
OKEL+2,3:L=L+1:GOTO35
60 POKEL-1,4:POKEL,6:POKEL+1,7:POKEL-1,2:POKEL,3:P
OKEL+1,U:L=L-1:GOTO 3 5
61 POKEL,8:POKEL+1,9:POKEL+M,10:POKEL+O,12
62 POKEL,U:POKEL+1,U:POKEL+M,2:POKEL+O,3:L=L+M:GOT
035
164
10
Missiles
ancT'Moonraker
63 POKEL, 10:POKEL+1,12:POKEL-M,8:POKEL-21,9
64 POKgL,U:POKEL+1,U:POKEL-M,2:POKEL-21,3:L=L-M:GO
TO.3V ^
65 Poicl2L+2,16:POKEV,15:POKE36877,N
66 FORF=0TO18:POKEL+3+F,17:POKEC+F+3,2:POKEL+2+F,U
:POKEL+2,U:POKE3687 7,N
67 L6=L+3+F:IFL6=LlTHEN X=X+150:GOTO71
68 IFL6=L2THENX=X+250:GOTO73
69 IFL6=L3ORL6=L3-MTHENX=X+50:GOTO75
70 N=N-12:NEXT:POKEL+21,U:POKEV,0:GOTO35
71 POKEV,15:POKES,130:POKELl,20:FORT=0TO600:NEXT
72 POKEL1,U:POKEV,0:L1=INT(RND(1)*O)+7702:GOTO35
73 POKEV,15:POKES,130:POKEL6,20:FORT=0TO600:NEXT
74 POKEL6,U:POKEV,0:GOTOQS> }£
75 POKEV,15:POKES,130:POKEL3,20:FORT=0TO600:NEXT
76 POKEL3,U:POKEL3-M,U:L3=INT(RND(1)*O)+7702:POKEV
,0:GOTO35
77 POKEL,20:POKEL+1,20:POKEV,15:POKES,130:FORT=0TO
600:NEXT
78 POKEV,0:GOTO35
79 POKE198,0:POKE36869,240:PRINT"{CLR}{5 DOWNTIME
IS UP:YOUR SCORE IS:";X
81 PRINT-.PRINT "HIT THE * TO TRY AGAINOR THE RUN/ST
OP TO END
82 GETA$:IFA$=""THEN82
83 GOTO11
84 A=PEEK(61)+256*PEEK(62)+3:POKE2,INT(A/256):POKE
1,A-256*PEEK(2)
85 A=PEEK(61)+256*PEEK(62)+3:POKE2,INT(A/256):POKE
1,A-256*PEEK(2)
86 IFERTHENPOKEA-2,0:POKEA-1,0:POKE45,PEEK(1):POKE
46,PEEK(2):CLR:GOTO6
87 PRINT11 {CLR} AS COMMANDER OF MOON-{DOWN}RAKER YO
U ARE TO{2 SPACES}PRO-{DOWN}TECT THE 2 RESEARCH
88 PRINT"{DOWN}PODS ON THE MOON'S{4 SPACES}{DOWN}S
URFACE. HITS BY ALIEN{DOWN}TO YOU OR YOUR
{2 SPACES}PODS
89 PRINT"{DOWN}CAUSES LOSS OF POINTS.{DOWN}BLAST T
HE ALIENS WITH {DOWN}YOUR LASER FOR POINTS
90 PRINT"{3 DOWN}{RVS}HIT ANY KEY TO CONT.{OFF}
91 GETA$:IFA$=""THEN91
92 PRINT"{CLR}BEWARE OF THE RANDOM{2 SPACES}{DOWN}
MOVING TWIRLER WHICH{2 SPACES}{DOWN}STRIKES WIT
HOUT NOTICE
93 PRINT"AND ROBS YOU OF POINTS{DOWN}YOU WILL HAVE
120 SEC-{DOWN}ONDS TO GET AS MANY
94 PRINT"{DOWN}POINTS AS YOU CAN.{4 SPACES}
{2 DOWN} GOOD LUCK COMMANDER11
95 PRINT"{2 DOWN}{RVS}HIT ANY KEY TO CONT.{OFF}
96 GETA$:IFA$=""THEN96
97 ER=1:GOTO84
165
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
A
Beginner's Guide to
Typing m Programs
A Beginner's
Guide to Typing
m Programs
what is a Program?
A computer cannot perform any task by itself. Like a car without
gas, a computer has potential, but without a program, it isn't going
anywhere. Most of the programs published in COMPUTE! Books
are written in a computer language called BASIC. BASIC is easy
to learn and is built into all VIC-20s.
basic Programs
Computers can be picky. Unlike the English language, which is
full of ambiguities, BASIC usually has only one right way of
stating something. Every letter, character, or number is signifi
cant. A common mistake is substituting a letter such as O for the
numeral 0, a lowercase 1 for the numeral 1, or an uppercase B for
the numeral 8. Also, you must enter all punctuation such as co
lons and commas just as they appear in the book. Spacing can be
important. To be safe, type in the listings exactly as they appear.
169
A
Beginner's Guide to
Typing in Programs
A Quick Review
1) Type in the program a line at a time, in order. Press RETURN at
the end of each line. Use the INST/DEL key to erase mistakes.
2) Check the line you've typed against the line in the book. You
can check the entire program again if you get an error when you
RUN the program.
3) Make sure you've entered statements in braces as the ap
propriate control key (see "How to Type In Programs").
170
B
How to Type
in Programs
How to Type
m Programs
Many of the programs listed in COMPUTE! Books contain special
control characters (cursor control, color keys, reverse characters,
etc.). To make it easy to know exactly what to type when entering
one of these programs into your computer, we have established
the following listing conventions.
Generally, any VIC-20 program listings will contain words in
braces which spell out any special characters: {DOWN} would
mean to press the cursor down key. {5 SPACES } would mean to
press the space bar five times.
To indicate that a key should be shifted (hold down the SHIFT
key while pressing the other key), the key would be underlined in
our listings. For example, S would mean to type the S key while
holding the shift key. This would appear on your screen as a heart
symbol. If you find an underlined key enclosed in braces (e.g.,
{10 N}), you should type the key as many times as indicated (in
our example, you would enter ten shifted N's).
If a key is enclosed in special brackets, [<>], you should hold
down the Commodore key while pressing the key inside the special
brackets. (The Commodore key is the key in the lower-left corner
of the keyboard.) Again, if the key is preceded by a number, you
should press the key as many times as necessary.
Rarely, you'll see a solitary letter of the alphabet enclosed in
braces, such as {A }. You should never have to enter such a
character on the VIC-20, but if you do, you would have to leave
the quote mode (press RETURN and cursor back up to the posi
tion where the control character should go), press CTRL-9 (RVS
ON), the letter in braces, and then CTRL-0 (RVS OFF).
About the quote mode: you know that you can move the cursor
around the screen with the CRSR keys. Sometimes a programmer
will want to move the cursor under program control. That's why
you see all the {LEFT }'s, {HOME }7s, and {BLU }7s in our pro
grams. The only way the computer can tell the difference be
tween direct and programmed cursor control is the quote mode.
Once you press the quote (the double quote> SHIFT-2), you
are in the quote mode. If you type something and then try to
change it by moving the cursor left, you'll only get a bunch of
171
How to Type
In Profjrdms
reverse-video lines. These are the symbols for cursor left. The
only editing key that isn't programmable is the DEL key; you can
still use DEL to back up and edit the line. Once you type another
quote, you are out of quote mode.
You also go into quote mode when you INSerT spaces into a
line. In any case, the easiest way to get out of quote mode is to just
press RETURN. Youll then be out of quote mode and you can
cursor up to the mistyped line and fix it.
Use the following table when entering cursor and color con
trol keys:
{up} CTRL || 8
{DOWN}
I LEFT}
{RIGHT} (3
{RVS} f4
{off} f5
Iblk} f6
{whtJ CTRL
LlJ f7
{red} CTRL [ 3 f8
{cyn} CTRL 4
SHIFT
{pur}
172
Screen Location
Table
Column
173
screen Color
Memory Table
Column
174
sereen color
codes
Code: 0 1 2 3 4 5 6 7
175
Screen and
Border colors
176
G
ASCII
codes
ascii codes
19 HOME 59
20 DELETE 60 <
28 RED 61
>
29 CURSOR RIGHT 62
30 GREEN 63 ?
31 BLUE 64 @
32 SPACE 65 A
33 I 66 B
34 67 C
35 # 68 D
36 $ 69 E
37 % 70 F
38 & 71 G
39 72 H
i
40 ( 73 I
41 ) 74 J
*
42 75 K
43 + 76 L
44 77 M
45 -
78 N
46 .
79 O
47 / 80 P
48 0 81 Q
49 1 82 R
177
c
ASCII
codes
1
IB 163 n
114 164
115 165
116 166
117 □ 167 a
118 168
119 169 E
178
c
ASCII
codes
170 207
171 208 □
172 n 209 m
173 H 210 B
174 211
175 U 212
176 H 213 □
177 H 214
178 H 215
179 216
180 □ 217 a
g
181 218
182 219
183 220
184 221 m
185 222
186 □ 223
187 224 SPACE
188 a 225 I
189 H 226
190 E 227 n
191 B 228
192 B 229 □
193 230
194 m 231 a
195 B 232
196 233 B
197 1 ' 234 a
198 B 235
199 D 236 ■
200 1 237
201 238
202 239
203 □ 240 H
204 D 241
205 S 242 H
206 243
179
c
ASCII
codes
ASCII CHARACTER
244 D
245 C
246 [J
247 n
248 □
249
250 a
251 Q
252 H
253 H
254 E
255
180
H
Screen
codes
screen codes
0 @ @ 31 —
1 A a 32 -space-
i
2 B b 33
34 "
3 C c
4 D d 35 # #
5 E e 36 $ $
6 F f 37 % %
7 G g 38 & &
1 '
8 H h 39
9 I i 40 ( (
10 J j 41 ) )
* *
11 K k 42
12 L 1 43 + +
13 M m 44
14 N n 45 - -
15 O o 46 .
16 P P 47 / /
17 Q q 48 0 0
18 R r 49 1 1
19 S s 50 2 2
20 T t 51 3 3
21 U u 52 4 4
22 V V 53 5 5
23 W w 54 6 6
24 X X 55 7 7
25 Y y 56 8 8
26 Z z 57 9 9
27 [ [ 58 ;
28 £ £ 59 ) ;
29 ] ] 60 < <
30 t t 61 = =
181
H
Screen
Codes
62 95 H
63 96 - -space- -
64 B B 97 ■ i
65 A 98 y y
66 B 99 □ □
67 B C
B n
100
68 B D 101
69 □ E 102
70 □ F 103 a a
71 D G 104
72 a H 105 B
73 I 106 a
74 □ J 107 E
75 □ K 108 Q
76 D L 109 H
77 M 110 H
78 0 N 111 U
79
□ O 112 B
80 □ P 113 H
81 Q 114 H
82 R 115
83 S 116 □
84 D T 117
85 U 118 a
86 V 119 □
87 W 120 a
88 X 121 u
89 Y 122 □
90 Z 123 D r
91 124 B H
92 125 H H
93 m m 126 B H
94 127 B
128-255 are reverse video of 0-127.
182
index
animation 4,20 colors on VIC 12
animation in place routine 94-95 combining characters 54
defined 80 Commodore 14
memory considerations 27 Commodore 64 Programmer's Reference Guide
minimum speed for smooth 79 107
player-controlled 96-97 complications, theory of 31
smooth 96 COMPUTED Second Book of VIC 119
with movement 95 control matrix 82
Apple computer 14 "Copying Characters" program 69-71
arrays, for program crunching 154 CPU 13
artificial intelligence 30-31 "Creating Characters" program 69
ASCII code 48,49 crunching programs 152,153-55
table 177-80 custom characters 27
Asteroids 25, 32,36,37,159 creating 63-75
Atari computer 14 memory considerations 27
'Athlete in Action" program 97-98 program crunching and 155
background sound 122-23 custom character sets 4,13,26-27
in main loop of game 123 DATA statements 169-70
BASIC 3 defeat, psychology of 32
relatively slow 13-14 Defender 19,25,37
Berserk 29-30 delay loop 98
"Blip" program 120 Dig-Dug 37,159
border colors 176 documentation 19-20, 38-39,150-51
Breakout 26 Donkey Kong 19,24,25,26,29,31,32,35,37,
Burger Time 24,31 80,117
cassettes, cheap ones work better 10 Donkey Kong Jr. 27,30,37
Centipede 25,29 existing games, improvement of 25-26
central processing unit see CPU experimentation 5-6
chaining programs 152-53 extras 135-44
character matrix 63-64 farewells 135,141-43
character memory 65 personalizing 144
characters 26 "Fill In" program 53
replacing 71-73 Firebird 25
sequential 73-74 FOR-NEXTloops3,5
character set 45 FRE function 75,136
copying into RAM for customization 68-75 Galaga 25,35
stored in ROM 68 Galaxians 25,36
character work grid 67 game design, different from programming
children, and game testing 7-8 6
CHR$ function 48 discussion 19-40
clock, in "Subroutine Sound" program game story 25-26
125 importance of originality 25
collisions 101-14 GOSUB3,5/28,136
detection of 101,129 GOTO 3
color key 56 graph paper 10
color memory 45,102 graphics characters 13
example program and discussion 57-59 habits, important in good programming
finding 57 148
limitation on POKE 56 homing pattern 29,30
manipulating 56-59 horizontal movement 85
table 174 ideas 6-7
colors, border, manipulating 43-45 in-line logic 89
colors, playfield, manipulating 43-45 "Inchworm" program 95
183
instructions 135,138-41 Mr. Do 159
interest-maintaining techniques 23, 32-38 Ms. Vac-Man 19
bonus turns 37 "Multicharacter PRINT Movement"
complication 34 routine 90
incentives 35 noise register 118
increasing accuracy 34 ON statement, for program crunching 154
increasing difficulty 33-34 opponents, intelligent 29-30
in Joust 20 opponents, mindless 30
new scenery 34-35 originality, in game story 25
scoring 35-36 Vac-Man 24,26, 30, 31, 32,35, 37,101,117,
story rewards 37 118
introductions 135-38 PEEK 14
invisible objects 44 explained 46-47
Joust 19,26,30,31,34,37,117 Personal Computing on the VIC-201,119
game analyzed 20-24 pixel 12,26,64
joystick 19,20,28 "Player-Controlled Animation" routine
reading 92-93 96-97
joystick button 93 player movement 20
Kangaroo 30,35,37 trade off speed and complexity 28
keyboard reading 81-85 point inflation 36
key code 81, 83 POKE 14
table 84 explained 46-47
"Keysound" program 120 - PRINT 3,48
discussion 120-21 combined with POKE 112-14
"Keysound UFO" program 121 dangers of 88-90
discussion 121-22 faster than POKE 88
"Laser X Jet" program 91-92 } moving cursor with 55-56
loops, for program crunching 154 screen displays with 54-55
machine language 13, 28 "PRINT Movement Routine" 87-88
and animation 79 programming techniques 147-55
magazines, programs in 5-6 program translation 14-15
main loop, proper function of 150 Qix 25
marketing 8-10 Rally-X 31
memory, economical use of 135 RAM 11
memory locations 14 5K basic option on VIC-2011-12
MID$ function 105 random access memory see RAM
missile routines 159-65 random screen displays 51-53
Missile Command 25, 33, 35, 37 raster 79
"Mission: Nova!" program 105-6 j READ statement 52
discussion 106-9 in character replacement 72-73
farewell code 143 REM statement 154
instructions code 139-40 RESTORE statement 52
introduction code 136 RND function 51-52
laser routine in 159-61 Robotron 25
missile routine in 161-62 Scramble 159
modified by GOSUBs 136 screen, VIC-2012
sounds, in code and discussion, 128-31 screen codes 48-49
Monopoly 32, 35 table 181-82
"Moonraker" program screen color codes 175,176
discussion 162-63 screen color memory table 174
program 163-65 screen design 4,43-58
movement 79-81 screen location table 173
defined 80 screen memory 45,102
demonstration program 80-81 finding 57
with animation 95 manipulating with PEEK and POKE 47
with POKE program 86-87 organization 49
184
screen relationships 29 Super Breakout 36
scrolling 104-5 Surround 26
6502 chip 14 TAB function 55
not all machines using it compatible Tempest 25,34,35
14-15 testing 7
sound 4 timer, common 151-52
importance of 37-38 timer reset routine 109
in Joust 23-24 TI$ variable 107,109,110
in "Mission: Nova!" 128-31 Iron 26
in subroutines 123-27 true/false test 44
turning off 120 unpredictability 33
uses of 117-18 programming 33
"Sound Game" program 127 vanity board 36-37
discussion 127-28 in Joust 23
sound registers 118 variables, take less space than numbers
Space Invaders 28,30, 33,117 154
"Spaceship Collisions" program 101-2 Venture 25, 35
discussion 102-3 vertical movement 85
"Spark" program U3-14 VIC-20
discussion 112-13 colors 12
farewell code 42 languages available 13
setting difficulty in 140-41 RAM 11-12
SPC function 56 screen 12
speed, real and apparent 150-51 sound 13
"Star-Eater" program 110-12 specifications 11-15
"Starfield" program 51-53 V7C-20 Programmer's Reference Guide 10, 68
STEP function 5 VIC-20 User's Guide 10,68
submission to publishers 9-10 Video Interface Chip (VIC) 45
subroutines, program crunching and volume control register 118
154-55 weaknesses, need for in computer
subroutines, sound 123-31 opponents 31
halt game action 124 "Wire" program 54-55
no-stop subroutines 126-28 wraparound 89-90
"Subroutine Sound" programs 124,126 "Zap" program 119
discussion 124-25,126
185
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
If you've enjoyed the articles in this book, you'll find the
same style and quality in every monthly issue of COMPUTE!
Magazine. Use this form to order your subscription to
COMPUTE!.
COMPUTE!
PO. Box 5406
Greensboro, NC 27403
My Computer Is:
□ Commodore 64 □TI-99/4A □ Timex/Sinclair DVIC-20 Q PET
□ Radio Shack Color Computer □ Apple □ Atari □ Other
□ Don't yet have one...
Name
Address
Country
Payment must be in US Funds drawn on a US Bank; International Money
Order, or charge card.
□ Payment Enclosed □ VISA
□ MasterCard □ American Express
Ace t. No. Expires /
25-6
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
If you've enjoyed the articles in this book, you'll find
the same style and quality in every monthly issue of
COMPUTERS Gazette for Commodore.
computers mmmmwwm
P.O. Box 5406
Greensboro, NC 27403
My computer is:
□ Commodore 64 □ VIC-20 □ Other.
Name
Address
25-6
The COMPUTED Gazette subscriber list is made available to carefully screened organiza
tions with a product or service which may be of interest to our readers. If you prefer not to
receive such mailings, please check this box □.
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
COMPUTE! Books
P.O. Box 5406 Greensboro, NC 27403
Country
Allow 4-5 weeks for delivery.
25-6
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
Q
O
O
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
G
o
o
G
G
G
G
G
G
G
me
You want to create your own games, but you're not sure just how
to begin. After all, game writing can be one of the most demand
ing programming tasks. Whether you already know programming
or are just starting, it may seem almost impossible to create a
successful game. This book — a guide for anyone who has thought
of designing and writing a game program — shows you how.
Robert Camp's Creating Arcade Games on the VIC is a step-by-step
guide through the process of writing your own game on a home
computer. From developing a game design concept to writing a
complete game, you'll find every method and technique you need
for creating VIC games. Detailed and clear explanations make it
easy to follow along.