Dock Master

For quite some time I had been thinking about a game in which you had to balance falling things (what a great and clear description!). The first draft was a Christmas game, in which you had to decorate a Christmas tree, being careful not to put too many decorations in one side, as that would cause the tree to loose balance and fall, ruining the holiday for everyone.
But, that was around April, and thinking that it would take me perhaps 2-3 months to finish it, I would end up with a Christmas game in July.
So I started looking for other themes to which the idea could be applied. And in this way, "Dock Master" was born. And it took me almost a year to complete it. Still good for a non-Christmas game.
"Dock Master" is an original game in the line of Tetris, Bejeweled, and Candy Crush. In it, you have to load colorful containers in cargo ships, carefully placing them in the best spot to maximize your score, and to avoid sinking the ship, while collecting bonus scores and trophies.

The game is played in the low resolution (64x32) screen, and the high resolution video memory (12 KB)is used to store 5 images that will be shown during the game.
This images are saved in binary format, and loaded when the main program is starting. This way, the main program is much smaller, as it does not need to include the code to draw the graphics. This is the same approach I used in "Minecamp", "Furious Felines" and "Hippo Teeth".

Besides a disk image with the game, you can also download the manual that includes some tips.


The files in the disk are:
DOCK.BAS The game itself.
SUNK.BAS SUNK1.BAS FAST.BAS FASTER.BAS BALANCE.BAS SORT.BAS INTRO.BAS Programs that draw and save the graphic screens to be used during the game.
SUNK.SCR FAST.SCR FASTER.SCR BALANCE.SCR SORT.SCR INTRO.SCR Files with the graphics created by the programs listed above.
SCORES.DAT Used to store the high scores and badge count.
XF.BAS The X-Filer file manager. Not related to the game.

Source Code

Here is the source of the main program, DOCK.BAS. And below are some explanations on how it works.

Program Structure and routines

Lines 0 to 2: Get the game ready to start.
Lines 3 to 9: Main loop.
Line 10: Drop a container.
Line 20: Calculate the ship's balance.
Line 30: Print current score.
Line 35: Move the loaded ship away.
Line 50: Perfect balance bonus.
Line 55: Speed bonus.
Line 60: Perfect sort bonus.
Line 65: Initialization.
Line 70: Game over and high scores.
Line 85: Detect CoCo model and set palette.
Line 95: Exit the game.


C: Current container's weight from 1 (green) to 4 (white)
G: Container position on the screen while being moved
H: Container position on the screen while falling, position of the ship while moving
BC$: Current container graphic
BF(n), C(n): Buffer of ASCII code background while moving the container. N ranges from 1 to 3
T(n1,n2): What is loaded in each ship's (n2) position (n1). n1 ranges from 1 to 9 (5 is the ship's structure). n2 ranges from 1 to 4 (topmost to bottommost ship)
L(n): Load balance in each ship (n ranges from 1 to 4)
D(n): Number of containers in each ship (n ranges from 0 to 3)
S: Speed meter for bonus
SP: Speed bonus score multiplier
PS: Partial score
BB, BF, BS, BO: Number of Perfect balance, Fast, SuperFast, and Perfect Order Badges
X, Y, L, A: Generic loop counters
NB: Number of badges to be drawn
K$, K: Pressed key and ASCII code
E: ASCII code of the ship's alert light
BM$(n): Strings with the ship being moved. N ranges from 1 to 3 (each line of the ship)
B$(n): Strings with the ship's graphic. N ranges from 1 to 3 (each line of the ship)
L$: String buffer to move ships down after one has left
D: Difficulty level

Other stuff

SUNK1.BAS is the code to draw the Game Over screen using an alternate color palette. When run, it will overwrite SUNK.SCR with the new version.
This is done because, even if the original color palette looks usually better, in some emulators - and perhaps some real hardware combinations - looks very bad. In those cases, the alternate color palette will probably look better.
If a CoCo 3, the color combination of all screens has been optimized.