Last month, I shared an old moon landing program I wrote back in the early 80s. Right after that, I decided to give it a bit of a face lift, updating the visuals without changing the game play. Moon Lander v2 is my updated game, yet still the same BASIC code under hood.
A fun new look.
As I noted last month, Moon Lander had some visual flaws and glitches. The most offending was the way the lander flickered. This version does its best to improve that by reworking the way the screen is cleared. This allows for a more fluid movement, without eliminating the blocky charm of this 8-bit game.
Perhaps the most striking change is the the new fuel and speed bars. Although kind of in the first game—having some minor routines in code, it didn‘t effect the game play. This time, full is an integral part of the game. Each time you use a thruster, you eat a little bit of fuel. As you do, the fuel gauge will slowly shrink until you are empty.
Below the fuel, I removed the slow printing speed and replaced it with a bar. This bar will grow as you accelerate, chasing the graphic when you are too fast. Should you need to reverse course, the graphic will change to a thin line, indicating you are moving up. This display is much faster, and smoother, than the numbers from the previous game.
The last visual change was to fix the landing zone. It is now a different graphic to make it easier to see amongst the rocks. I know, you won't find nice landing pads on the moon, but games need to take some liberties for the the sake of play.
More fun to play.
Beyond the visual changes, the game sports better gameplay. The speed of the new look helps improve the overall responsiveness of Moon Lander. The variability of the landing zone made each attempt unique. If the landing pad was too far right or left, it required some strategy to get to it without running out of fuel or crashing into the ground.
I also added in some nice quality of life features. After landing or crashing, Moon Lander now tells you want to do next after print the score. It leaves your fuel and speed on screen for reference. And, unlike the first version, your lander will actually crash and looked destroyed.
Although these are minor cosmetic changes, they help to unify the feel of the game and make it complete. It isn’t a huge change in game play, but does feel more polished.
Still a short program.
Even with the cosmetic change, the program didn’t grow too much. In fact, Moon Lander v2 uses less memory on run due to the removal of the large array in the first game. Those visuals did require changing things.
The biggest change is the print routine. In the first version, all the visuals were in two lines:
131 PRINT AT 0,0;C$;AT 0,0;
140 PRINT AT X,Y;A$;AT X+1,Y;B$
The first line clears the screen using the C$ array and prints the speed held in SP. The second prints both halves of the moon lander, A$ being the upper and B$ the lower. It is straight forward and works, but is also the reason for the flickering. The
STR$ SP didn’t improve how fast the ZX81 printed the number in SP. It was still slow.
The new routine is much larger, now encompassing four lines, but also faster. Let’s take a look at that code.
132 PRINT AT X1,Y1;C$;AT X1+1,Y
1;C$;AT 0,1;"FUEL:";F$( TO F/4);
" ";AT 1,0;"SPEED:";
133 IF SP<=0 THEN PRINT T$( TO
134 IF SP>0 THEN PRINT S$( TO S
140 PRINT AT X,Y;A$;AT X+1,Y;B$
Okay, the first line, 132, does much of what line 131 did in the first version of Moon Lander. It clears the lander using C$, which is now only two spaces. Here, I have the previous position of the lander in X1 and Y1, something I didn’t track before.
In Moon Lander v2, you can see that I then print the fuel graphic in F$ using a simple string slice. You’ll notice I divided the fuel value in F by 4. I did that to keep the graphic relatively small and to not shrink every turn. I position the speed graphic, but that one required some extra work.
Lines 133 and 134 are used to print the speed. Since you could be accelerating up or down, I decided to break that out. If you are going up—speed less than or equal to zero, it prints the graphic in T$. If you are going down, it prints your speed in S$. Like the fuel, it is a string slice using a bit of math to keep the bar on the screen.
The last line, 140, is the same in both versions. Those couple of lines encompass the majority of the changes between the two games. Taking a different approach, really improved the visuals without adding a ton of code.
Working with fuel.
Of course, the big add was including fuel into the game. In the original game, the only place I had fuel was in line 191, where I test if you ran out. Funny enough, I didn‘t decrement it anywhere, so this line doesn’t do anything. If it did, the
GOTO would drop you into the crash routine. That would have been jarring to end the game with your moon lander still in the air. Obviously, I didn’t really have that worked out quite yet.
191 IF F<=0 THEN GOTO 250
In Moon Lander v2, I decided to put in the effort to make fuel a thing. To make fuel work, I had to add in one line, but rework and rearrange things to make it work. Here are the first few changes.
144 IF X$<>"" AND F>0 THEN LET
145 LET SP=SP+.2
146 IF F<=0 THEN GOTO 170
Line 144 basically decrements the fuel amount in F if it is greater than 0. That line sums up the biggest change from the first game. Now, line 145 wasn’t directly in the first game. Instead, I added .2 to the the speed variable in SP as part of checking if the player pressed the M key. This wouldn’t work in v2 because because of another change.
Line 146 looks similar to 191, but they are subtlety different. First, I moved the routine up in the code before I make changes to the moon landers position. Which leads to the second change. The
GOTO 170 skips over any attempts you made to move if you are out of fuel. This has the effect of the game finishing without you. If you were close to landing, and slow enough, you could theoretically successfully land. In practice, you will likely crash.
Minor tweaks to finish things up.
The rest of the code is just minor tweaks. I added in the lines to capture the moon lander’s position, updated the print routines, and adding in the continue functions. A subtle tweak was done in the scoring code. In the original game, you basically started over if you crashed or not. In the new version, your score adds up as long as you successful land.
210 LET S=200-T+200+F
Versus Moon Lander v2:
210 LET S=S+200-T+200+F
I have a feeling it was an oversight on my part, since the routine doesn’t reset the score. Both versions jump to the line 30 where the speed is reset. Funny that although fuel wasn’t implemented in Moon Lander, it was still used in the score.
Time to land.
And there you have it. A second version of Moon Lander that improves the visuals, but doesn’t alter the game play that made the first one fun to play. Now that doesn’t mean it is perfect or couldn’t be further improved. Given my new found z80 assembly skills, I could expand upon the game and make it a lot more fluid and dynamic. Until then, enjoy playing Moon Lander v2.