Breakout style game level editor by Matt McFarland30th Nov 2003 3:37
|
---|
Summary Make breakout levels with ease, save and load. Description You'll have to pay attention closely to the First few lines of the main loop to see how it translates the grid() array into what you see on the board. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com `Created by "ToneArti" (tonechild2000@yahoo.com) `Free Source for all who want to learn more about DBPro `Made on Nov 30th, 2003 `Special Thanks goes to: `Beginner's Guide to DB Programming (a great book for beginners like me!) `CattleRustler from the forums `DBoy780 from the forums `Thanks you two!!!! without you I wouldnt have been able to make this thing! load image "reblock.png",1 load image "grblock.png",2 load image "ylblock.png",3 load image "prblock.png",4 load image "blblock.png",5 load image "eraser.png",6 load image "blank.png",7 DIM Top$(4) DIM Button$(6) DIM Grid(118) FileMenu: DATA 1 DATA "New","Load","Save","Exit" Buttons: DATA 1 DATA "reblock","grblock","ylblock","prblock","blblock","eraser" Remdata = 0 `Set variables Restore FileMenu For I = 0 to 4 Read Top$(I) next I Restore Buttons For I = 0 to 6 Read Button$(I) Next I create bitmap 1,640,480 `Create Grid Create_Grid: CLS for I = 60 to 580 step 60 line I,65,I,307 next I for I = 64 to 308 step 22 line 60,I,541,I next I Create_Menu: line 1,28,640,28 line 1,440,640,440 For I = 1 to 220 step 60 Inc T if T > 4 then T = 4 Text I,1,Top$(T) next I T=0 `reset T For I = 120 to 420 step 60 Inc T if T > 6 then T = 6 Paste Image T,I,450 next I set current bitmap 0 sync rate 60 selection1=1 selection2=7 restart: for Y=64 to 308 step 22 for X=60 to 580 step 60 set current bitmap 1 paste image 7,X,Y next X next Y UNDIM grid(118) DIM grid(118) for gridno=1 to 118 grid(gridno)=0 next gridno `Main Loop MainLoop: do set current bitmap 1 for gridno = 1 to 118 if grid(gridno)<>0 gridno$ = STR$(gridno) if LEN(gridno$) = 3 gridY = VAL(LEFT$(gridno$,2)) GridX = VAL(RIGHT$(gridno$,1)) else gridY = VAL(LEFT$(gridno$,1)) GridX = VAL(RIGHT$(gridno$,1)) Endif paste image grid(gridno),gridX*60,gridY*22+42 EndIf next gridno for I = 60 to 580 step 60 `redraw the lines so they stay on the screen, lol. line I,65,I,307 next I for I = 64 to 308 step 22 line 60,I,541,I next I set current bitmap 0 copy bitmap 1,0 ` moving the bitmap back and forth works. `Show the mouse coordinates for easy debugging text 540,450,STR$(mouseX()) text 568,450,"," text 580,450,STR$(mouseY()) `the show status is the event procedure that shows what your brush is painting with gosub ShowStatus `You can use the left mouse button or the right mouse button to paint, its fun! delay = TIMER() if mouseclick()=1 then gosub MouseOperation1 if mouseclick()=2 then gosub MouseOperation2 ` if mouseclick()=3 then gosub MouseOperation3 sync loop MouseOperation1: `Bottom Menu Buttons if mouseX()>=121 and mouseX()<=178 and mouseY()<=472 and mouseY()>=449 then selection1=1 if mouseX()>=181 and mouseX()<=238 and mouseY()<=472 and mouseY()>=449 then selection1=2 if mouseX()>=241 and mouseX()<=298 and mouseY()<=472 and mouseY()>=449 then selection1=3 if mouseX()>=301 and mouseX()<=358 and mouseY()<=472 and mouseY()>=449 then selection1=4 if mouseX()>=361 and mouseX()<=418 and mouseY()<=472 and mouseY()>=449 then selection1=5 if mouseX()>=421 and mouseX()<=478 and mouseY()<=472 and mouseY()>=449 then selection1=7 `Painting Operations gridX=GetGridX() gridY=GetGridY() if gridX<>0 and gridY<>0 set current bitmap 1 ` paste image selection1,gridX*60,gridY*22+42 `ie: 810 (8y,10x) ComplexGrid$ = STR$(GridY)+STR$(GridX) ComplexGrid = VAL(ComplexGrid$) Grid(ComplexGrid) = selection1 set current bitmap 0 EndIf for I = 60 to 580 step 60 line I,65,I,307 next I for I = 64 to 308 step 22 line 60,I,541,I next I `Main Menu Buttons if mouseX()<=64 and mouseY()<=14 then goto restart if mouseX()>=60 and mouseX()<=94 and mouseY()<=14 then gosub Load if mouseX()>=120 and mouseX()<=152 and mouseY()<=14 then gosub Save if mouseX()>=180 and mouseX()<=214 and mouseY()<=14 then End return MouseOperation2: `Bottom Menu Buttons if mouseX()>=121 and mouseX()<=178 and mouseY()<=472 and mouseY()>=449 then selection2=1 if mouseX()>=181 and mouseX()<=238 and mouseY()<=472 and mouseY()>=449 then selection2=2 if mouseX()>=241 and mouseX()<=298 and mouseY()<=472 and mouseY()>=449 then selection2=3 if mouseX()>=301 and mouseX()<=358 and mouseY()<=472 and mouseY()>=449 then selection2=4 if mouseX()>=361 and mouseX()<=418 and mouseY()<=472 and mouseY()>=449 then selection2=5 if mouseX()>=421 and mouseX()<=478 and mouseY()<=472 and mouseY()>=449 then selection2=7 `Painting Operations gridX=GetGridX() gridY=GetGridY() if gridX<>0 and gridY<>0 set current bitmap 1 ` paste image selection2,gridX*60,gridY*22+42 `ie: 8103 (8y,10x) ComplexGrid$ = STR$(GridY)+STR$(GridX) ComplexGrid = VAL(ComplexGrid$) Grid(ComplexGrid) = selection2 set current bitmap 0 EndIf for I = 60 to 580 step 60 line I,65,I,307 next I for I = 64 to 308 step 22 line 60,I,541,I next I return return ShowStatus: if selection1 <> 7 then paste image selection1,500,1,0 if selection2 <> 7 then paste image selection2,570,1,0 if selection1 = 7 then paste image 6,500,1,0 if selection2 = 7 then paste image 6,570,1,0 return Load: `clear all variables undim gridY() undim GridX() dim GridX(8) dim GridY(11) for Y=64 to 308 step 22 for X=60 to 580 step 60 set current bitmap 1 paste image 7,X,Y next X next Y set current bitmap 0 `start load interface cls DIR print "all levels have a '.lv' extension" input "Enter File Name(do not use extension) :",FILE$ FILE$=FILE$+".lv" if FILE EXIST(FILE$)=0 print "File does not exist. press a key to continue":print wait key goto Load EndIf `load file cls print "Loading...." sleep 10 OPEN TO READ 1,FILE$ for gridno = 1 to 118 READ FILE 1,Grid(gridno) next gridno print "Cleaning file..." for gridno = 1 to 118 if Grid(gridno) = 7 then Grid(gridno) = 0 next gridno CLOSE FILE 1 return Save: `We're going to need to save this, but how? cls `delete bitmap 0 input "Enter file name (do not use extension) :",FILE$ if file exist(FILE$+".lv") = 1 question: input "File already exists! Overwrite?(y/n)",overwrite$ if overwrite$<>"Y" and overwrite$<>"y" and overwrite$<>"N" and overwrite$<>"n" then goto question if overwrite$="y" or overwrite$="Y" DELETE FILE (FILE$+".lv") Endif if overwrite$="n" or overwrite$="N" then goto Save EndIf fullname$ = FILE$+".lv" OPEN TO WRITE 1,fullname$ print "Cleaning File..." for gridno = 1 to 118 if Grid(gridno) = 7 then Grid(gridno) = 0 next gridno for gridno = 1 to 118 WRITE FILE 1,Grid(gridno) print "Grid Coordinates:",gridno, " = ",Grid(gridno) next gridno CLOSE FILE 1 print "file successfully saved. " sleep 1000 return Function GetGridX() T=0 for I = 60 to 500 step 60 inc T if mouseX()>=I and mouseX()<=I+60 then gridX=T next I EndFunction (gridX) Function GetGridY() T=0 for I = 64 to 291 step 22 inc T if mouseY()>=I and mouseY()<=I+60 then gridY=T next I EndFunction (GridY) |