AgonLight Week Programming Challenge – ISSUE 3

Here we go to the Third issue of the AgonLight programming challenge.

This time taking into the account the feedback we got from Facebook we will extend it to be 1 week long, not just weekend!

So rules are changed:

What is WPC?

It’s a small coding challenge that you have to solve for 1 week from Friday 2nd of June to Thursday 8th of June!.

Who can participate?

Anyone can participate except Olimex employees. You can submit the solutions under your name or anonymously under an alias name.

What are the rules?

The code must run on AgonLight. There are no restriction how you will code your solution: Assembler, Forth, C, BBC Basic, Turbo Pascal for CP/M any tool is possible. If your tool need special installation you should provide brief note how to do it so we can verify your solution.
There is no restriction to re-use code found on internet and adopt it for AgonLight2 as far the code is working and doing the job!
The solutions should be sent to info at olimex dot com. You will receive notification email that the solution is received.

On next Friday 9th of June, we will push all solutions received to a special GitHub repository and announce the winner on Monday 12th of June, who will receive a €50 voucher to use in the Olimex web shop. The jury will consist of Tsvetan Usunov and Bernardo Kastrup.

So z80 retro ninja coders here is the third challenge for you!

Make Snake game for AgonLight in the next 7 days!

https://en.wikipedia.org/wiki/Snake_(video_game_genre)

Good Luck!

AgonLight Weekend Programming Challenge – ISSUE 2

What is WPC?

It’s a small coding challenge that you have to solve in two days during the weekend.

Who can participate?

Anyone can participate except Olimex employees. You can submit the solutions under your name or anonymously under an alias name.

What are the rules?

The code must run on AgonLight. There are no restriction how you will code your solution: Assembler, Forth, C, BBC Basic, Turbo Pascal for CP/M any tool is possible. If your tool need special installation you should provide brief note how to do it so we can verify your solution.
There is no restriction to re-use code found on internet and adopt it for AgonLight2 as far the code is working and doing the job!
The solutions should be sent to info at olimex dot com. You will receive notification email that the solution is received.

On Monday, we will push all solutions received to a special GitHub repository and announce the winner on Tuesday, who will receive a €50 voucher to use in the Olimex web shop. The jury will consist of Tsvetan Usunov and Bernardo Kastrup.

So z80 retro ninja coders here is the second challenge for you!

Make Flappy Bird game for AgonLight during this weekend!

https://en.wikipedia.org/wiki/Flappy_Bird

According to the Author it took him one weekend to write it 😉

Good Luck!

UPDATE 08-05-2023

With only one single submission we have the ultimate winner LuzrBum:

https://github.com/OLIMEX/AgonLight-WPC/tree/main/ISSUE-2

New Product in Stock: Open Source Hardware Simon-85 game assembled and as kit

SIMON-85-KIT

Simon-85 is based on the popular Simon says game and check and train your short time memory. It’s sold as DIY kit but also as assembled and tested board:

SIMON-85-1

To run the game you need USB-A-B cable or LiPo battery. In case you want to use battery you may also need charger for it.

Inside the game there is ATiny85 microcontroller with micronucleus bootloader which allow the board to be re-programmed with Digispark’s Arduino IDE. All sources are on our web and you can download and modify the game yourself. No need for external programmers etc.

When power is applied after 5 seconds the four LEDs will flash for a while and the game will wait you to choose difficulties “Level”. There are 4 levels for sequencies of 10-20-30-40 LED blink patterns. Depend on which button you press BUT1,BUT2,BUT3,BUT4 the game will start at the corresponding level. You will hear Super Mario Bros theme and LEDs will blink then the game will start and you have to repeat the LED blink pattern you see.

If you make mistake the game will over and you can start it again. Each time you complete the pattern correctly the game will flash new one which is one more blink longer. Each new game starts with random pattern so you can’t memorize these.

Simon-85 assembled and tested cost EUR 7.95 the kit is EUR 5.95.

Assembling Simon-85-KIT is good way kids and beginners to learn basic electronics components and how to solder.

Free online eBook – Game Programming Patterns

Image

Game Programming Patterns, is a book on architectural patterns in game code. If you ever struggle with the complexity of your game’s codebase, this book will help.

http://gameprogrammingpatterns.com/

Weekend Programming Challenge – Week #37 – Snake Retro Game

Image

Problem:

Make your own snake game!

Do you remember the Nokia phones Snake game? You move the snake with 4 keys and it eats apples on the screen and gets bigger, collision with walls or snake body ends the game.

The rules:

You can code the solution in any programming language during the weekend and have to submit it to info@olimex.com latest on Sunday December 15th.

On Monday we will upload the solutions on GitHub https://github.com/OLIMEX/WPC

You can play with your real name or with nick if you want to be anonymous, we will not disclosure your personal info if you do not want to.

AVR-T32U4 Arduino Leonardo interfacing to LEDs and Buttons in LED game

Image

We create small video tutorial http://www.youtube.com/watch?v=OCd_YFYHWnM how to connect LEDs and Buttons to AVR-T32U4 Arduino Leonardo and create small Game.

The code is on GitHub https://github.com/OLIMEX/DUINO

DuinoMite – retro Snake game written in Basic

I will admit that I didn’t wrote computer games since I was 14, but recently user of The Back Shed forum named Darthmite inspired me when he wrote two games in MM Basic – Bricks and Space Invaders.

This weekend I had some free time and decided to try code some of the old time retro games in Basic.
Snake was good candidate as it’s very easy as concept and would not take much time, so I started:

1. had to define the game constants as I wanted it to make it flexible as much as possible

10 ESC = 27: LF = 130: RG = 131: UP =128: DN = 129 ‘keyboard keys to play Esc-exit and the arrows
20 OPTION BASE 0
30 MAXSNAKE = 14 ‘max length of the snake to go to upper level
40 MAXSTAGE = 5 ‘max number of levels actually anything above stage 2 is very hard to complete
50 DIM SNAKEX(MAXSNAKE),SNAKEY(MAXSNAKE) ‘here we will keep snake body coordinates
60 MAXX = 40 ‘playfield X size
70 MAXY = 30 ‘playfield Y size
80 SIZEX=5 ‘snake body X size
90 SIZEY=10 ‘snake body Y size
100 BLOCKS = 4 ‘snake body initial length
110 STAGE = 1 ‘start from stage 1
120 DIRECTION = 2 ‘initial move direction
130 POINT = 0 ‘number of points
140 SPEED = 100 ‘speed delay

then we have to display the game rules:

150 CLS
160 PRINT “SNAKE GAME 1.0 15.01.2011 OLIMEX LTD http://www.olimex.com”
170 PRINT “MAX SNAKE LENGHT “;MAXSNAKE
180 PRINT “MAX STAGES “;MAXSTAGE
190 PRINT “PLAYFIELD SIZE “;MAXX;” x “;MAXY
200 PRINT “USE UP-DOWN-LEFT-RIGHT KEYS TO MOVE SNAKE DIRECTION”
210 PRINT “PRESS ANY KEY TO START”
220 IF INKEY$=”” THEN 220

and we can start the game:

230 ‘START
240 CLS ‘clear screen and draw the play field
250 LINE (0,0)-(MAXX*SIZEX+SIZEX,0): LINE -(MAXX*SIZEX+SIZEX,MAXY*SIZEY+SIZEY)
260 LINE -(0,MAXY*SIZEY+SIZEY): LINE -(0,0)
270 LOCATE MAXX*SIZEX+10,0 : PRINT “POINTS: “;POINT
280 LOCATE MAXX*SIZEX+10,12 : PRINT “STAGE : “;STAGE
290 FOR I = 0 TO BLOCKS: SNAKEX(I) = MAXX \ 2: SNAKEY(I) = MAXY \ 2 – I: NEXT I ‘init snake body
300 X = SNAKEX(0): Y = SNAKEY(0)
310 DIRECTION = 2
320 FOR I = 0 TO BLOCKS ‘draw snake body
330 LINE (SNAKEX(I)*SIZEX+1,SNAKEY(I)*SIZEY+1)-(SNAKEX(I)*SIZEX+SIZEX-1,SNAKEY(I)*SIZEY+SIZEY-1),1,BF
340 NEXT I

now let’s draw some food for the snake:

350 RANDOMIZE = TIMER
360 TARGETX = CINT(RND*MAXX) : TARGETY = CINT(RND*MAXY)
370 CIRCLE (TARGETX*SIZEX+SIZEX\2,TARGETY*SIZEY+5)+SIZEY\2,SIZEX\2,1,F

and we start the main game loop:

380 ‘MAINLOOP
390 KEY$=INKEY$ ‘get keyboard input and handle the keys
400 IF KEY$=CHR$(ESC) THEN CLS: END
410 IF KEY$=CHR$(UP) THEN IF DIRECTION <>1 THEN DIRECTION = 0
420 IF KEY$=CHR$(DN) THEN IF DIRECTION <>0 THEN DIRECTION = 1
430 IF KEY$=CHR$(RG) THEN IF DIRECTION <>3 THEN DIRECTION = 2
440 IF KEY$=CHR$(LF) THEN IF DIRECTION <>2 THEN DIRECTION = 3
450 IF DIRECTION = 0 THEN Y = Y-1
460 IF DIRECTION = 1 THEN Y = Y+1
470 IF DIRECTION = 2 THEN X = X+1
480 IF DIRECTION = 3 THEN X = X-1

then check for game over – if the snake crash to walls or bit itself

490 IF X<0 OR Y<0 OR X>MAXX OR Y>MAXY THEN 810
500 FOR I = 1 TO BLOCKS
510 IF SNAKEX(0)=SNAKEX(I) AND SNAKEY(0)=SNAKEY(I) THEN 810
520 NEXT I

then check if snake hit some food and increase snake size in this case:

530 IF SNAKEX(0) = TARGETX AND SNAKEY(0) = TARGETY THEN
540 SOUND 700,100: PAUSE 100
550 CIRCLE (TARGETX*SIZEX+SIZEX\2,TARGETY*SIZEY+5)+SIZEY\2,SIZEX\2,0,F
560 LINE (TARGETX*SIZEX+1,TARGETY*SIZEY+1)-((TARGETX+1)*SIZEX-1,(TARGETY+1)*SIZEY-1),1,BF
570 TARGETX = CINT(RND*MAXX) : TARGETY = CINT(RND*MAXY)
580 CIRCLE (TARGETX*SIZEX+SIZEX\2,TARGETY*SIZEY+5)+SIZEY\2,SIZEX\2,1,F
590 POINT = POINT+10
600 BLOCKS = BLOCKS+1
610 LOCATE MAXX*SIZEX+10,0 : PRINT “POINTS: “;POINT
620 ENDIF

if the snake grow to max length move to new stage:

630 IF BLOCKS = MAXSNAKE THEN
640 STAGE = STAGE + 1
650 IF STAGE = MAXSTAGE THEN 850
660 BLOCKS = 4
670 SPEED = 100 \ STAGE
680 LOCATE MAXX*SIZEX+10,22: PRINT “STAGE : “;STAGE-1;” CLEAR”
690 PAUSE 2000
700 LOCATE MAXX*SIZEX+10,22: PRINT ” ”
710 GOTO 230
720 ENDIF

if no walls, no self bite nor hit food then just move the snake

730 LINE (X*SIZEX+1,Y*SIZEY+1)-((X+1)*SIZEX-1,(Y+1)*SIZEY-1),1,BF
740 PAUSE SPEED
750 LINE (SNAKEX(BLOCKS)*SIZEX+1,SNAKEY(BLOCKS)*SIZEY+1)-(SNAKEX(BLOCKS)*SIZEX+SIZEX-1,SNAKEY(BLOCKS)*SIZEY+SIZEY-1),0,BF
760 FOR I = BLOCKS TO 1 STEP -1
770 SNAKEX(I) = SNAKEX(I-1): SNAKEY(I) = SNAKEY(I-1)
780 NEXT I
790 SNAKEX(0)=X: SNAKEY(0)=Y

then close the main loop:

800 GOTO 380

or handle the Game Over:

810 FOR I = 700 TO 100 STEP -100: SOUND I,100: PAUSE 100: NEXT I
820 LOCATE MAXX*SIZEX+10,22: PRINT “GAME OVER”
830 PAUSE 2000
840 RUN

if all sgates are complete (which I highly doubt as speed become terrible after Stage 2:

850 LOCATE MAXX*SIZEX+10,22: PRINT ” YOU ARE GENIUS!”
860 END

—————————–

the complete code is below:

10 ESC = 27: LF = 130: RG = 131: UP =128: DN = 129
20 OPTION BASE 0
30 MAXSNAKE = 14
40 MAXSTAGE = 5
50 DIM SNAKEX(MAXSNAKE),SNAKEY(MAXSNAKE)
60 MAXX = 40
70 MAXY = 30
80 SIZEX=5
90 SIZEY=10
100 BLOCKS = 4
110 STAGE = 1
120 DIRECTION = 2
130 POINT = 0
140 SPEED = 100
150 CLS
160 PRINT “SNAKE GAME 1.0 15.01.2011 OLIMEX LTD http://www.olimex.com&#8221;
170 PRINT “MAX SNAKE LENGHT “;MAXSNAKE
180 PRINT “MAX STAGES “;MAXSTAGE
190 PRINT “PLAYFIELD SIZE “;MAXX;” x “;MAXY
200 PRINT “USE UP-DOWN-LEFT-RIGHT KEYS TO MOVE SNAKE DIRECTION”
210 PRINT “PRESS ANY KEY TO START”
220 IF INKEY$=”” THEN 220
230 ‘START
240 CLS
250 LINE (0,0)-(MAXX*SIZEX+SIZEX,0): LINE -(MAXX*SIZEX+SIZEX,MAXY*SIZEY+SIZEY)
260 LINE -(0,MAXY*SIZEY+SIZEY): LINE -(0,0)
270 LOCATE MAXX*SIZEX+10,0 : PRINT “POINTS: “;POINT
280 LOCATE MAXX*SIZEX+10,12 : PRINT “STAGE : “;STAGE
290 FOR I = 0 TO BLOCKS: SNAKEX(I) = MAXX \ 2: SNAKEY(I) = MAXY \ 2 – I: NEXT I
300 X = SNAKEX(0): Y = SNAKEY(0)
310 DIRECTION = 2
320 FOR I = 0 TO BLOCKS
330 LINE (SNAKEX(I)*SIZEX+1,SNAKEY(I)*SIZEY+1)-(SNAKEX(I)*SIZEX+SIZEX-1,SNAKEY(I)*SIZEY+SIZEY-1),1,BF
340 NEXT I
350 RANDOMIZE = TIMER
360 TARGETX = CINT(RND*MAXX) : TARGETY = CINT(RND*MAXY)
370 CIRCLE (TARGETX*SIZEX+SIZEX\2,TARGETY*SIZEY+5)+SIZEY\2,SIZEX\2,1,F
380 ‘MAINLOOP
390 KEY$=INKEY$
400 IF KEY$=CHR$(ESC) THEN CLS: END
410 IF KEY$=CHR$(UP) THEN IF DIRECTION <>1 THEN DIRECTION = 0
420 IF KEY$=CHR$(DN) THEN IF DIRECTION <>0 THEN DIRECTION = 1
430 IF KEY$=CHR$(RG) THEN IF DIRECTION <>3 THEN DIRECTION = 2
440 IF KEY$=CHR$(LF) THEN IF DIRECTION <>2 THEN DIRECTION = 3
450 IF DIRECTION = 0 THEN Y = Y-1
460 IF DIRECTION = 1 THEN Y = Y+1
470 IF DIRECTION = 2 THEN X = X+1
480 IF DIRECTION = 3 THEN X = X-1
490 IF X<0 OR Y<0 OR X>MAXX OR Y>MAXY THEN 810
500 FOR I = 1 TO BLOCKS
510 IF SNAKEX(0)=SNAKEX(I) AND SNAKEY(0)=SNAKEY(I) THEN 810
520 NEXT I
530 IF SNAKEX(0) = TARGETX AND SNAKEY(0) = TARGETY THEN
540 SOUND 700,100: PAUSE 100
550 CIRCLE (TARGETX*SIZEX+SIZEX\2,TARGETY*SIZEY+5)+SIZEY\2,SIZEX\2,0,F
560 LINE (TARGETX*SIZEX+1,TARGETY*SIZEY+1)-((TARGETX+1)*SIZEX-1,(TARGETY+1)*SIZEY-1),1,BF
570 TARGETX = CINT(RND*MAXX) : TARGETY = CINT(RND*MAXY)
580 CIRCLE (TARGETX*SIZEX+SIZEX\2,TARGETY*SIZEY+5)+SIZEY\2,SIZEX\2,1,F
590 POINT = POINT+10
600 BLOCKS = BLOCKS+1
610 LOCATE MAXX*SIZEX+10,0 : PRINT “POINTS: “;POINT
620 ENDIF
630 IF BLOCKS = MAXSNAKE THEN
640 STAGE = STAGE + 1
650 IF STAGE = MAXSTAGE THEN 850
660 BLOCKS = 4
670 SPEED = 100 \ STAGE
680 LOCATE MAXX*SIZEX+10,22: PRINT “STAGE : “;STAGE-1;” CLEAR”
690 PAUSE 2000
700 LOCATE MAXX*SIZEX+10,22: PRINT ” ”
710 GOTO 230
720 ENDIF
730 LINE (X*SIZEX+1,Y*SIZEY+1)-((X+1)*SIZEX-1,(Y+1)*SIZEY-1),1,BF
740 PAUSE SPEED
750 LINE (SNAKEX(BLOCKS)*SIZEX+1,SNAKEY(BLOCKS)*SIZEY+1)-(SNAKEX(BLOCKS)*SIZEX+SIZEX-1,SNAKEY(BLOCKS)*SIZEY+SIZEY-1),0,BF
760 FOR I = BLOCKS TO 1 STEP -1
770 SNAKEX(I) = SNAKEX(I-1): SNAKEY(I) = SNAKEY(I-1)
780 NEXT I
790 SNAKEX(0)=X: SNAKEY(0)=Y
800 GOTO 380
810 FOR I = 700 TO 100 STEP -100: SOUND I,100: PAUSE 100: NEXT I
820 LOCATE MAXX*SIZEX+10,22: PRINT “GAME OVER”
830 PAUSE 2000
840 RUN
850 LOCATE MAXX*SIZEX+10,22: PRINT ” YOU ARE GENIUS!”
860 END

Have fun 🙂

Next weekend if I have some more free will try to write TETRIS for DuinoMite

DUINOMITE with GAMEDUINO shield

Ken Seggler who writes DuinoMite firmware just posted Video for successfuly implementation of Gameduino shield support in DM BASIC

Here is the YOUTUBE video

and here is the code which implements it:

10 DATA 31,47,32,48,33,49,34,48,35,50,36,51,37,52,38,53
20 DATA 39,54,40,55,41,56,42,57,43,58,44,59,45,60,46,61
30 DIM sintab(4096)
40 FOR xx=4096 TO 0 STEP -1
50 sintab(xx)=SIN(xx/25.0)*25+30
60 NEXT
70 RANDOMIZE TIMER:x=0:y=0:ch=0
80 FOR x=0 TO 4096
90 GDWRITEB x,INT(RND()*31)
100 NEXT
110 FOR f=0 TO 15
120 READ a
130 GDWRITEB 1169+f,a
140 READ a
150 GDWRITEB 1233+f,a
160 NEXT
170 k=0:r=1:fire =0:update=5:x=192:dir=0
180 f=1
190 SETTICK 50,510
200 GDSPRITEC 0,400,400,55,0,0,0
210 xx=416
220 ‘yy = SIN(xx/25.0)*25+30
230 ‘
240 IF done=1 THEN xx=416 ELSE xx=xx-1
250 IF xx > 0 THEN GDSPRITEC 10,xx-16,sintab(xx),26,0,0,0
260 IF xx <384 AND xx+16 >0 THEN GDSPRITEC 11,xx,sintab(xx+16),43,0,0,0
270 IF xx < 384 AND xx+32 > 0 THEN GDSPRITEC 12,xx+16,sintab(xx+32),31,0,0,0
280 IF xx < 384 AND xx+48 > 0 THEN GDSPRITEC 13,xx+32,sintab(xx+48),36,0,0,0
290 IF xx < 384 AND xx+64 > 0 THEN GDSPRITEC 14,xx+48,sintab(xx+64),37,0,0,0
300 IF xx < 384 AND xx+80 > 0 THEN GDSPRITEC 15,xx+64,sintab(xx+80),35,0,0,0
310 IF xx < 384 AND xx+96 > 0 THEN GDSPRITEC 16,xx+80,sintab(xx+96),31,0,0,0
320 IF xx < 384 AND xx+112 > 0 THEN GDSPRITEC 17,xx+96,sintab(xx+112),42,0,0,0
330 IF xx < 384 AND xx+128 > 0 THEN GDSPRITEC 18,xx+112,sintab(xx+128),27,0,0,0
340 ‘IF xx < 384 AND xx+144 > 0 THEN GDSPRITEC 19,xx+128,sintab(xx+144),40,0,0,0
341 IF xx > 0 THEN GDSPRITEC 20,xx-16,284,29,0,0,0
342 IF xx <384 AND xx+16 >0 THEN GDSPRITEC 21,xx,284,23,0,0,0
343 IF xx < 384 AND xx+32 > 0 THEN GDSPRITEC 22,xx+16,284,35,0,0,0
344 IF xx < 384 AND xx+48 > 0 THEN GDSPRITEC 23,xx+32,284,27,0,0,0
345 IF xx < 384 AND xx+64 > 0 THEN GDSPRITEC 24,xx+48,284,26,0,0,0
346 IF xx < 384 AND xx+80 > 0 THEN GDSPRITEC 25,xx+64,284,43,0,0,0
347 IF xx < 384 AND xx+96 > 0 THEN GDSPRITEC 26,xx+80,284,31,0,0,0
348 IF xx < 384 AND xx+112 > 0 THEN GDSPRITEC 27,xx+96,284,36,0,0,0
349 IF xx < 384 AND xx+128 > 0 THEN GDSPRITEC 28,xx+112,284,37,0,0,0
350 ‘IF xx < 384 AND xx+144 > 0 THEN GDSPRITEC 29,xx+128,284,40,0,0,0
351 IF xx+176 = 0 THEN done=1 ELSE done = 0
352 PAUSE 5
360 a$=INKEY$
370 IF a$=”” THEN a$=CHR$(dir)
380 IF ASC(a$)=&h82 THEN x=x-1:dir=&h82
390 IF ASC(a$)=&h83 THEN x=x+1:dir=&h83
400 IF x > 384 THEN x=384
410 IF x < 0 THEN x=0
420 IF fire=1 THEN GOTO 440
430 IF a$=” ” THEN fire=1:xf=x:yf=265-16
440 GDSPRITEC 1,x,265,50,0,0,0
450 y=y-1
460 GDWRITEW &h2806,y
470 GOSUB 490
480 GOTO 220
490 IF GDREADB(&h2803) <> 1 GOTO 490
500 RETURN
510 ‘
520 update=update-1
530 IF update = 0 THEN update = 10 ELSE GOTO 660
540 n=128
550 FOR xz=30 TO 275 STEP 25
560 xs=xz+25
570 IF f=1 THEN GDSPRITEC n,xs+k,70,52,0,0,0:GDSPRITEC n+10,xs+k,90,54,0,0,0
580 IF f=0 THEN GDSPRITEC n,xs+k,70,51,0,0,0:GDSPRITEC n+10,xs+k,90,53,0,0,0
590 n=n+1
600 NEXT
610 IF r=1 THEN k=k+3
620 IF r=0 THEN k=k-3
630 IF k=60 THEN r=0
640 IF k=0 THEN r =1
650 IF f=1 THEN f=0 ELSE f=1
660 IF yf<0 THEN fire=0:GDSPRITEC 0,400,400,55,0,0,0:GOTO 690
670 GOSUB 490
680 IF fire=1 THEN GDSPRITEC 0,xf,yf-15,55,0,0,0:yf=yf-5
690 IRETURN

We work on new MOD-VGA board which will be based on Gameduino shield but with additional 512KB  of RAM which will be available either as video RAM and allow resolution of 800×600 pixels either as memory for DuinoMite code.

The module will be available for sale in mid February!