Wandering Down the ZX81 Road


An infinite road program that has a few curves.

I had this idea on Sunday that led to today’s program—more about that in a minute. One of those sit down and do it programs, I banged this out pretty quick yesterday. Not wasting time, I decided today I’d share it. Road is a very simple program that I never intended to make. But here it is, so lets talk about it more.

# It started with an idea.

On Sunday, I was trying to talk myself into setting a goal to finish my Gem Quest game. I sat down and just wrote a journey entry explaining how I would do that. While playing Destiny, I was thinking about how I work to complete quests. The quests aren’t very different and are sometimes tedious, but I get them done. My mind asked, why?

The answer is reward. Each task in isolation may be a pain, but the idea of completing one after the other has appeal. I know my progress. I know how much I need to do. Together, it gives me a goal that is measurable and I can strive to accomplish it. That begged the question, why can’t I do that with my program? The short answer is: I can!

To that end, my journey entry was all about how to gamify my development goals. I wrote down each of the different tasks I still needed to complete. I have each world, some play tweaking, optimization and play testing. I then broke each of those into sub tasks that I would then work on. The intent is that I would then give myself badges or points as I accomplished them.

Now none of that directly gets me to this program, but it prompted another tangent of thought. I had in my mind some sort of road that would include each badge as I completed a task. The thought was this would be my journey to completing my game. I went to bed with that thought in my head.

# A game within a game.

Now, the idea of a journey made wasn’t unique to me. I’d built slides for work depicting a journey or story to get from a current state to a desired future state. Doing this, albeit in a gamified manner, for home wasn’t too out there. But, my mind started to think about those badges.

Now, I was thinking of using prebuilt software or applications to help gamify my task list. Dwelling on the badges, I thought I’d make some sort of 8-bit version of them. It is something I like to do. Thus, the reward for finishing each major task would be to create a badge for that task.

Of course, given Gem Quest is a ZX81 game, I thought about how that would look. The idea that came to me was to create some sort of road that I could display the badges along. The idea of a scrolling, curving road running on my ZX81 entered my mind and consumed my sleep. This is not how you should program, but hey.

# Building a road to nowhere.

Now, the next day, Monday, I still had my gamify idea in my head along with that ZX81 road. During my run that day, it crept into my thoughts. My mind mulled over how to create that road. To my surprise, the code just kind of appeared to me. It wasn’t complex or even that interesting, but it seemed workable.

That evening, burnt out on email and other activities, I told myself I should just write that code down. Not quite committed to how I would enter the program, I found myself futzing around with the JSzeddy emulator. I threw caution to the wind—as every good program should do, and just decide to write Road in BASIC.

I tried to organize the code bit from what was in my head, but otherwise the ideas were from my run. I had the thought or printing a road with stripes. Easy enough. The challenge is I wanted to curve my roads, but not like a racing game. I wanted to arch them out and back.

The code to do that was simple, I just use a variable (in this case Z) to hold the random direction. This is translated into a left curve, straight, or a right curve. I just create a random number between 1 and 3 and subtract 2 to get: -1, 0 and 1. Now, I could have just used the 1-3, but I thought the numbers better conveyed what road direction.

With that done, I then created three IF statements that would add or subtract to bend the road. Now, looking back on the program, I could have used the Z variable and simplified this to one statement. But the program works and I did have to do some tweaking to get the right curve to look better.

The next step was to print the road and scroll the screen. I cheated and used another boolean check to decide when to paint the median line. With that done, I ran the program and, to my utter surprise, it worked. No real debugging or such. As noted above, I did have to tweak some math for the right to bend better. Other than that, it just ran.

# Bridges or curves?

The final program works as I envisioned it, but the curves weren’t quite as subtle as I had in my head. Watching the program run, the curved roads started to look more like little bridges. I mused over that for a bit, decided if I should tweak the routine. In the end I liked the effect and let it alone.

Road, ZX81 Screenshot, 2022 by Steven ReidRoad, ZX81 Screenshot, 2022 by Steven Reid

Now, with the program running properly all that was left to do was some minor clean up. I decided to make the median line one of the hatched or grey blocks. That looked better and added some depth. I threw in a save routine and I was complete.

Next steps were simply to copy the text from JSzeddy to my mac. I ran my bin2hex.pl script and I had a working ZX81 program. I was done for Monday. I ran it, shared with my wife, and went to bed.

Getting back to my program tonight, I thought it would be perfect to just write about it now. This saves me waiting until the end of the month to write my article. Plus, I have a lot going on at work and don’t to be in a rush at the end of the month.

To finish the program, I followed my normal routine of copying it into an EightyOne on an older Mac that I can still run 32bit programs on. I saved a screen shot along with a tape (.tzx) version of the program. I copied all that to my laptop, converted and compressed the picture, and wrote this article. All in all, a nice way to spend a couple of hours.



Comments on this article:

No comments so far.

Write a comment:

Type The Letters You See.
[captcha image][captcha image][captcha image][captcha image][captcha image][captcha image]
not case sensitive