Home  |  Contents 

Microcontroller and PC projects
  Forum Index : Microcontroller and PC projects         Section
Subject Topic: (MM-DM-UBW32) Break the Wall Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
darthmite
Senior Member
Senior Member
Avatar

Joined: 20 November 2011
Location: France
Online Status: Offline
Posts: 240
Posted: 27 November 2011 at 10:34pm | IP Logged Copy link to clipboard   Quote darthmite

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 on 27 November 2011 at 10:46pm


__________________
Theory is when we know everything but nothing work ...
Practice is when everything work but no one know why ;)


Back to Top View darthmite's Profile Search for other posts by darthmite
 
Olimex
Senior Member
Senior Member


Joined: 02 October 2011
Location: Bulgaria
Online Status: Offline
Posts: 226
Posted: 28 November 2011 at 3:13am | IP Logged Copy link to clipboard   Quote Olimex

my son love it :)
good work!
Back to Top View Olimex's Profile Search for other posts by Olimex
 
VK6MRG
Guru
Guru
Avatar

Joined: 08 June 2011
Location: Australia
Online Status: Offline
Posts: 347
Posted: 28 November 2011 at 6:30pm | IP Logged Copy link to clipboard   Quote VK6MRG

Awesome. I love it. Thanks for the neat game.

__________________
Its easier to ask forgiveness than to seek permission!
............VK6MRG.............VK3MGR............
Back to Top View VK6MRG's Profile Search for other posts by VK6MRG Visit VK6MRG's Homepage
 
trippyben
Regular Member
Regular Member
Avatar

Joined: 26 June 2011
Location: Australia
Online Status: Offline
Posts: 89
Posted: 04 December 2011 at 4:40pm | IP Logged Copy link to clipboard   Quote trippyben

That is good. One day I'll let the boys have a go!
Back to Top View trippyben's Profile Search for other posts by trippyben
 


If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Search the forums using Google.
 
Post ReplyPost New Topic
Printable version Printable version
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

Powered by Web Wiz Forums version 7.8
Copyright ©2001-2004 Web Wiz Guide

This page was generated in 0.1250 seconds.
Privacy Policy     Process times : 0, 0.02, 0, 0.11