A downloadable game

ROUTE81
=======

BASIC 10-Liner videogame for the Sinclair ZX81
==============================================

Marco Varesio ([Marco's Retrobits](https://retrobits.itch.io/))
[English language blog](https://retrobits.altervista.org/)
[Italian language blog](https://somebitsofme.altervista.org)
[YouTube channel](https://www.youtube.com/channel/UCWTxG8paNsOUEU5mPcNklXA)

ROUTE81 is an action game for the Sinclair ZX81 8-bit home computer. 
It is my second entry to the 2021 edition of the BASIC 10 Liner Contest.
The game has been entirely coded in BASIC language and the program is 10 lines long.
Drive your shiny sports car `*` along the most iconic highway in computer history! 
Avoid the other cars `o` and going off the road.
Controls: steer your car with "o" (left) and "p" (right).

Gameplay video:

Play online: https://somebitsofme.altervista.org/rm-rf/site/?p=emu/jtyone&l=2&tzx=emu/soft/zx...

Program description
===================

The player's car occupies the top line of the screen, while the road and the other cars 
scroll up by one line at each iteration of the main game loop. 
Whenever the scrolling occurs, a new road segment (with random horizontal displacement from the previous one) 
and a new opponent car (at random horizontal position within the road segment) are printed at the bottom of the screen. Then the player's car horizontal position is updated based on the pressed key and printed and collision check is performed.

Variables
---------

R: Road segment horizontal position
X: Player's car horizontal position
C: Collision detection

Program listing
---------------

The program is 10 lines long and each line is shorter than 80 characters. 
The most challenging aspect of ZX81 BASIC programming is that the interpreter only allows one statement per line.
In the following listing, which can be used with the ZXText2P tool to make a ".P" file suitable for loading into X81 emulators,
block graphic characters have been replaced with the corresponding escape sequences made up of standard characters.
Therefore, the program looks longer than it actually is. See the ZXText2P documentation for details:
http://freestuff.grok.co.uk/zxtext2p/index.html

1 LET R=11
2 LET X=R+2
3 PRINT AT 21,0;"\.'\.'\.'\.'\.'\.'\.'\.'\.'\.'\.'\.'\.'\.'   \'.\'.\'.\'.\'.\'.\'.\'.\'.\'.\'.\'.\'.\'.\'."
4 LET R=R+(R<20)*RND-(R>2)*RND
5 SCROLL
6 LET X=X+(INKEY$="P")-(INKEY$="O")
7 PRINT AT 21,R;"\##       \##";AT 21,R+1+RND*6; "o";AT 0,X;
8 LET C=(PEEK(PEEK 16398+256*PEEK 16399)<>0)*105
9 PRINT CHR$(23 + C)
10 GO TO 4 + C*10

Source code explained
---------------------

Initializations

The first two lines initialize the road segment horizontal offset R and player's car position X.
Line 3 prints the "start line" at the bottom of the screen.

Game loop

Line 4 calculates the position of the next road segment to be printed, with random displacement from the previous one. 
The program also ensures that the road segment stays within the screen, i.e. the left side of the road segment stays within columns 2 and 20.
Line 5 SCROLLs the display up one line.
Line 6 calculates the new player's car horizontal position, depending on the pressed key. 
If "P" is pressed, the car moves right; if "O" is pressed, the car moves left. 
Line 7 prints at the bottom of the screen (row 21):
* the new road segment at the previously calculated horizontal position R;
* a new opponent car, at a random position within the road sides.
Finally, it sets the print position to the new player's car position.
Line 8 performs collision detection, by reading the value at current print position 
(which corresponds to the new player's car position as effect of the last AT in line 7) in the display file, 
by means of the DF_CC system variable. 
A collision occurs whether the position in which the car will be printed contains a character different than space 
(whose character code is 0); in this case, C is set to 105. Conversely, if there is no collision, C is set to 0. 
C value meaning will be clear by looking at the next statements.
Kudos to [kmurta](http://zx81.eu5.org/) for pointing out that DF_CC system variable can be PEEKed in order to determine what character is  displayed at a particular print position.
Line 9 prints the car at the print position set in line 7, i.e. vertical position 0 (top line) and horizontal position X calculated in line 6.
If a collision occurs (C=105), the printed character is the full block, whose code is 23 + C = 23 + 105 = 128. 
Otherwise, if there is no collision, the printed character is "*", whose code is 23 + C = 23 + 0 = 23.
If no collision occurs, line 10 jumps back to the beginning of the game loop at line 4; 
otherwise, in case of collision, the program jumps to a non-existing line, causing the program to exit with code 0.


Enjoy your drive!

StatusReleased
Rating
Rated 5.0 out of 5 stars
(1 total ratings)
AuthorBASIC 10Liner
GenreRacing
Tagsbasic, basic10liner, sinclair, zx81

Download

Download
ROUTE81.p 1 kB
Download
ROUTE81.pdf 178 kB

Install instructions

Loading instructions ====================

ROUTE81 requires a real or emulated ZX81 with at least 4k RAM Pack expansion. 

EightyOne emulator ------------------

The following instructions apply to the EightyOne emulator. Go to "Options" -> "Hardware..." and make sure that ZX81 with 4k RAM Pack is selected. Open "Tools" -> "Tape Manager..." and ensure that automatic loading options are selected. Select “Open Tape…” from the “File” menu to locate and load the **ROUTE81.p** file.  In the next seconds, if the emulator is configured in order to automatically load tape images, you should see something happening on the screen and finally a white screen with only the `0/0` message on the bottom.  If nothing happens, you must manually start tape image loading, by tapping the "J" key followed by "SHIFT" + "P" twice.  You should see the `LOAD ""` message followed by a a black cursor. Press "ENTER" to start loading. To run the program, tap the “R” key. You should see `RUN` followed by a black cursor on the bottom of the screen. Finally, press "ENTER". To list the program, tap the “K” key. You should see `LIST` followed by a black cursor on the bottom of the screen. Finally, press "ENTER".

JtyOne Online ZX81 Emulator ---------------------------

Alternatively, if your web browser supports Javascript, you can play directly in your browser (powered by JtyOne Online ZX81 Emulator). Just follow this link: https://somebitsofme.altervista.org/rm-rf/site/?p=emu/jtyone&l=2&tzx=emu/soft/zx...  and then press "R" followed by "ENTER" as previously described.

Leave a comment

Log in with itch.io to leave a comment.