Adios, Amoebas!: Technical stuff
This game has pretty much the same structure as most of my other Java games.
There is a single thread that controls all the animation and updates the
screen once every 75 milliseconds or so. It's only the structure of the
offscreen image buffer that really needs an explanation.
As you may know, there are two ways of drawing "chunks" of graphics in
Java. The most common one is drawImage. The other one is
copyArea. While the latter is less powerful, does not preserve
pixel transparency and can only copy from one place to another within
the same image, it is also slightly faster. It's the speed advantage
that motivated its use in this game.
All the image "building blocks" which don't need transparency (unlike the
player and the moving amoebas), have been placed at the bottom of this
image buffer (area number 3). There are 27 building blocks altogether.
The playing field is built and updated by having such blocks copied onto
area number 2 when needed. In each animation loop, the entire area 2 is
itself copied onto area number 1, on which possible moving objects are
drawn. That area is then drawn on the screen. This creates smooth
animation at a relatively low cost. (Of course, the small
size of the applet area also helps.)
To keep track of what's going on in the field is an array of integers.
The lowest 8 bits contain information about objects and such. (If bit 0
is set, the player is (at least partly) standing on the corresponding
tile. If bit 1 is set, there's an amoeba on it. Bit 2 means a moving
weight. Bit 3 means the tile is flipping around, etc.) This is used for,
among other things, determining where to flip objects in or out. A counter
variable sweeps the board one tile per animation cycle. If it finds an
empty tile (no object, amoeba or player), a random number is within
a given range and a few other conditions are satisfied, a new object gets
The top bits contain, where applicable, information about when the player
was last standing on that tile, and in which direction he left. This
works as a "scent trace" the amoebas can use to "smell" where the player
is going. If the player has been on an amoeba's tile less than approximately
5 seconds ago and a random number falls within a specific range, the amoeba
will follow this trace. The higher the level, the more likely this is
to happen, and the more intelligent the amoebas will appear.
Amoebas can also change directions if they find a clear, horizontal or
vertical path to the player. This too is more likely to happen on