After working on different oneliner programs I wanted to create a small basic game. The challange is to find an idea that is not to complex but also has some challanges and also a simple game concept.

At first I was just playing with some code to see how I could draw some simple rectangles on the screen. Then an idea struck me. The idea was simple and as follows:

  • can I create blocks with a certain pattern on the screen for which a user should search for equal patterns.

From this idea i doodled a bit on my ipad and brought it back to the following

  • generate a matrix of a number of rectangles on the screen let say 16
  • use a character that has a pattern
  • randomize the color of the characters and ensure they are all different
  • then select two random blocks in this matrix
  • highlight the second block
  • copy the pattern from the first to the second (just the color) (the second because otherwise changing color would disclose both blocks (because proces is probably to slow)

Ok next start programming, testing and try to keep it as lean and mean as possible, so first the consept nog input, output, any user input or score.

Then the result:

Then the user can use see which block and pattern is equal to the one marked. After pressing a key the aswer is revealed.

Aswer revealed after pressing a key

Then the game code. This code can be copied directly into the VICE Commodore 64 emulator if you want to playu with it a bit.

10 rem ——- pattern matching concept game ————
20 rem ———— initialize size and start position —————
30 dim bp(16)
35 ?chr$(147):ai=1:sm=1024:cm=55296:r=4:c=4:w=4:h=3:sp=(6-w)+((6-h)40)
50 rem ————- draw a matrix of random blocks —————–
100 for b=0 to r-1:for i=1 to c:for l=0 to h:for p=0 to w 130 o =(i(w+2))+sp+p+(40l)+(40b(h+2)):pOsm+o,102:pOcm+o,int(rnd(1)4)
150 next p,l:bp(ai)=o:ai=ai+1:next i,b
200 rem ——– random selections of which blocks to equalize ———-
210 f=int(rnd(1)16)+1: s=int(rnd(1)16)+1:if f=s then goto 210
250 rem ——————- mark first block ————————
270 tl=f:gosub 800:co=1:rem gosub 400 :rem only for debug
280 rem ——— copy color to second block and mark block ———–
310 tl=s:gosub 800:co=3:gosub 400 :gosub 600
320 rem ——————- end of program —————————
325 poke214,22:?:poke211,5:?”press a key to see the answer”
340 poke 198,0: wait 198,1 : rem wait on key pressed
350 rem ——————- disclosure other block ——————–
360 tl=f:gosub 800:co=1:gosub 400
362 poke214,22:?:poke211,5:?” press a key to play again “
365 poke 198,0: wait 198,1: goto 35 :rem again again
370 end
400 rem ————- mark a tile use passed tile id —————-
410 for m=0 to w+2:pokesm+lc-1+m,67:pokecm+lc-1+m,co:next m
420 for m=0 to w+2:pokesm+bc-1+m,67:pokecm+bc-1+m,co:next m
430 for m=0 to h+2:pokesm+lc-1+(m40),66:pokecm+lc-1+(m40),co:next m
440 for m=0 to h+2:pokesm+lc+w+1+(m40),66:pokecm+lc+w+1+(m40),co:next m
450 pokesm+lc-1,85:pokesm+bc-1,74:pokesm+lc+w+1,73:pokesm+bc+w+1,75
500 return
600 rem —- copy tile colours to from first to second tile ————
610 tl=f:gosub 800:fc=lc:tl=s:gosub 800
620 for i=1 to h+1:for j=0 to w: poke cm+lc+j+(i40),peek(cm+fc+j+(i40))
650 next j,i : return
800 rem ——- set determine left corner en bottom corner ————-
810 lc = (bp(tl)-((h+1)*40)-w): rem left corner top
820 bc = (bp(tl)-w)+40: rem bottom corner
830 return

See it in action:

Categories:

Tags:

No responses yet

Geef een antwoord

Het e-mailadres wordt niet gepubliceerd.