IBM Personal Computing

Donald B. Trivette

Inside King's Quest

Byron and I were playing King's Quest-a new adventure game for the IBM PCjr written by Sierra. "But how does it work?" he wanted to know. "How would you even go about writing a program like that?" As a bright computer science major, Byron can write programs to perform reverse Polish notation, link-lists in Pascal, and all those other exotic things that students learn to do. But he couldn't begin to guess how King's Quest was written. Neither could I.

Everyone is familiar with arcade-style games in which you win points either for zapping strange-looking creatures or for not getting zapped yourself. An adventure game is entirely different. Winning an adventure game requires logic and puzzle-solving ability, not eye-hand coordination with a joystick.

Searching For Treasure

In King's Quest you play the game as Sir Grahame, a computer-animated knight who roams the kingdom of Daventry looking for three treasures. As Sir Grahame explores the kingdom, he can pick up objects like a dagger, a carrot, and a goat (yes! a goat) that may eventually help him locate the magical treasures. However, finding the objects is no cinch-some are in plain view but easily overlooked, while others are hidden in stumps and at the tops of trees. And of course there are hazards to overcome and puzzles to solve. How can Sir Grahame get across a bridge guarded by a troll? Kill the troll with the dagger? Don't try it! This is a game of strategy, not violence. There are several solutions to each puzzle and the more innovative and peaceful Sir Grahame is, the more points he gets.

The mechanics of playing the game are simple. You control Sir Grahame with either a joystick or the cursor-arrow keys. When Sir Grahame moves out of one scene, say to the right, a new scene appears on the screen. The main kingdom of Daventry is six scenes from north to south and eight scenes from east to west. The kingdom wraps around itself so that the 48 scenes are continuous. There are 32 other scenes for the interiors of caves and houses.

On the bottom four lines of the screen, you can type simple verb-noun sentences like Take a carrot, Kill the troll, or Look at the river. This area also displays messages and warnings for Sir Grahame: The river is swift and deep. (One quickly learns not to swim in swift, deep rivers.)

The graphics and animation in the PCjr version of King's Quest are spectacularly better than in any other adventure game I've seen. The three-dimensional quality makes it seem like Sir Grahame is moving through an animated cartoon. He can bump into and go around objects, climb trees and swim in water, duck behind rocks, and jump into the air. If he walks behind a rock, his legs are invisible; if he walks in front of a rock, part of the rock is invisible. When Sir Grahame moves, his arms and legs move, and the background shows between them. While we take that kind of animation for granted in a movie, it is not easily accomplished in a computer program on a machine without sprites. That's the part that had Byron and me puzzled. How do they do that? I called Sierra to find out.

A $700,000 Computer Game

A year before the PCjr was announced - when the "Peanut" was just a rumor to the rest of us - IBM asked Sierra to create a game that would show off the new computer's color graphics capabilities. IBM supplied Sierra with a prototype junior.

Roberta Williams, who had worked on five other adventure games, was given the task of designing something completely new and dif ferent. Eighteen months later, Williams and a team of six programmers and artists had created King's Quest-at a cost of over $700,000.

First, Williams wrote the story. She based it not on strange characters with strange names, but rather on familiar characters from literature. Do you remember "Billy Goats Gruff" and "Hansel and Gretel"? Once the story line was established, the artists prepared detailed color drawings of each of the 80 scenes. In adventure-game jargon, scenes are called rooms. Each drawing was then traced on a Calcomp Graphics Tablet. This process automatically generated the instructions which tell the computer how to reproduce each room, saving the programmers months of tedious work.

The drawing instructions for each room are stored as separate files on the disk. (Technically, they are stored at absolute sector addresses, not actually in disk files.) When Sir Grahame moves from one room to another, the computer loads the instructions for displaying the new room, draws the room point by point, and then fills in the color. It takes about four seconds for the PCjr to draw and color a room. A faster approach would have been to store the room images themselves on disk, already drawn. But that method would have used considerably more disk space and reduced the number of rooms in the game. (Actually, it's entertaining to watch the computer draw and color each scene.)

Sir Grahame begins his quest Sir Grahame begins his quest at the castle of Daventry.

The Invisible Skeleton

The first scene in King's Quest is the castle of Daventry where Sir Grahame's quest begins (see photo). The lions, flags, stone blocks, alligators, and plants make this the most detailed room in the kingdom. It takes 2400 bytes of instructions to tell the PCjr how to draw and color this scene. By contrast, the easiest room to draw requires only 470 bytes of instructions.

The scenes are more than just static back grounds. For instance, if Sir Grahame staggers a bit and runs into a castle wall, he stops. How does the program know when the character hits something? There's a skeleton, an invisible structure, behind each picture. If you could see this skeleton, you'd notice lots of lines running all over the screen defining where Sir Grahame can and cannot walk. The lines were drawn into each room with the graphics tablet.

In addition to concealing hidden lines, each room also assigns priorities to every object it contains (trees, rocks, flowers, etc.). These priorities-numbers from 1 to 15-give King's Quest its three-dimensional quality.

Objects at the top of the screen have low priority; those at the bottom, high. Sir Grahame's priority changes as he moves around the room. For example, a tree in the middle of the screen might have a priority of 9. When Sir Grahame is in front of the tree-closer to the bottom of he screen-his priority might be 11. As he moves up the screen, his priority changes. If he is behind the tree in a scene, his priority is less than that of the tree. By comparing priorities each time Sir Grahame moves, the program makes decisions about how to draw the screen. If Sir Grahame's priority is higher than the object behind him, he is visible and the object (or part of it) is invisible. If his priority is lower, as when he steps behind a tree, then he (or part of him) disappears.

Each time Sir Grahame (or any object) moves, the surrounding region on the screen is saved in the computer's memory in one of four save-areas. The program checks the new location for skeleton lines and priorities, then adjusts Sir Grahame and the surrounding area for any changes-perhaps part of a rock became visible in front of his legs. Finally, Sir Grahame and the surrounding area are redrawn on the screen. And that's how Sir Grahame walks around the kingdom of Daventry.

The Game's Own Language

In addition to the graphics for each room, there is a set of logical statements. These are written in a special language devised by Sierra called the Game Adaptation Language. The program constantly loops through these statements looking for something to change. They work sort of like a group of IF-THEN statements in BASIC.

For example, in one room, room 10, a goat randomly wanders around inside a pen (see photo). The pen extends into room number 11 on the right. If the goat happens to wander out of room 10, the program must erase the goat. The program knows the goat by the codename 14 and Sir Grahame by the name Ego. So if Ego moves to room 11 in search of the goat, the program must remember to draw 14 in room 11. The statement in Game Adaptation Language looks like this:


If I understood what that meant, I'd be writing adventure games instead of magazine articles, but with a little examination we can pretty much figure out what's going on. In programming logic, the numeral 0 means false, no, or off, and the numeral 1 means true, yes, or on. Thus, in English, the statement might read: "If Ego doesn't have the goat and if the goat has hit the edge of the room and if the edge of the room has been hit and if the goat is in the room in the first place and if the goat has not been shown the carrot, then [Whew!] remember to draw the goat in room 11 and erase the goat from room 10."

And remember, that is just one of the logic statements that goes with room 10-there are a total of 180 logic lines for this room alone. The logic statements give the program its personality; they tell the program what to do and when to do it.

pastoral scene A pastoral scene in King's Quest

Inevitable Bugs

Anyone who has ever written a computer program knows that program logic is a fertile field for errors. If the programmer forgets to tell the computer just one little detail, the results can be amusing-and disastrous. Preliminary versions of King's Quest were not without bugs. It took several weeks to find out why, if Sir Grahame jumped in the air as he moved from one room to another, he skidded into the new room totally out of control. That bug has been fixed, but a few others still lurk in the current PCjr version. (But not, says Sierra, in the versions it markets directly.)

During one game, Sir Grahame was standing at the edge of a bridge. The goat was coming back across the bridge, and as it passed, I made Sir Grahame jump. A foolish thing to do, I know, but I was celebrating. Unfortunately, the screen filled with horizontal lines and the game came to a swift end. The programmer who wrote the logic statements for that scene forgot to allow for the possibility that Ego might jump as the 14 passes in front of him. Nevertheless, the errors are very few.

Some things you might consider an error are not errors at all. For example, there can be only four animated objects (including Sir Grahame) in any one room. The program has only four save-areas for animated objects. Somewhere along the way (I won't tell you where), Sir Grahame can acquire some magic beans. Getting those beans is the toughest part of King's Quest. (It helps to have read Grimms' Fairy Tales.) But try to plant the beans in the room where you found them and the screen will say: "You can't do that here." That's because that room already has four animated objects. In fact, you can plant the beans in only about half of the rooms in King's Quest because of the four-object-maximum rule. That's not a bug or an error, it's just a programming tradeoff to conserve memory.

There is one room in King's Quest with five objects. I don't want to give anything away, but: Should Sir Grahame (1) give the Woodcutter (2) and his wife (3) the right object (4), then he can take the fiddle (5). This apparent violation of the rule is permitted because the programmers pulled a fast one. Look closely when Sir Grahame puts the something on the table and you'll see the Woodcutter disappear for a moment. The programmer briefly swaps objects to keep within the limits. Tricky.

A Sequel On The Way

Roberta Williams is a perfectionist. There just wasn't time or memory to put everything in King's Quest that she wanted. She wishes the language interpreter had a larger vocabulary, that Sir Grahame could drop objects he has picked up, and that he could be even more animated. She wishes some of the characters, like the wolf, could roam from room to room. But she says the sequel, due in February or March, will be even better.

In King's Quest II, Sir Grahame-who becomes King Grahame when you solve King's Quest-goes in search of a wife. Along the way he meets Dracula and King Neptune, and rides a flying carpet. And, somehow, the folks at Sierra found a way to squeeze 94 rooms onto the disk. I can hardly wait.

IBM markets the PCjr version of King's Quest and Sierra markets versions for the IBM PC, Apple IIc, Apple Ile, and Tandy 1000 (a new computer scheduled for release in January 1985). All versions cost $49 and require 128K of memory and a disk drive. In addition, the PC version runs on most IBM compatibles. (When the PC version is displayed on an RGB monitor, the graphics are in the standard four-color medium-resolution mode; but connect your PC to a television and you'll get the same spectacular colors as the PCjr version.)

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.