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) Labyrinth generator
Author | Message | ||||
darthmite Senior Member Joined: 20/11/2011 Location: FrancePosts: 240 |
Heya, This time i made a little Labyrinth generator , it's not actually perfect because i get some unsolvable Laby but it can be a base to some who want made a Labyrinth style game. Here are some pics: and here the source: 10 'Labyrinth for Maximite 20 CLEAR 30 OPTION base 0 40 CLS 50 Labwidth = 15 60 Labheight = 10 70 DIM Neighbor(3) 80 DIM TmpLab(Labwidth,Labheight,9) 90 LOCATE 1,180 100 PRINT "Press a key to start" 110 '[presskey] 120 IF INKEY$ = "" GOTO 110 130 CLS 140 RANDOMIZE TIMER 150 'Initialize the Laby 160 FOR a = 0 TO Labwidth - 1 170 FOR b = 0 TO Labheight - 1 180 FOR c = 0 TO 3 190 TmpLab(a,b,c) = 1 200 NEXT c 210 TmpLab(a,b,4) = 0 220 NEXT b 230 NEXT a 240 'Create the Laby 250 CaseX = INT(RND * Labwidth) 260 CaseY = INT(RND * Labheight) 270 SensX = 0 280 SX = 1 290 SensY = 1 300 SY = 1 310 IF CaseY = Labheight - 1 THEN SensY = -1: SY = -1 320 IF CaseX = Labwidth - 1 THEN SX = -1 330 N = Labwidth * (Labheight - 1) 340 DO WHILE (N > 0) 350 TmpLab(CaseX , CaseY , 4) = 1 360 IF CaseY > 0 THEN 370 Neighbor(0) = TmpLab(CaseX , CaseY - 1 , 4) 380 ELSE 390 Neighbor(0) = 1 400 ENDIF 410 IF CaseX < (Labwidth - 1) THEN 420 Neighbor(1) = TmpLab(CaseX + 1 , CaseY , 4) 430 ELSE 440 Neighbor(1) = 1 450 ENDIF 460 IF CaseY < (Labheight - 1) THEN 470 Neighbor(2) = TmpLab(CaseX , CaseY + 1 , 4) 480 ELSE 490 Neighbor(2) = 1 500 ENDIF 510 IF CaseX > 0 THEN 520 Neighbor(3) = TmpLab(CaseX - 1 , CaseY , 4) 530 ELSE 540 Neighbor(3) = 1 550 ENDIF 560 IF (Neighbor(0) = 1) AND (Neighbor(1) = 1) AND (Neighbor(2) = 1) AND (Neighbor(3) = 1) THEN 570 CaseY = CaseY + SensY 580 CaseX = CaseX + SensX 590 SensX = 0 600 SensY = SY 610 ELSE 620 DO 630 a = INT(RND * 4) 640 IF a = 4 THEN a = 3 650 LOOP UNTIL (Neighbor(a) = 0) 660 IF a = 0 THEN 670 TmpLab(CaseX, CaseY , 0) = 0 680 CaseY = CaseY - 1 690 TmpLab(CaseX, CaseY , 2) = 0 700 ENDIF 710 IF a = 1 THEN 720 TmpLab(CaseX, CaseY , 1) = 0 730 CaseX = CaseX + 1 740 TmpLab(CaseX, CaseY , 3) = 0 750 ENDIF 760 IF a = 2 THEN 770 TmpLab(CaseX, CaseY , 2) = 0 780 CaseY = CaseY + 1 790 TmpLab(CaseX, CaseY , 0) = 0 800 ENDIF 810 IF a = 3 THEN 820 TmpLab(CaseX, CaseY , 3) = 0 830 CaseX = CaseX - 1 840 TmpLab(CaseX, CaseY , 1) = 0 850 ENDIF 860 N = N - 1 870 ENDIF 880 IF CaseX = Labwidth - 1 THEN 890 SX = -1: SensX = 0 900 ENDIF 910 IF CaseX = 0 THEN 920 SX = 1: SensX = 0 930 ENDIF 940 IF (CaseY = Labheight - 1 AND SY = 1) OR (CaseY = 0 AND SY = -1) THEN 950 SY = -SY: SensY = 0: SensX = SX 960 ENDIF 970 LOOP 980 'Create entry and output point 990 TmpLab(0, Labheight - 1 , 3) = 0 1000 TmpLab(Labwidth - 1, 0 , 1) = 0 1010 'Trace the Laby 1020 L = 10 1030 T = 10 1040 SelSize = 15 1050 FOR a = 0 TO Labwidth - 1 1060 FOR b = 0 TO Labheight - 1 1070 IF TmpLab(a, b , 0) = 1 THEN 1080 LINE (L + a * SelSize , T + b * SelSize ) - (L + (a + 1) * SelSize , T + b * SelSize), 1 1090 ENDIF 1100 IF TmpLab(a, b , 1) = 1 THEN 1110 LINE (L + (a + 1) * SelSize , T + b * SelSize ) - (L + (a + 1) * SelSize , T + (b + 1) * SelSize), 1 1120 ENDIF 1130 IF TmpLab(a, b , 2) = 1 THEN 1140 LINE (L + (a + 1) * SelSize , T + (b + 1) * SelSize) - (L + a * SelSize , T + (b + 1) * SelSize), 1 1150 ENDIF 1160 IF TmpLab(a, b , 3) = 1 THEN 1170 LINE (L + a * SelSize, T + (b + 1) * SelSize ) - (L + a * SelSize , T + b * SelSize), 1 1180 ENDIF 1190 NEXT b 1200 NEXT a 1210 LOCATE 1,180 1220 PRINT "Press a key to start" 1230 '[presskey] 1240 IF INKEY$ = "" GOTO 1230 1250 CLEAR 1260 RUN You can change the Width and Height here: 50 Labwidth = 15 60 Labheight = 10 If someone correct it to made a generator who create 100% solvable Laby each time , please post the source here. Cheer. Theory is when we know everything but nothing work ... Practice is when everything work but no one know why ;) |
||||
Gizmo Admin Group Joined: 05/06/2004 Location: AustraliaPosts: 5078 |
That works OK Darth, thanks for posting. I do remember a maze generating program from some time ago, I'll keep an eye out for it. I also remember one maze generating algorithm that took a room, added a wall to split the room into two, and then added a door way between the two rooms. It did this, splitting smaller and smaller rooms, until it reached the minimum room size, same size as the doorway/corridor. Glenn The best time to plant a tree was twenty years ago, the second best time is right now. JAQ |
||||
darthmite Senior Member Joined: 20/11/2011 Location: FrancePosts: 240 |
For this one i have convert a old VB6 prog , but after looking on wikipedia i have see that it exist allot maze algorithm I will probably try some other with MM basic and then get the best one to post here. Cheer. 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: BulgariaPosts: 226 |
Darthmite, you seems to be interested to make games. Do you want to betatest the new color Duinomite add-on board? It's Gameduino based modified for Duinomite and add 400x300 pixels with 512 colors VGA and sprites and characters specially made for game developments? PM me with your address and I will mail you one of the first prototypes so you can betatest it. Tsvetan |
||||
rhamer Senior Member Joined: 06/06/2011 Location: AustraliaPosts: 174 |
This is too bigger news to hide away here. How about creating another thread to announce this? BTW someone had better let Nick know, he's been wanting this since day 1. Cheers Rohan Rohan Hamer HAMFIELD Software & Hardware Solutions Makers of the Maximite Expander. http://www.hamfield.com.au |
||||
darthmite Senior Member Joined: 20/11/2011 Location: FrancePosts: 240 |
Hi Olimex , My interest is not really to develop game but get fun i seeing what i can push out the MM And as you know , games are the best way to do it. I know the Gameduino and Picaso board ,but because my work (R&D in industrial robotics) ,i will not have the time to adapt the API. Cheer. 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: BulgariaPosts: 226 |
ok, no problem, we will have few prototypes this month, note that the API will be supported in the DM firmware and there will be some kind of equivalents of PRINT, LINE, PIXEL etc probably GPRINT, GLINE, GPIXEL which draw on the second color screen if someone have interesting idea and want to betatest one of the first prototypes I will certainly have couple of prototypes extra beside these we will make for the DM development group the initial resolution is 400x300 512 colors, but we will add provisions for more RAM on our board so 800x600 pixels will be possible later with the same board just with updated FPGA firmware |
||||
Print this page |