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) Moon Lander
Author | Message | ||||
darthmite Senior Member Joined: 20/11/2011 Location: FrancePosts: 240 |
Hi , This time i have do a little moon lander. For this one you need 3 buttons Up on pin 11 Left on pin 13 Right on pin 14 And here is the source : 10 'Lunar Lander for Maximite 20 ' 30 CLEAR 40 DIM TEvel(MM.HRES) 50 CLS 60 'PIN 11 = UP (Booster) 70 SETPIN 11,2 80 'PIN 13 = LEFT 90 SETPIN 13,2 100 'PIN 14 = RIGHT 110 SETPIN 14,2 120 Booster = 0 130 LemSpeed = 0.1 140 SpeedX = 0.0 150 Fuel = 50.0 160 Gravity = 1.63 170 RecomputeSpeed = 0 180 RedrawLem = 0 190 GoRight = 0 : GoUp = 0 : GoLeft = 0 200 Score = 0 210 GMx = MM.HRES - 1 220 GMy = MM.VRES - 1 230 PRINT "Press a key to Start" 240 IF INKEY$ = "" THEN GOTO 240 250 CLS 260 RANDOMIZE TIMER 270 'Landing platform position 280 Platformx = INT(RND * (GMx -40)) + 20 290 Platformy = INT(RND * 80) + (GMy - 80) 300 'Here we draw the terrain and the Landin platform 310 LINE (Platformx,Platformy)-(Platformx + 40,Platformy + 5),1,bf 320 FOR a = Platformx TO Platformx + 40 330 TEvel(a) = Platformy 340 NEXT a 350 'Terrain at Left from the platform 360 py = Platformy + (RND * 7) - 3 370 FOR a = Platformx - 1 TO 0 STEP - 1 380 py = py + (RND * 7) - 3 390 LINE (a,GMy) - (a,py),1 400 TEvel(a) = py 410 NEXT a 420 'Terrain at Right from the platform 430 py = Platformy + (RND * 7) - 3 440 FOR a = Platformx + 41 TO GMx 450 py = py + (RND * 7) - 3 460 LINE (a,GMy) - (a,py),1 470 TEvel(a) = py 480 NEXT a 490 'Terrain under the platform 500 FOR a = Platformx TO Platformx + 40 510 LINE (a,GMy) - (a,Platformy + 6),1 520 NEXT a 530 'LEM position at start 540 LemX = RND * (GMx - 40) + 20 550 LemY = RND * 50 + 25 560 OldLemX = LemX 570 OldLemY = LemY 580 ' Interrupt every 100mS 590 SETTICK 100,1540 600 'Main program loop 610 DO WHILE 1 620 'Read the buttons 630 IF PIN(11) = 0 THEN GoUP = 1 640 IF PIN(14) = 0 THEN GoRight = 1 650 IF PIN(13) = 0 THEN GoLeft = 1 660 ' 670 'This part is executed every 100mS 680 IF RecomputeSpeed = 1 THEN 690 LEMSpeed = LEMSpeed + (Gravity * 0.1) 700 IF (GoUP = 1) AND (Fuel > 0) THEN 710 LemSpeed = LemSpeed - (Gravity * 0.2) 720 Fuel = Fuel - 0.3 730 GoUp = 0 740 Booster = 1 750 ELSE 760 Booster = 0 770 ENDIF 780 IF (GoRight = 1) AND (Fuel > 0) THEN 790 Vx = Vx + 0.1 800 Fuel = Fuel - 0.1 810 GoRight = 0 820 ENDIF 830 IF (GoLeft = 1) AND (Fuel > 0) THEN 840 Vx = Vx - 0.1 850 Fuel = Fuel - 0.1 860 GoLeft = 0 870 ENDIF 880 'Record the LEM position 890 OldLemX = INT(LemX) : OldLemY = INT(LemY) 900 LemY = INT(LemY + LemSpeed) 910 LemX = INT(LemX + Vx) 920 'Clip the LEM in the screen 930 IF LemX > (GMx - 25) THEN LemX = GMx - 25 940 IF LemX < 5 THEN LemX = 5 950 IF LemY > (GMy - 20) THEN LemY = GMy - 20 960 IF LemY < 50 THEN LemY = 50 970 RecomputeSpeed = 0 980 ENDIF 990 'This part is executed every 100mS 1000 IF RedrawLem = 1 THEN 1010 LOCATE 0,0 : PRINT "Speed ";INT(LemSpeed) 1020 LOCATE 100,0 : PRINT "Fuel ";INT(Fuel) 1030 'We erase the old LEM and draw the new one 1040 LINE(OldLemX -1 , OldLemY - 1) - (OldLemX + 21 , OldLemY + 31),0,BF 1050 ' Draw the LEM TO new position 1060 LINE(LemX + 10 , LemY) - (LemX + 20 , LemY + 20),1 1070 LINE(LemX + 20 , LemY + 20) - (LemX + 20 , LemY + 30),1 1080 LINE(LemX + 20 , LemY + 30) - (LemX + 17 , LemY + 20),1 1090 LINE(LemX + 17 , LemY + 20) - (LemX + 3 , LemY + 20),1 1100 LINE(LemX + 3 , LemY + 20) - (LemX , LemY + 30),1 1110 LINE(LemX , LemY + 30) - (LemX , LemY + 20),1 1120 LINE(LemX , LemY + 20) - (LemX + 10 , LemY),1 1130 ' Draw the Booster if needed 1140 IF Booster = 1 THEN 1150 LINE(LemX + 6,LemY + 21) - (LemX + 13,LemY + 21),1 1160 LINE(LemX + 13,LemY + 21) - (LemX + 10,LemY + 30),1 1170 LINE (LemX + 10,LemY + 30) - (LemX + 6,LemY + 21),1 1180 Booster = 0; 1190 ENDIF 1200 'Test if we have landed or Collided 1210 RedrawLem = 0 1220 ENDIF 1230 'Test if we are over the platform 1240 IF LemY > (Platformy - 33) THEN 1250 IF (LemX >= Platformx) AND (Lemx < (Platformx + 20)) THEN 1260 'Landing test 1270 IF LemSpeed <= 2.0 THEN 1280 SOUND 1000,500 1290 LOCATE 10,50 : PRINT "Successfully Landed" 1300 PAUSE 2000 1310 PRINT "Press a key to restart" 1320 IF INKEY$ = "" THEN GOTO 1320 1330 RUN 1340 ELSE 1350 SOUND 500,500 1360 LOCATE 10,50 : PRINT "You Crashed !!!" 1370 PAUSE 2000 1380 PRINT "Press a key to restart" 1390 IF INKEY$ = "" THEN GOTO 1390 1400 RUN 1410 ENDIF 1420 ENDIF 1430 ENDIF 1440 'We check collision with the Terrain 1450 IF (TEvel(LemX) < (LemY + 32)) OR (TEvel(LemX + 20) < (LemY + 32)) THEN 1460 SOUND 500,500 1470 LOCATE 10,50 : PRINT "You Crashed !!!" 1480 PAUSE 2000 1490 PRINT "Press a key to restart" 1500 IF INKEY$ = "" THEN GOTO 1500 1510 RUN 1520 ENDIF 1530 LOOP 1540 'Timer interrup routine every 100mS 1550 RecomputeSpeed = 1 1560 RedrawLem = 1 1570 IRETURN Will be better with sound but i don't know how to made a Booster like noise, if someone got an idea i get it Enjoy. Theory is when we know everything but nothing work ... Practice is when everything work but no one know why ;) |
||||
Gadget Regular Member Joined: 22/06/2011 Location: AustraliaPosts: 70 |
Well done!! Just expanding on this i can see a whole lot of these types of games coming up, an to simplify the controls I think the use of the old Atari style joysticks would be an appropriate fit. so to allow this I reckon we should standardise on the inputs used for this and other games. pin 11 - Up Pin 12 - Down Pin 13 - Left Pin 14 - Right pin 15 - Fire an interface for one of these sticks wont be hard, as I remember they all have a common and a switch to that common, I'll have to pull apart once I get home. anyway just a thought, open for comments Terry |
||||
jman Guru Joined: 12/06/2011 Location: New ZealandPosts: 711 |
Hi I added the Wii numchuck code So now i can play this with my $3.50 numchuck All the wii variables are still there so maybe somebody wants to make it go with the accelerometer Regards Jman 10 'Lunar Lander for Maximite 20 ' 30 CLEAR 35 gosub 1600 ' Setup I2C 40 DIM TEvel(MM.HRES) 50 CLS 120 Booster = 0 130 LemSpeed = 0.1 140 SpeedX = 0.0 150 Fuel = 50.0 160 Gravity = 1.63 170 RecomputeSpeed = 0 180 RedrawLem = 0 190 GoRight = 0 : GoUp = 0 : GoLeft = 0 200 Score = 0 210 GMx = MM.HRES - 1 220 GMy = MM.VRES - 1 230 PRINT "Press a key to Start" 240 GOSUB 1690 245 if Button_Z = 1 then 240 250 CLS 260 RANDOMIZE TIMER 270 'Landing platform position 280 Platformx = INT(RND * (GMx -40)) + 20 290 Platformy = INT(RND * 80) + (GMy - 80) 300 'Here we draw the terrain and the Landin platform 310 LINE (Platformx,Platformy)-(Platformx + 40,Platformy + 5),1,bf 320 FOR a = Platformx TO Platformx + 40 330 TEvel(a) = Platformy 340 NEXT a 350 'Terrain at Left from the platform 360 py = Platformy + (RND * 7) - 3 370 FOR a = Platformx - 1 TO 0 STEP - 1 380 py = py + (RND * 7) - 3 390 LINE (a,GMy) - (a,py),1 400 TEvel(a) = py 410 NEXT a 420 'Terrain at Right from the platform 430 py = Platformy + (RND * 7) - 3 440 FOR a = Platformx + 41 TO GMx 450 py = py + (RND * 7) - 3 460 LINE (a,GMy) - (a,py),1 470 TEvel(a) = py 480 NEXT a 490 'Terrain under the platform 500 FOR a = Platformx TO Platformx + 40 510 LINE (a,GMy) - (a,Platformy + 6),1 520 NEXT a 530 'LEM position at start 540 LemX = RND * (GMx - 40) + 20 550 LemY = RND * 50 + 25 560 OldLemX = LemX 570 OldLemY = LemY 580 ' Interrupt every 100mS 590 SETTICK 100,1540 600 'Main program loop 610 DO WHILE 1 620 'Read the buttons 625 gosub 1690 ' Read I2C 630 IF Joy_Y = 255 THEN GoUP = 1 640 IF Joy_X = 255 THEN GoRight = 1 650 IF Joy_X = 0 THEN GoLeft = 1 660 ' 670 'This part is executed every 100mS 680 IF RecomputeSpeed = 1 THEN 690 LEMSpeed = LEMSpeed + (Gravity * 0.1) 700 IF (GoUP = 1) AND (Fuel > 0) THEN 710 LemSpeed = LemSpeed - (Gravity * 0.2) 720 Fuel = Fuel - 0.3 730 GoUp = 0 740 Booster = 1 750 ELSE 760 Booster = 0 770 ENDIF 780 IF (GoRight = 1) AND (Fuel > 0) THEN 790 Vx = Vx + 0.1 800 Fuel = Fuel - 0.1 810 GoRight = 0 820 ENDIF 830 IF (GoLeft = 1) AND (Fuel > 0) THEN 840 Vx = Vx - 0.1 850 Fuel = Fuel - 0.1 860 GoLeft = 0 870 ENDIF 880 'Record the LEM position 890 OldLemX = INT(LemX) : OldLemY = INT(LemY) 900 LemY = INT(LemY + LemSpeed) 910 LemX = INT(LemX + Vx) 920 'Clip the LEM in the screen 930 IF LemX > (GMx - 25) THEN LemX = GMx - 25 940 IF LemX < 5 THEN LemX = 5 950 IF LemY > (GMy - 20) THEN LemY = GMy - 20 960 IF LemY < 50 THEN LemY = 50 970 RecomputeSpeed = 0 980 ENDIF 990 'This part is executed every 100mS 1000 IF RedrawLem = 1 THEN 1010 LOCATE 0,0 : PRINT "Speed ";INT(LemSpeed) 1020 LOCATE 100,0 : PRINT "Fuel ";INT(Fuel) 1030 'We erase the old LEM and draw the new one 1040 LINE(OldLemX -1 , OldLemY - 1) - (OldLemX + 21 , OldLemY + 31),0,BF 1050 ' Draw the LEM TO new position 1060 LINE(LemX + 10 , LemY) - (LemX + 20 , LemY + 20),1 1070 LINE(LemX + 20 , LemY + 20) - (LemX + 20 , LemY + 30),1 1080 LINE(LemX + 20 , LemY + 30) - (LemX + 17 , LemY + 20),1 1090 LINE(LemX + 17 , LemY + 20) - (LemX + 3 , LemY + 20),1 1100 LINE(LemX + 3 , LemY + 20) - (LemX , LemY + 30),1 1110 LINE(LemX , LemY + 30) - (LemX , LemY + 20),1 1120 LINE(LemX , LemY + 20) - (LemX + 10 , LemY),1 1130 ' Draw the Booster if needed 1140 IF Booster = 1 THEN 1150 LINE(LemX + 6,LemY + 21) - (LemX + 13,LemY + 21),1 1160 LINE(LemX + 13,LemY + 21) - (LemX + 10,LemY + 30),1 1170 LINE (LemX + 10,LemY + 30) - (LemX + 6,LemY + 21),1 1180 Booster = 0; 1190 ENDIF 1200 'Test if we have landed or Collided 1210 RedrawLem = 0 1220 ENDIF 1230 'Test if we are over the platform 1240 IF LemY > (Platformy - 33) THEN 1250 IF (LemX >= Platformx) AND (Lemx < (Platformx + 20)) THEN 1260 'Landing test 1270 IF LemSpeed <= 2.0 THEN 1280 SOUND 1000,500 1290 LOCATE 10,50 : PRINT "Successfully Landed" 1300 PAUSE 2000 1310 PRINT "Press a key to restart" 1320 GOSUB 1690 1325 if Button_Z = 1 then 1320 1330 RUN 1340 ELSE 1350 SOUND 500,500 1360 LOCATE 10,50 : PRINT "You Crashed !!!" 1370 PAUSE 2000 1380 PRINT "Press a key to restart" 1390 GOSUB 1690 1395 if Button_Z = 1 then 1390 1400 RUN 1410 ENDIF 1420 ENDIF 1430 ENDIF 1440 'We check collision with the Terrain 1450 IF (TEvel(LemX) < (LemY + 32)) OR (TEvel(LemX + 20) < (LemY + 32)) THEN 1460 SOUND 500,500 1470 LOCATE 10,50 : PRINT "You Crashed !!!" 1480 PAUSE 2000 1490 PRINT "Press a key to restart" 1500 GOSUB 1690 1505 if Button_Z = 1 then 1500 1510 RUN 1520 ENDIF 1530 LOOP 1540 'Timer interrup routine every 100mS 1550 RecomputeSpeed = 1 1560 RedrawLem = 1 1570 IRETURN 1600 REM ReadWii Numchuck 1640 DIM RDbuff(255) 1650 i2caddr = &h52 ' Numchuck address 1660 I2CEN 400, 100 ' Enable I2C 1670 I2CSEND i2caddr, 0, 2, &hF0, &h55 1680 I2CSEND i2caddr, 0, 2, &hFB, &h0 1685 return 1690 I2CSEND i2caddr, 0, 1, &h0 1700 I2CRCV i2caddr, 0, 6, RDBuff(0) 1710 Joy_X = RDBuff(0) 1720 Joy_Y = RDBuff(1) 1730 Accel_X = RDBuff(2) 1740 Accel_Y = RDBuff(3) 1750 Accel_Z = RDBuff(4) 1760 IF (RDbuff(5) AND &h01) <> 0 THEN 1770 Button_Z = 1 1780 ELSE 1790 Button_Z = 0 1800 ENDIF 1810 IF (RDbuff(5) AND &h02) <> 0 THEN 1820 Button_C = 1 1830 ELSE 1840 Button_C = 0 1850 ENDIF 1980 return |
||||
Olimex Senior Member Joined: 02/10/2011 Location: BulgariaPosts: 226 |
you are my hero! what's next? snake game or the frog crossing street with cars :) |
||||
ajkw Senior Member Joined: 29/06/2011 Location: AustraliaPosts: 290 |
darthmite, For some white noise, which could sound like a burner, try 10 x = int(rnd*10000+100) 20 sound x,2 30 goto 10 The only problem is see is running it quick enough in the game. Great work on the series of games. Regards, Anthony. |
||||
darthmite Senior Member Joined: 20/11/2011 Location: FrancePosts: 240 |
Hi , On a loop i know that was possible to made a noise , but in a game we cant stop for sound , it have to work in background like the SOUND command. If a next version of MM Basic comes with extended sound function it can then be possible to do something like that in real time For the buttons layout i agree with Gadget, that will prevent us to every time change all cable on the MM I/O bus , actually i use a little 5 way joystick that is exactly connected like Gadget prediction !! (Do you read in my mind ?) pin 11 - Up Pin 12 - Down Pin 13 - Left Pin 14 - Right pin 15 - Fire And it's great to see that some on the forum like my little games examples On the 'Lunar Lander' example i have see that i have some graphic glitches. I think it come because the use of an interrupt. I made a black filled rectangle to erase the 'LEM' but sometimes not everything is erased. i have try to redraw the 'LEM' in black at the OldLemX ,OldLemY cooordinates but it's more worst as when i just draw a filled rectangle to erase it .... Actually i don't have found a solution for resolve this issue. Cheer. Theory is when we know everything but nothing work ... Practice is when everything work but no one know why ;) |
||||
Gadget Regular Member Joined: 22/06/2011 Location: AustraliaPosts: 70 |
For the buttons layout i agree with Gadget, that will prevent us to every time change all cable on the MM I/O bus , actually i use a little 5 way joystick that is exactly connected like Gadget prediction !! (Do you read in my mind ?) No not a mind reader, just great minds think alike, or is it Fools seldom differ? Terry |
||||
VK6MRG Guru Joined: 08/06/2011 Location: AustraliaPosts: 347 |
Could someone design a game controller interface for the Maximite? Its easier to ask forgiveness than to seek permission! ............VK6MRG.............VK3MGR............ |
||||
Olimex Senior Member Joined: 02/10/2011 Location: BulgariaPosts: 226 |
Joystick Arduino Shield is under development |
||||
jman Guru Joined: 12/06/2011 Location: New ZealandPosts: 711 |
We allready have one take a look at this post NumChuck Jman |
||||
Olimex Senior Member Joined: 02/10/2011 Location: BulgariaPosts: 226 |
Jman incredible :) I'll order one immediately and solder UEXT to it! I still do wonder how they can deliver it for $3.50 If I only have to post empty letter from Bulgaria to HK it will cost me more, Chinese post must be very cost efficient! |
||||
donmck Guru Joined: 09/06/2011 Location: AustraliaPosts: 1313 |
As I have said before in another thread, the Chinese Govt must subsidize all postage. I got 3 of the AC to 5V USB adapters for about $3.50, and the postage on the package was about $2.50, so they costs 33cents each? No way!!! Cheers Don... https://www.dontronics.com |
||||
Print this page |