I've made a one liner - called Line

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
patters
Dizzy
Posts: 52
Joined: Thu Apr 11, 2019 12:06 am

I've made a one liner - called Line

Post by patters » Sun Jul 28, 2019 11:38 pm

A game about a line, written in a single line of BASIC code

I've been fascinated by Digital Prawn's One Liners since discovering them recently. I was compelled to take up the challenge, and have created my own game, called Line:

Image

I notice that things have been a bit quiet for the last decade on the one liners front - anyone else fancy having a crack at one?
10 x
25 years in the making: Artillery projectile motion simulation
20 years in the making: Line a one line arcade game

User avatar
Alessandro
Manic Miner
Posts: 509
Joined: Wed Nov 15, 2017 11:10 am
Location: Messina, Italy
Contact:

Re: I've made a one liner - called Line

Post by Alessandro » Mon Jul 29, 2019 9:14 pm

Nice! I managed to get to level 10 on my first go.

Out of curiosity, why didn't you make the game run upon loading?
0 x

User avatar
patters
Dizzy
Posts: 52
Joined: Thu Apr 11, 2019 12:06 am

Re: I've made a one liner - called Line

Post by patters » Mon Jul 29, 2019 10:46 pm

A solid first go! I set the max level at 20 mainly because it seems within easy reach enough to hook the player a bit more. However, the escalation in difficulty is quite rapid. The aim is for it to be a digital equivalent to one of those wire loop dexterity tests. Just one more go, I know I can do it this time...

I did just try it on my real Speccy for this first time and unfortunately the blue line is really hard to see compared to on the emulators. Not ideal.

Regarding not saving with LINE 1, I was following what seems to be the convention of those other one liners on Digital Prawn's site. Since you have to keep typing RUN anyway, I figure it at least gives people a chance to see the listing before the colours get changed. That is the focus after all.

I find this format forces clean design. That Connect 4 game on Digital Prawn's sits is so elegant, a real marvel.

There are two features from my original version of this game that I had to drop to fit within the one liner constraints - multiple lives in a game, and better sound effects for dying and game over. Now I'm already wondering if I can get the lives back in. It's quite addictive, optimising over and over.
0 x
25 years in the making: Artillery projectile motion simulation
20 years in the making: Line a one line arcade game

User avatar
R-Tape
Site Admin
Posts: 2591
Joined: Thu Nov 09, 2017 11:46 am

Re: I've made a one liner - called Line

Post by R-Tape » Tue Jul 30, 2019 10:26 am

It certainly does have that 'just one more go' factor. Surprisingly fun game.
patters wrote:
Sun Jul 28, 2019 11:38 pm
I notice that things have been a bit quiet for the last decade on the one liners front
Aye - there is a ZXDB on-liner group, and there's only been 1 of them since Prawn's, Einar's and DrBeep's heyday.
- anyone else fancy having a crack at one?
Not me! I'm not averse to certain kinds of coding challenge, but the thought of doing a one-liner gives me the heebeegeebies! Happy to admire what you guys achieve.
0 x

Joefish
Manic Miner
Posts: 634
Joined: Tue Nov 14, 2017 10:26 am

Re: I've made a one liner - called Line

Post by Joefish » Tue Jul 30, 2019 10:41 am

I find it horrendous enough not having an 'ELSE' keyword in Sinclair BASIC, never mind having to code an entire game with non-branching logic.
0 x

User avatar
patters
Dizzy
Posts: 52
Joined: Thu Apr 11, 2019 12:06 am

Re: I've made a one liner - called Line

Post by patters » Tue Jul 30, 2019 11:31 am

Joefish wrote:
Tue Jul 30, 2019 10:41 am
I find it horrendous enough not having an 'ELSE' keyword in Sinclair BASIC, never mind having to code an entire game with non-branching logic.
Agreed, having to repeat the condition and resort to GOTOs is so annoying .

There is a secret weapon though once you start peeling apart the examples - POKE 23620,x (the sysvar named NSPPC) which jumps execution to statement x within a line. Since logic operators are evaluated inline you can retain very complex control, for example from Labyrin3D:

Code: Select all

POKE (p+z<i)*23620,8+9*o*(q<i)*(c>1):
So this is only going to apply the POKE if a certain conditions are met, and even then its outcome depends on a host of other variable states.
Another trick of the trade is using READ and DATA to define and calculate variables instead of LET since they can be combined (e.g. READ a,b,c,d,e,f)

There is one slight edge case to my game. In order to keep the action reasonably fast I DRAW the line in increments of two pixels rather than PLOTing each point. Since the attributes are only checked every two pixels of line it's possible for the line to clip across the corner pixel of an obstacle and turn it blue without a collision. A necessary design compromise though...
1 x
25 years in the making: Artillery projectile motion simulation
20 years in the making: Line a one line arcade game

User avatar
Einar Saukas
Manic Miner
Posts: 949
Joined: Wed Nov 15, 2017 2:48 pm

Re: I've made a one liner - called Line

Post by Einar Saukas » Tue Jul 30, 2019 4:23 pm

Good job!
patters wrote:
Mon Jul 29, 2019 10:46 pm
There are two features from my original version of this game that I had to drop to fit within the one liner constraints - multiple lives in a game, and better sound effects for dying and game over.
A few easy tips to make it shorter:
  • Initializing variables using READ/DATA doesn't always make it shorter. In your case, eliminate variables 'a' and 'b' (use these values directly in your DRAW statements) to save 4 characters.
  • Sometimes simple Math changes can save a lot. For instance, replace this:

    Code: Select all

    FOR x=10 TO 250 STEP 2: ... INT (x/8)
    with this:

    Code: Select all

    FOR x=5 TO 125: ... INT (x/4)
  • Don't use parenthesis unless really necessary. For instance, you can save 2 characters replacing this:

    Code: Select all

    LET k=(4*(INKEY$=" "))-2
    with this:

    Code: Select all

    LET k=4*(INKEY$=" ")-2
    although I think it would work better like this:

    Code: Select all

    LET k=4*(INKEY$<>"")-2
    This way, users would be able to play the game using whatever key they prefer.
2 x

User avatar
Einar Saukas
Manic Miner
Posts: 949
Joined: Wed Nov 15, 2017 2:48 pm

Re: I've made a one liner - called Line

Post by Einar Saukas » Tue Jul 30, 2019 5:55 pm

After eliminating variables 'a' and 'b', you can save another 8 characters replacing this:

Code: Select all

FOR n=0 TO 1: PLOT 1+n,6+n: DRAW 0,163: DRAW 248,0: DRAW 0,-163: DRAW -248,0: NEXT n: PLOT 250,6
with this:

Code: Select all

PLOT 2,170: FOR n=0 TO 1: DRAW 248,0: DRAW 0,n+n-164: DRAW n+n-249,0: DRAW 0,163: NEXT n
0 x

User avatar
Einar Saukas
Manic Miner
Posts: 949
Joined: Wed Nov 15, 2017 2:48 pm

Re: I've made a one liner - called Line

Post by Einar Saukas » Tue Jul 30, 2019 6:12 pm

Another optimization is to allow Sinclair BASIC to round numbers for you. For instance, instead of this:

Code: Select all

INK INT (RND*4)+4
use this:

Code: Select all

INT RND*4+3.5
There are several places in your program where you can use this kind of trick.
0 x

User avatar
Einar Saukas
Manic Miner
Posts: 949
Joined: Wed Nov 15, 2017 2:48 pm

Re: I've made a one liner - called Line

Post by Einar Saukas » Tue Jul 30, 2019 6:20 pm

Instead of this:

Code: Select all

FOR n=9+(l>9) TO 12-(l>9): PRINT AT n,31; INK 0;" ": NEXT n: PRINT AT 0,0; INK 3;"LEVEL ";l
use this:

Code: Select all

PRINT INK 3;"LEVEL ";l: FOR n=9+(l>9) TO 12-(l>9): PRINT AT n,31; INK 0;" ": NEXT n
0 x

Post Reply