Home
JAQForum Ver 19.8.18
Log In or Join  
Active Topics
Local Time 12:55 17 Sep 2019 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : (MM-DM-UBW32) Break the Wall

Author Message
darthmite

Senior Member

Joined: 20/11/2011
Location: France
Posts: 240
Posted: 12:34pm 27 Nov 2011
Copy link to clipboard 

Hi ,

After some tests in 3D graphics with the MM i have want made something more interactive
I have 1st think about made a PONG game but it was too easy , i then just made a
Breakout like game.
To play you have to connect a potentiometer to the PIN 1 (B4) and run.

Here we have the source code ....


10 OPTION base 0
20 'Connect a 10k potentiometer to PIN 1 (B4)
30 SETPIN 1,1
40 'array for a 16 x 10 bricks wall
50 DIM Brick(16,10)
60 RackSize = 40
70 CLS
80 PRINT "Press a key to start"
90 IF INKEY$ = "" THEN GOTO 90
100 CLS
110 'We made the wall
120 FOR a = 0 TO 9
130 FOR b = 0 TO 15
140 LINE (b*19,a*10)-((b*19)+17,(a*10)+8),1,bf
150 Brick(b,a) = 1
160 NEXT b
170 NEXT a
180 CalcPot = 3 / MM.HRES
190 Racket = INT((PIN(1) -0.1) / CalcPot)
200 RANDOMIZE TIMER
210 ballx = RND * (MM.HRES -40) + 20
220 bally = 150
230 oldballx = ballx
240 oldbally = bally
250 dx = 0
260 DO WHILE dx = 0
270 dx = RND(5) - 2
280 LOOP
290 dy = -2
300 LINE (racket,200)-(racket + 39,210),1,bf
310 oldracket = racket
320 'Main loop
330 DO WHILE 1
340 Racket = INT((PIN(1) -0.1) / CalcPot)
350 IF ASC(a$) = 130 THEN Racket = racket - 20
360 IF Racket < 0 THEN Racket = 0
370 IF Racket > (MM.HRES - 40) THEN Racket = MM.HRES - 40
380 RackRight = Racket + RackSize
390 IF Racket <> oldracket THEN
400 LINE (oldracket,200)-(oldracket + 39,210),0,bf
410 LINE (racket,200)-(racket + 39,210),1,bf
420 ENDIF
430 oldracket = racket
440 oldballx = ballx
450 oldbally = bally
460 ballx = ballx + dx
470 bally = bally + dy
480 IF bally >= 200 THEN GOSUB 610
490 IF bally <= 3 THEN dy = ABS(dy)
500 IF ballx > (MM.HRES - 4) THEN dx = -dx
510 IF ballx < 2 THEN dx = ABS(dx)
520 ShootY = INT(bally / 10)
530 LINE (oldballx - 2,oldbally - 2)-(oldballx + 2,oldbally + 2),0,bf
540 LINE (ballx - 2,bally - 2)-(ballx + 2,bally + 2),1,bf
550 IF (ShootY >= 0) AND (ShootY <= 9) THEN
560 ShootX = INT(Ballx / 19)
570 IF ShootX <= 15 THEN GOSUB 910
580 ENDIF
590 PAUSE 20
600 LOOP
610 'Racket Test
620 IF ballx < Racket THEN
630 LOCATE 10,150
640 PRINT "GAME OVER !"
650 SOUND 500,500
660 PRINT "Press a key to restart"
670 IF INKEY$ = "" THEN GOTO 670
680 RUN
690 ENDIF
700 IF ballx > RackRight THEN
710 LOCATE 10,150
720 PRINT "GAME OVER !"
730 SOUND 500,500
740 PRINT "Press a key to restart"
750 IF INKEY$ = "" THEN GOTO 750
760 RUN
770 ENDIF
780 SOUND 700,10
790 dy = -dy
800 IF ballx >= Racket AND ballx >= Racket + INT(RackSize / 4) THEN
810 IF dx > 0 THEN dx = -3
820 ENDIF
830 IF BallX >= Racket + INT(RackSize/4) AND BallX <= Racket + INT(RackSize/2) THEN
840 IF dx > 0 THEN dx = -2
850 ENDIF
860 IF BallX >= (Racket + INT(RackSize / 2)+INT(RackSize / 4)) AND BallX <= RackRight THEN
870 IF dx < 0 THEN dx = 2
880 ENDIF
890 'Here we return to main loop
900 RETURN
910 'Test the Bricks
920 IF ShootX < 0 THEN ShootX = 0
930 IF brick(ShootX,ShootY) = 1 THEN
940 brick(ShootX,ShootY) = 0
950 SOUND 1000,20
960 LINE (ShootX*19,ShootY*10)-((ShootX*19)+18,(ShootY*10)+9),0,bf
970 score = score + 10
980 LOCATE 5,120
990 PRINT score
1000 IF score > 1600 THEN
1010 LOCATE 10,150
1020 PRINT "You win !"
1030 INPUT "Press a key to restart"
1040 RUN
1050 ENDIF
1060 IF dy > 0 THEN
1070 dy = -dy
1080 ELSE
1090 dy = ABS(dy)
1100 ENDIF
1110 ENDIF
1120 'Here we return to the main loop
1130 RETURN







Enjoy
Edited by darthmite 2011-11-28
Theory is when we know everything but nothing work ...
Practice is when everything work but no one know why ;)
 
Olimex
Senior Member

Joined: 02/10/2011
Location: Bulgaria
Posts: 226
Posted: 05:13pm 27 Nov 2011
Copy link to clipboard 

my son love it :)
good work!
 
VK6MRG

Guru

Joined: 08/06/2011
Location: Australia
Posts: 347
Posted: 08:30am 28 Nov 2011
Copy link to clipboard 

Awesome. I love it. Thanks for the neat game.
Its easier to ask forgiveness than to seek permission!
............VK6MRG.............VK3MGR............
 
trippyben

Regular Member

Joined: 26/06/2011
Location: Australia
Posts: 90
Posted: 06:40am 04 Dec 2011
Copy link to clipboard 

That is good. One day I'll let the boys have a go!
 


To reply to this topic, you need to log in.

© JAQ Software 2019