Okay! Now for the part of the documentation that makes the game come to life. Programming docs are not light reading--and the next several paragraphs are some of the most significant to the game engine.
Background tiles are just opaque sprites (all with 16x14 size) drawn in a grid
formation. A two-dimensional array (the primary grid) provides the
look-up entries that index these sprites. It is relatively easy to draw the background; a nested for loop is all you really need. Of course, I had to
optimize the drawing routine for speed, which made the actual programming more
complicated than just a few for loops.
The 16x16 size of a grid square is synonymous with the 16x14 size of the opaque sprite. If I get a 640x480 video mode version of Nibbler up and running, the graphics will measure as 32x32; no changes to the coordinate system will have to happen in NIB-OOL for a change in video mode.
All objects have a variable that allows them to display at most one free sprite
each. Free sprites are not fixed to a grid formation; rather, they are defined by
the individual object's x and y coordinates (high-order 16 bits only). Even if
sprites are partially or totally off-screen, they will be clipped along the sides
of the screen automatically. Sprites are center-based (oriented as if the
objects' x and y coordinates formed dots in the center of the drawn sprites).
Some objects have their flags set to +P. This means the sprite is
palette-changed. In other words, each 256-color entry is swapped for
another in a table as the sprite is drawn on the screen. The sprite can be
changed to 13 different color schemes, indexed by the object's pal
variable. A few colors are designed to remain constant despite palette
changes (such as the polka dots on the back of the snake).
If the flags variable has +S, the sprite is drawn as a solid color. The pal
variable now represents a color (0-256) to which to change the entire sprite.
Individual colors are composed of one of about 16 different shades with a choice
of several different hues.
In addition to palette changes, sprites may undergo other transformations.
The sprite variable is composed of three parts: the sprite index, the horizontal
flip flag, and the vertical flip flag. Setting the flip flags will
mirror the sprite horizontally or vertically. Note that these flags do not
rotate sprites. Rotation of free sprites is not implemented in this game
engine.
In addition to the background and free sprites, there are more simple drawing
protocols. Text display is very simple. Fonts are grabbed in an application
similar to GET.EXE. Of course, fonts don't require the storage of individual
pixel data. Instead, each point in a letter/number/character fits into an
individual bit of a character matrix. There is plenty of documentation
for character matrices available, so I won't go into details as to how
they work. I will note, however, that the BIOS functions that display text in
graphics modes are woefully inadequate for the purposes of most computer games.
You can see in the image above that the status bar has long lines
of repeated colors. A few simple functions (once again, for loops are all
that are needed) can be used to take a thin "wedge" sprite and use it to paint a
window border. Look at the windows borders used in the application you're using
to view this! Can you make out what the wedge sprite is, and which direction the
painting cursor uses? It isn't hard at all to draw window borders.
The next page contains the black magic of Nibbler's display engine.
It gets pretty technical. You were warned.