Classic Computer Magazine Archive ST-Log ISSUE 28 / FEBRUARY 1989 / PAGE 10

GAME

LOW RESOLUTION ONLY

FLAG TRIVIA

by Michael Rupertus

Philadelphian Michael Rupertus has been an avid Atari user for over five years. He enjoys programming in C and 68000 assembly language, and although he is primarily interested in graphics, he likes to try to simulate board games on his computer. He hopes to eventually write a chess program.

Due to the large size of this program, it is available only on this month's disk version or from the ST-Log users' group on DELPHI.

After deciding that I wanted to become more familiar with the many flags of our world, off I went to a local bookstore in search of a book that contained flags shown in color. While looking at the flags, I concluded that it would be difficult, if not impossible, to memorize a good majority of them. Sure, countries like Canada with its maple leaf and Japan with its circle representing the land of the rising sun are easy to remember. But how about some of the less talked about countries—countries such as Suriname, Tonga and Malaysia? Rather than stare at the almanac, I realized that a more interactive (and interesting) method of learning was called for.

Yes, this is where the ST fits in. I reasoned that the computer could be programmed to draw the flags and then show them in a random order. And, hey, how about having the computer quiz me on the flags, giving me a limited amount of time to identify them? Also, it would be nice to have a two-player option enabling the player to race against each other and the clock.

Playing the game

The game is simple. The names of four countries will be shown at the top of your screen, one of which belongs to the flag shown. You get one guess at each flag. If you are correct, you get 1,000 points plus a bonus based on the skill level and the amount of time remaining on the timer. If your guess is wrong, you will not be told the correct country. This was done to make the game more interesting, albeit annoying!

Pressing one of the function keys along the top of the keyboard tells the computer your choice. Player 1 uses keys F1 through F4, and Player 2 uses keys F7 through F10. The keys F5 and F6 are not used. The table that follows shows the relationship between the function keys and the names of the countries shown at the top of the screen.

Player 1 Player 2
_________ _________
F1 F7 Upper left-hand country
F2 F8 Upper right-hand country
F3 F9 Lower left-hand country
F4 F10 Lower right-hand country

Programming notes

Before writing any of the program code, one major problem had to be overcome. Where will the data for drawing the flags come from? The problem was solved when I determined that only five basic drawing operations needed to be employed to draw a flag. They are as follows:

  1. drawing lines,
  2. filling an area with color,
  3. drawing circles,
  4. drawing arcs,
  5. drawing elliptical arcs.

After figuring out how to draw the flags, I then needed to find the most efficient medium to use. After dismissing the idea of having piles and piles of graph paper littered on my workspace, DEGAS was selected.

Fortunately, the vast majority of the flags all share something in common. They are rectangular shapes of the same width and height. With this in mind, I drew an outline that resembled a flag and saved the outline to disk. Each time I started a new flag, I loaded the outline and used it as a template.

So, with the problem of drawing flags resolved, a method of recreating the flags under program control was now needed. As most users of DEGAS know, each picture file requires 32,034 bytes of storage on disk. Since 100 flags were drawn, over three megabytes of storage space are required! It would be impossible to put this much data on a floppy disk, since a typical ST disk has a capacity of around 349K. This disk limitation ruled out the idea of having each flag loaded when needed.

VDI to the rescue

The VDI (Virtual Device Interface) provides a relatively simple method of redrawing the flags while the program is running. As many readers know, the VDI is extremely powerful because of its variety of graphics functions. The trick was to convert each flag into a set of numerical data that could be fed to the VDI functions u__pline, u__contourfill, u__circle, u__are and u__ellarc. Each set of data had to abide by a special format so that a standard could be developed. In fact, the program isn't limited to drawing flags. Virtually anything can be drawn as long as the data is in the proper sequence.

In order to develop the format, the VDI functions had to be examined. For example, to draw one or more lines, the function u__pline was used. The u__pline function is used to draw lines in connect-the-dots fashion. When you call u__pline, it expects three arguments: the workstation handle, the number of coordinate pairs to be connected by lines and the address of an array. The array contains the actual coordinate data. Please note that the workstation handle is not related to drawing and is therefore not needed in the flag data.

Knowing where we want to draw our lines is not enough, we must also tell the program which color register to use and the value to assign to the register.

At this point, I think an example is in order. The line that follows is a properly formatted data sequence for Flag Trivia:

NEW, 5, 1000, 0, 1000, 4, 50, 40, 58, 32, 66, 40, 50, 40

Believe it or not, this sequence draws a purple triangle! The first value is a code that tells the program which of the five drawing operations it is to use. In this example, the code "NEW" means that we will be drawing one or more lines with the u__pline function. The actual value of NEW is — 1, but the symbolic name NEW was chosen to make the program more readable.

Next we have the value 5. This tells the program to use color register 5. The next piece of data is 1000. This is the red color intensity of the color. The 0 that follows is the green color intensity of the color. Next we have a value of 1000, which is the blue intensity of the color. As you may remember from art class, the colors red, yellow and blue are called the primary colors. We can create any color by varying their intensities. A value of 1000 equals full intensity. A value of 0 means that the color is not mixed in at all. In our example, the mixing of red and blue produces purple.

The next data item tells the program how many pairs of coordinates are used in the u__pline function. In this case, the value is 4. The program will then use the next eight data items as X and Y coordinates for the lines. It knows to read eight items because their are four pairs. The program multiplies the number of pairs by two and uses that value as the number of data items to be read.

The game is simple. The names of four countries will be shown at the top of your screen, one of which belongs to the flag shown. You get one guess at each flag.

If we now wanted to draw another line on the screen, we can use one of two methods. We could again use the NEW command. But suppose that we would like to continue drawing purple lines. The command I call "MORE" provides this capability. An example of MORE follows:

MORE, 2, 22, 199, 187, 88

Since we are content with purple, the data following the MORE command skips over the color register value. It also skips over the red, green and blue color intensities. All that is needed is the number of coordinate pairs and the X and Y coordinates themselves. The value of 2 represents the number of pairs. The next four items are the X and Y coordinates. The use of the MORE command accomplishes two desirable things. First, it conserves memory because space isn't used up with color register values and their intensities. Second, execution speed is improved because the color register doesn't need to be set.

There are also other commands, including "FILL," "MFILL," "CIRCLE," "ARC" and "ELLARC." The command FILL tells the program to send the data that follows to the VDI function u__contourfill. As most readers know, this function can color a small or large area of the screen quickly and easily. The MFILL command is a shortcut of the FILL command. I call it MFILL to signify that we want to do some More FILLing of the screen, using the same color register and color.

The command called CIRCLE is obvious. An ARC is part of a circle. An ELLARC means that we want to draw an elliptical arc. Elliptical arcs can be used to draw egg-shaped or oval objects. There is also a command called "DONE." This tells the program that the flag is finished and is ready to be seen by the players.