I painted more borders on the ZX81 than just about any other shape. An easy way to confine movement, it shouldnt come as a surprise that Electon starts by building a box. And before you ask, this months ZX81 program isnt another version of snake. Instead, you use the Z, X, N, and M keys to move in an attempt to capture the Electon. Sounds easy? Better give it a try and see.
That things active.
Ah the elusive Electon. Im not sure where the little inverted asterisk got its nameperhaps I just forgot the r in electron. Yet, it is apt. The energetic particle bounces around, making it difficult to contain. Thats where you come in.
You have the ability to create a trail of dark energy that you can use to try to contain it. As with all energy, you cant touch it or youll crash. Fortunately, youre not forced to movewhy I said this isnt snake. Take your time as that Electon can be a bit of a pain to catch.
I find it best to just move out and try to wall it in. But, as you'll learn, the Electon moves faster than you. In fact, it can leap over your energy field to safety. Because of this, it pays to keep your distance. I recommend constructing double walls in a attempt to corner the renegade particle.
As you progress in the game, you might be surprised how it can be both frustrating and easy. Written in 1983, there is a duality to it that comes from my early experimentation. Yet, if youve looked at my other games, its also foundational. Setting that aside, lets dig deeper into Electon.
Bad movement keys.
On purpose I didnt tell you what direction the keys took you. Instead, I wanted you to experience the frustration of movement that doesnt match expectations. The Z and X keys move you up and down respectively. If you found yourself crashing a lot, I can relate. The combination took me several games to overcome. But why?
For one, its not intuitive. Moving vertically using horizontal neighboring keys is hard to relate to. Had I used A and Z instead, I doubt you or I would have had any issues. For another, most gamers are so used to the WASD that anything else is just, well, weird.
I must have figured that out at some point as later games used either the ZX81 arrow keys or the AZ combination I mentioned earlier. Although unintentional, and forgivable for a game from the earlier 80s, I was surprised at how difficult it was for me. If I changed anything, this would be the first.
Im somewhat mixed on the second issue. If you sit still, it may surprise you that you can still capture the Electon. Perhaps I should also state that it can crash into you as well, so some about of cation is warranted. But that same logic is also what makes the game fun. Let me explain.
You see, the fun of the game is the chaotic movement of the Electon. The bouncing around is caused by the following code:
125 FOR L=1 TO 3
130 LET Y1=Y1+(INT (RND*3-1))
140 LET Y2=Y2+(INT (RND*3-1))
145 PRINT AT Y1,Y2;
150 LET P=PEEK (PEEK 16398+256*
151 IF P=0 OR P=151 OR P=8
THEN GOTO 160
152 NEXT L
153 GOTO 300
Lets walk through that code. Line 125 starts a loop using the L variable. The loop will go three times, unless we exit early as well see in a minute. Basically, our little asterisk gets three changes to move.
Lines 130 and 140 are where Electon gets its bounce. Note that ZX81s
RND function generates a real number between 0 and 1although not 1 itself. So, multiplying it by 3, subtracting 1 and then using
INT to turn it into a whole number yields -1, 0 or 1. The asterisk will either move, or not, each loop.
Lines 145151 decide if the Electon hit anything unimportant. In this case, it checks if the square it will occupy is a space, itself or you. If so, it breaks out of the loop and moves there. Note that at this point, if that square is you, its game over.
Now, the fun part. Line 152 continues the loop and, if after three moves of not finding a space to land in, line 153 takes you to the score screen. The energy wallthe inverted spaceis considered an occupied space that it cant move into. The intent was for you to corner it with your energy wall. But there is a problem.
You see, I forgot to reset the previous movement in lines 130140. So, each loop is additive, meaning Electon can move more than a single space each time. On hand, this is great. It makes the game a lot more fun as the particle can leap around unexpectedly.
Yet, even if I fixed that I have a second issue. Given the movement is completely random, it is very possible that it will try to move into the same space each time. Thus, it is possible to capture the particle with only one block next to it. Not my intent, but fixing that is more difficult. Do you see a way?
Iterative programming at its best.
Instead of talking about all the flaws in the codeyou can find those on your own, I want to focus instead on my development process. My coding then, much as it is today, wasnt linear. Id try something, run the program to see what didnt work, and then adjust. In simple terms, I can sum up the sequence as follows: code, test, iterate.
The evidence of my process is quite visible in Electon. It was right there in the first few lines. The border routine, lines 2023, were clearly added after the fact. I mean, come on, I added it right in the middle of declaring your starting locationlines 20 and 30.
10 LET S=0
20 LET X1=1
21 FOR A=0 TO 21
22 PRINT AT A,0;"_";AT A,31;"_
";AT 0,A;"__________";AT 21,A;"_
23 NEXT A
30 LET X2=15
The same thing can be seen in the earlier code snippet. Normally, I wouldve cleaned this up before printing. But this program predates that process. The original printout is even missing the comment line. I added that from the hand written title on it.
Now, this isnt bad, just more visible in BASIC. The reason most people number programs by 10 is to give themselves room for just this sort of thing. But lets be honest, this isnt Agile. And, at 13, I didnt caring about software development process. Nope, I was just doing what worked. And that, my friend, is finefor this kind of work.
But, dont take that to mean I dont believe in process. I do. Consistency can be very valuable in improving speed and supportability. I also believe in automation and letting the computer do repeatable tasks that I otherwise would have to do. Yet, its just a tool and not an absolute. Personally, Im always swinging that pendulum, trying to find that balance.
Hey, isnt this on your main site?
Why yes, it is. Five years later, Im close to merging my sites back together. When I broke my ZX81 site out in 2011, it was because it was a separate site on Geocities. Yet, Yahoo forced my hand.
My original plan was to have a single blog shared across sites, but I found it difficult. Ive never been satisfied with the arrangement and recent issues are fueling my desire to bring them back together. Its not super high on my priority list, but I expect it will happen before the end of the year.
Yet, dont fret. Ill make sure it all redirects when I pull the trigger. Until then, Ill continue to cross post articles for those that are still linking to the sub-domain.
Originally published at www.reids4fun.com on August 22, 2016.