I would like to know what I could improve on:
-code structure and neatness
-code useage
-graphics(no media)
Thanks!
` ~~~BrickFlip~~~
` Aug 20,2009
set display mode 1024,768,32
sync on:sync rate 0
randomize timer()
set text font "Times New Roman",1
set text size 75
gosub loadlevels
gosub makeimages
dim Tbrick(6,6)
dim oldTbrick(6,6)
dim rndX(3)
dim rndY(3)
midwidth=screen width()/2
midheight=screen height()/2
lives=5
turns=1
oldlevel=level
gosub menu
gosub setup
` ~~~MAIN LOOP~~~
DO
gosub pasteimages
gosub status
if mouseclick()=1 then gosub mouseclick
sync:cls
LOOP
END
` ~~~Sub-Files~~~
Loadlevels:
If File Exist("BFlevels.txt")=1
`Read File
OPEN to read 1,"BFlevels.txt"
Read String 1,T$: maxlev=Val(T$)
Dim Brick(maxlev,6,6)
for n=1 to maxlev
Read String 1,T$: Brick(n,0,0)=Val(T$)
next n
`bricktype
for lev=1 to maxlev
for y=1 to brick(lev,0,0)
for x=1 to brick(lev,0,0)
Read String 1,T$: Brick(lev,x,y)=Val(T$)
next x
next y
next lev
CLOSE file 1
else
restore datastart
`Read Date
Read maxlev
dim brick(maxlev,6,6)
`size
for n=1 to maxlev
read brick(n,0,0)
next n
`bricktype
for lev=1 to maxlev
for y=1 to brick(lev,0,0)
for x=1 to brick(lev,0,0)
Read Brick(lev,x,y)
next n
next y
next lev
endif
Return
Setup:
level=level+1
Glevel=Glevel+1
if level>maxlev
level=1
turns=turns+1
lives=5
endif
if turns>3
turns=3
level=rnd(maxlev-1)+1
endif
turnsleft=turns
for y=1 to brick(level,0,0)
for x=1 to brick(level,0,0)
Tbrick(x,y)=brick(level,x,y)
next x
next y
for n=1 to turns
`goto
back:
rndX(n)=rnd(brick(level,0,0)-1)+1
rndY(n)=rnd(brick(level,0,0)-1)+1
if rndX(2)=rndX(1) and rndY(2)=rndY(1) and n=2 then goto back
if rndX(3)=rndX(1) and rndY(3)=rndY(1) and n=3 or rndX(3)=rndX(2) and rndY(3)=rndY(2) and n=3 then goto back
if rndX(n)-1>0
if rndY(n)+1<=brick(level,0,0) then Tbrick(rndX(n)-1,rndY(n)+1)=3-Tbrick(rndX(n)-1,rndY(n)+1)
Tbrick(rndX(n)-1,rndY(n))=3-Tbrick(rndX(n)-1,rndY(n))
if rndY(n)-1>0 then Tbrick(rndX(n)-1,rndY(n)-1)=3-Tbrick(rndX(n)-1,rndY(n)-1)
endif
if rndX(n)+1<=brick(level,0,0)
if rndY(n)+1<=brick(level,0,0) then Tbrick(rndX(n)+1,rndY(n)+1)=3-Tbrick(rndX(n)+1,rndY(n)+1)
Tbrick(rndX(n)+1,rndY(n))=3-Tbrick(rndX(n)+1,rndY(n))
if rndY(n)-1>0 then Tbrick(rndX(n)+1,rndY(n)-1)=3-Tbrick(rndX(n)+1,rndY(n)-1)
endif
if rndY(n)+1<=brick(level,0,0) then Tbrick(rndX(n),rndY(n)+1)=3-Tbrick(rndX(n),rndY(n)+1)
Tbrick(rndX(n),rndY(n))=3-Tbrick(rndX(n),rndY(n))
if rndY(n)-1>0 then Tbrick(rndX(n),rndY(n)-1)=3-Tbrick(rndX(n),rndY(n)-1)
next n
for y=1 to brick(level,0,0)
for x=1 to brick(level,0,0)
oldTbrick(x,y)=Tbrick(x,y)
next x
next y
oldtime=timer()
While forever=0
`background
paste image 4,imaX,0,1
paste image 4,imaX+1024,0,1
imaX=imaX-1
if imaX<-1024 then imaX=0
set text size 100
text 340,250, "LEVEL:"+str$(Glevel)
if timer()-oldtime>1500 then Exit
sync:cls
Endwhile
Return
Menu:
press=1
select=0
While forever=0
mx=mousex()
my=mousey()
`background
paste image 4,imaX,0,1
paste image 4,imaX+1024,0,1
imaX=imaX-1
if imaX<-1024 then imaX=0
ink rgb(130,30,0),0
if select=1 then box 400,330,635,365
if select=2 then box 400,390,635,425
if select=3 then box 400,450,635,485
if select=4 then box 400,510,635,545
`options
set text size 155
ink rgb(200,90,0),0
text midwidth-255,160, "BrickFlip"
set text size 35
text 408,330, " START GAME"
text 403,390, " INSTRUCTIONS"
text 405,450, " LEVEL EDITOR"
text 408,510, " EXIT GAME"
`mouse position
select=0
if mx>400 and mx<635 and my>330 and my<365 then select=1
if mx>400 and mx<635 and my>390 and my<425 then select=2
if mx>400 and mx<635 and my>450 and my<485 then select=3
if mx>400 and mx<635 and my>510 and my<545 then select=4
if mouseclick()=0 then press=0
if mouseclick() and select=1 and press=0 then EXIT
if mouseclick() and select=2 and press=0 then gosub instuctions
if mouseclick() and select=3 and press=0 then gosub editor
if mouseclick() and select=4 and press=0 then END
sync:cls
Endwhile
Return
Makeimages:
ink rgb(185,70,0),0
box 0,0,74,74
ink rgb(210,95,0),0
box 1,1,73,73
ink rgb(235,120,0),0
box 2,2,72,72
ink rgb(255,148,0),0
box 3,3,71,71
for y=4 to 70
for x=4 to 70
ink rgb(rnd(40)+215,rnd(40)+120,0),0
dot x,y
next x
next y
get image 1,0,0,74,74:cls
ink rgb(80,10,0),0
box 0,0,74,74
ink rgb(100,25,0),0
box 1,1,73,73
ink rgb(125,40,0),0
box 2,2,72,72
ink rgb(145,60,0),0
box 3,3,71,71
for y=4 to 70
for x=4 to 70
ink rgb(rnd(40)+125,rnd(40)+40,0),0
dot x,y
next x
next y
get image 2,0,0,74,74:cls
ink rgb(120,30,0),0
box 0,0,74,74
ink rgb(140,55,0),0
box 1,1,73,73
ink rgb(165,70,0),0
box 2,2,72,72
ink rgb(185,90,0),0
box 3,3,71,71
for y=4 to 70
for x=4 to 70
ink rgb(rnd(40)+165,rnd(40)+70,0),0
dot x,y
next x
next y
get image 3,0,0,74,74:cls
ink rgb(255,255,255),0
text 320,620, "LOADING..."
for y=0 to 768
for x=0 to 1024
ink rgb((rnd(20)*3)+185,(rnd(20)*3)+120,0),0
dot x,y
next x
next y
get image 4,0,0,1024,768:cls
Return
Mouseclick:
press=1
Repeat
gosub pasteimages
x=0
y=0
mx=mousex()
my=mousey()
`find brick under mouse
for y1=1 to brick(level,0,0)
for x1=1 to brick(level,0,0)
if mx>(x1*75)-50 and my>(y1*75)+75 and mx<(x1*75)+25 and my<(y1*75)+150 then x=x1:y=y1:goto skip
next x1
next y1
`goto
skip:
`change bricks
if x>0 and y>0
`half brick image
if x-1>0
if y+1<=brick(level,0,0) then paste image 3,((x-1)*75)-50,((y+1)*75)+75,1
paste image 3,((x-1)*75)-50,((y)*75)+75,1
if y-1>0 then paste image 3,((x-1)*75)-50,((y-1)*75)+75,1
endif
if x+1<=brick(level,0,0)
if y+1<=brick(level,0,0) then paste image 3,((x+1)*75)-50,((y+1)*75)+75,1
paste image 3,((x+1)*75)-50,((y)*75)+75,1
if y-1>0 then paste image 3,((x+1)*75)-50,((y-1)*75)+75,1
endif
if y+1<=brick(level,0,0) then paste image 3,((x)*75)-50,((y+1)*75)+75,1
paste image 3,((x)*75)-50,((y)*75)+75,1
if y-1>0 then paste image 3,((x)*75)-50,((y-1)*75)+75,1
endif
if mouseclick()=0 then Exit
sync:cls
Until forever=1
x=0
y=0
mx=mousex()
my=mousey()
`find brick under mouse
for y1=1 to brick(level,0,0)
for x1=1 to brick(level,0,0)
if mx>(x1*75)-50 and my>(y1*75)+75 and mx<(x1*75)+25 and my<(y1*75)+150 then x=x1:y=y1:goto skip2
next x1
next y1
`goto
skip2:
if x>0 and y>0
`change brick image
if x-1>0
if y+1<=brick(level,0,0) then Tbrick(x-1,y+1)=3-Tbrick(x-1,y+1)
Tbrick(x-1,y)=3-Tbrick(x-1,y)
if y-1>0 then Tbrick(x-1,y-1)=3-Tbrick(x-1,y-1)
endif
if x+1<=brick(level,0,0)
if y+1<=brick(level,0,0) then Tbrick(x+1,y+1)=3-Tbrick(x+1,y+1)
Tbrick(x+1,y)=3-Tbrick(x+1,y)
if y-1>0 then Tbrick(x+1,y-1)=3-Tbrick(x+1,y-1)
endif
if y+1<=brick(level,0,0) then Tbrick(x,y+1)=3-Tbrick(x,y+1)
Tbrick(x,y)=3-Tbrick(x,y)
if y-1>0 then Tbrick(x,y-1)=3-Tbrick(x,y-1)
turnsleft=turnsleft-1
endif
Return
Status:
match=1
for y=1 to brick(level,0,0)
for x=1 to brick(level,0,0)
if Tbrick(x,y)<>brick(level,x,y) then match=0
next x
next y
if match=1
hide mouse
oldtime=timer()
While forever=0
gosub pasteimages
if timer()-oldtime>1400 then Exit
sync:cls
Endwhile
show mouse
gosub setup
endif
if turnsleft=0
hide mouse
oldtime=timer()
While forever=0
gosub pasteimages
if timer()-oldtime>1300 then Exit
sync:cls
Endwhile
show mouse
for y=1 to brick(level,0,0)
for x=1 to brick(level,0,0)
Tbrick(x,y)=oldTbrick(x,y)
next x
next y
lives=lives-1
turnsleft=turns
endif
if mousex()>893 and mousex()<980 and mousey()>697 and mousey()<730 and mouseclick()=1 then lives=0
if lives=0
num=num+1
if num=2
hide mouse
oldtime=timer()
While forever=0
gosub pasteimages
if timer()-oldtime>1500 then Exit
sync:cls
Endwhile
press=1
While forever=0
`background
paste image 4,imaX,0,1
paste image 4,imaX+1024,0,1
imaX=imaX-1
if imaX<-1024 then imaX=0
set text size 100
text 255,200, "GAME OVER"
text 340,300, "LEVEL:"+str$(Glevel)
if mouseclick()=0 then press=0
if mouseclick()=1 and press=0 then Exit
sync:cls
Endwhile
show mouse
Glevel=0
level=0
lives=5
turns=1
num=0
gosub menu
endif
endif
Return
Pasteimages:
`background
paste image 4,imaX,0,1
paste image 4,imaX+1024,0,1
imaX=imaX-1
if imaX<-1024 then imaX=0
`bricks
for y=1 to brick(level,0,0)
for x=1 to brick(level,0,0)
paste image TBrick(x,y),(x*75)-50,(y*75)+75,1
paste image Brick(level,x,y),((x+7+(6-brick(level,0,0)))*75)-50,(y*75)+75,1
next x
next y
if mousex()>893 and mousex()<980 and mousey()>697 and mousey()<730 then ink rgb(130,30,0),0:box 893,697,979,736
set text size 35
ink rgb(200,90,0),0
text 30,8, "TURNS:"+str$(turnsleft)
text 30,58, "LIVES:"+str$(lives)
text 30,108, "LEVEL:"+str$(Glevel)
text 900,700, "QUIT"
Return
Instuctions:
press=1
select=0
set text size 25
While forever=0
`background
paste image 4,imaX,0,1
paste image 4,imaX+1024,0,1
imaX=imaX-1
if imaX<-1024 then imaX=0
text 230,200, "Get the left set of bricks to match the right set. To do"
text 230,230, "this click on a brick, the brick clicked on and the ones"
text 230,260, "around it get fliped. You have five lives for every nine"
text 230,290, "levels. Each level will tell you how many turns it takes"
text 230,320, "to complete it. The turns for each nine levels increase."
text 230,350, "Edit levels to make the game easier or harder."
if mouseclick()=0 then press=0
if mouseclick()=1 and press=0 then Exit
sync:cls
Endwhile
press=1
Return
Editor:
press=1
Elevel=1
While forever=0
`background
paste image 4,imaX,0,1
paste image 4,imaX+1024,0,1
imaX=imaX-1
if imaX<-1024 then imaX=0
text 30,8, "Left click to change brick"
text 30,58, "Right click to exit"
text 30,108, "S key to save and R key to reset"
text 450,8, "Switch levels by useing the number keys"
text 450,58, "LEVEL:"+str$(Elevel)
`Elevel
for n=2 to 10
if keystate(n)=1 then Elevel=n-1
next n
`save
if keystate(31)=1
If File Exist("BFlevels.txt")=1 Then Delete File "BFlevels.txt"
`Write to File
OPEN to write 1,"BFlevels.txt"
write String 1,str$(maxlev)
for n=1 to maxlev
write String 1,str$(Brick(n,0,0))
next n
`bricktype
for lev=1 to maxlev
for y=1 to brick(lev,0,0)
for x=1 to brick(lev,0,0)
write String 1,str$(Brick(lev,x,y))
next x
next y
next lev
CLOSE file 1
endif
`reset
if keystate(19)=1
If File Exist("BFlevels.txt")=1 Then Delete File "BFlevels.txt"
gosub loadlevels
endif
`bricks
for y=1 to brick(Elevel,0,0)
for x=1 to brick(Elevel,0,0)
paste image brick(Elevel,x,y),(x*75)-50,(y*75)+75,1
next x
next y
`mouseclick
if mouseclick()=0 then press=0
if mouseclick()=1 and press=0
press=1
mx=mousex()
my=mousey()
`find brick under mouse
for y1=1 to brick(Elevel,0,0)
for x1=1 to brick(Elevel,0,0)
if mx>(x1*75)-50 and my>(y1*75)+75 and mx<(x1*75)+25 and my<(y1*75)+150 then brick(Elevel,x1,y1)=3-brick(Elevel,x1,y1)
next x1
next y1
endif
if mouseclick()=2 then exit
sync:cls
Endwhile
select=0
Return
` ~~~DATA~~~
DataStart:
`Maxlev
data 9
`Sizes
data 4,4,4,5,5,5,6,6,6
`Bricktype
data 2,2,2,2
data 2,1,1,2
data 2,1,1,2
data 2,2,2,2
data 2,1,1,2
data 1,2,2,1
data 1,2,2,1
data 2,1,1,2
data 1,2,2,1
data 2,1,1,2
data 2,1,1,2
data 1,2,2,1
data 1,2,1,2,1
data 2,1,1,1,2
data 1,1,2,1,1
data 2,1,1,1,2
data 1,2,1,2,1
data 1,2,2,2,1
data 2,1,1,1,2
data 2,1,2,1,2
data 2,1,1,1,2
data 1,2,2,2,1
data 1,1,2,1,1
data 1,2,2,2,1
data 2,2,1,2,2
data 1,2,2,2,1
data 1,1,2,1,1
data 1,2,2,2,2,1
data 2,1,1,1,1,2
data 2,1,2,2,1,2
data 2,1,2,2,1,2
data 2,1,1,1,1,2
data 1,2,2,2,2,1
data 2,1,1,1,1,2
data 1,2,2,2,2,1
data 1,2,1,1,2,1
data 1,2,1,1,2,1
data 1,2,2,2,2,1
data 2,1,1,1,1,2
data 2,1,1,1,1,2
data 1,2,1,1,2,1
data 1,1,2,2,1,1
data 1,1,2,2,1,1
data 1,2,1,1,2,1
data 2,1,1,1,1,2
This is non-media but will create a file if you save in level editer.(The reset button erases the file.)
Without caffeine, where would our awesome programers be?