This time a minimalist version of the well-known game Breakout. I set myself the goal to see whether it is possible to make this in a maximum of ten lines Commodore Basic. Of course, it will not be a full version just a nice try. I wanted to have several minimal game elements in it such as:
- Colour bars
- A bouncing ball
- A paddle to bounce the ball
- Something for keeping score
It is precisely with these components that I have built up the program step by step. Below first the long version with comments and not shortened commands so that it remains readable.
Then the shortened version to 10 (oops still 11) lines. Although I do get to 10 lines if I were to use the PetscII characters, but I haven’t used them here to keep typing and readability simple.
To move the paddle the key “1” (left) en “2) right can be used.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
100 rem ---------------------------------------------------- 110 rem initialization of variables 120 rem ---------------------------------------------------- 130 pp=17 : rem paddle start line on screen 140 sm=1024 : rem screen memory start 150 sa=sm+(22*40) : rem screen boundary adress range 160 dx=1:dy=1 : rem initial direction of bouncing ball (positive) 170 x=int(rnd(1)*24):y=12: rem ball start position with random x position 180 c$=chr$(28)+chr$(149)+chr$(158)+chr$(30)+chr$(31) : rem define color values 185 1 = 1 : rem used to reverse ball on missed and last key direction 188 h = 0 : rem hit score variable 190 rem ---------------------------------------------------- 200 rem initialisation of screen start and color 210 rem ---------------------------------------------------- 220 poke 650,128 : rem set key input on repeative 230 poke 53280,0 : rem screen border color to black 240 poke 53281,0 : rem screen color to black 250 print chr$(147): rem clear screen and cursor to top 260 rem ----------------------------------------------------- 270 rem draw five color lines with eight bars 280 rem ----------------------------------------------------- 290 print : rem print blanco screen line on top 300 for p=1 to 5: 310 for n=1 to 8 320 print chr$(18)+mid$(c$,p,1)+chr$(229)+" "+chr$(234); 330 next n 340 next p 350 rem ----------------------------------------------------- 360 rem Start main loop (paddle and bouncing ball) 370 rem ----------------------------------------------------- 380 sp=sa+pp : rem calculate start position of paddle 390 rem -------------------------------------------------------------- 400 rem poke the paddle characters into memory on calculated position 410 rem start and end with space (32) to clear previous on movement 420 rem -------------------------------------------------------------- 430 pokesp,32:pokesp+1,98:pokesp+2,98:pokesp+3,98:pokesp+4,98:pokesp+5,32 440 rem -------------------------------------------------------------- 450 rem get input (key "1" = left, key "2" = right 460 rem -------------------------------------------------------------- 470 getk:pp=pp+(k=1)-(k=2) 480 rem -------------------------------------------------------------- 490 rem validate boundaries' to ensure new position is within play area 500 rem -------------------------------------------------------------- 510 if pp<-1 then pp=-1 : rem reset pebble position to min -1 520 if pp>35 then pp=35 : rem reset pebble position to max 35 530 rem -------------------------------------------------------------- 540 rem clear current bouncing ball position and calculate new 550 rem -------------------------------------------------------------- 560 pokesm+x+(y*40),32: 570 if y>=24 or y<1 then dy=-dy : rem reverse y on boundary 580 if y>=24 then ms=ms+1 : rem count missed if y below pebble 590 if x>=39 or x<1 then dx=-dx : rem reverse x on boundary 600 if k=1 then mc=-mc : rem direction correction on hit and last key 610 x= x+dx : y= y+dy : rem new ball x,y coordinate 620 rem -------------------------------------------------------------- 630 rem validate hit pebble on hit count and shift to pebble position 640 rem -------------------------------------------------------------- 650 if peek(sm+x+(y*40))=98 then dx=-dx*mc:dy=-dy:h=h+1:x=pp 660 poke sm+x+(y*40),81 : rem poke new ball position on screen 670 print chr$(19)"hit:";h;" missed:";ms : rem rewrite score on screen 680 goto 380 : rem restart main loop |
And here is the shortened version of it. Only 10 mmm almost 11 lines of Commodore 64 Basic code.
It is possible to bring it to 10 lines if you replace the chr$ code by the PetscII characters. However to still have some readability i left it like this, as this makes it also easy to copy and use in the Emulator like Vice.
1 2 3 4 5 6 7 8 9 10 11 |
1 ?chr$(147):pO53280,0:pO53281,0:pp=17:pO650,128:sa=1024+(22*40):sm=1024:dx=1 2 x=int(rnd(1)*24):y=12:dy=1:c$=chr$(28)+chr$(149)+chr$(158)+chr$(30)+chr$(31) 3?:forp=1to5:forn=1to8:?chr$(18)+mid$(c$,p,1)+chr$(229)+" "+chr$(234);:nE:nE 4 sp=sa+pp:pOsp,32:pOsp+1,98:pOsp+2,98:pOsp+3,98:pOsp+4,98:pOsp+5,32 5 getk:pp=pp+(k=1)-(k=2):ifpp<-1thenpp=-1 6 ifpp>35thenpp=35 7 pokesm+x+(y*40),32:ify>=24ory<1thendy=-dy:ify>=24then ms=ms+1 8 ifx>=39orx<1thendx=-dx 9 mc=-1:ifk=1tHmc=-mc 10 x=x+dx:y=y+dy:ifpE(sm+x+(y*40))=98tHdx=-dx*mc:dy=-dy:l=l+1:x=pp 11 poke sm+x+(y*40),81:print chr$(19)"hit:";l;" missed:";ms:goto4 |
No responses yet