kk, srry.
sync on : randomize timer()
gosub init_stuff
gosub load_media
gosub main_menu
loop music 2
loadlevel("levels.txt",1)
`--------------------------------------------------
`MAIN LOOP
`--------------------------------------------------
do
gosub check_input
gosub update_stuff
gosub move_ball
if returnkey()=1 then gosub main_menu
if brickdata(0,1)=0
inc currentlevelnumber
loadlevel("levels.txt",currentlevelnumber)
ballff=0
endif
sync
loop
`-----------------------------------------------
`SUBROUTINES
`-----------------------------------------------
init_stuff:
rem this array hold data concerning bricks
rem (x,0) = brick type
rem (x,1) = x coordinate
rem (x,2) = y coordinate
rem (0,0) = number of bricks in level
rem (0,1) = number of alive bricks
dim brickdata(200,2)
currentlevelnumber=1
rem Lives
NumberofLives=3
rem this bmp will hold the current score
create bitmap 2,420,40
rem this bmp will be updated with current brick data
create bitmap 1,640,480
return
load_media:
cls rgb(0,118,163) : rem this is the color of the menu
rem border
load image "Media/Images/backdrop.png",1
rem bricks, 4 types
load image "Media/Images/bricks.png",1000
paste image 1000,0,0
get image 99,0,48,64,64
get image 101,0,144,63,160
get image 102,0,0,63,16
get image 103,0,16,63,32
get image 104,0,160,64,176
delete image 1000
rem paddle
load image "Media/Images/Paddle.PNG",3
cls 0
rem ball
load image "Media/Images/Ball.png",2
rem score font
load image "Media/Images/font.PNG",300
rem split score font image into 10 digits
paste image 300,0,0
for dig=0 to 9
get image 301+dig,40*dig,0,40*(dig+1),40
next dig
cls 0
delete image 300
load image "Media/Images/rightarrow.PNG",201
load image "Media/Images/leftarrow.PNG",202
load music "Media/Audio/DNG_menu_2.mp3",1
load music "Media/Audio/DNG_maingame_v2.mp3",2
load sound "Media/Audio/Metal Brick hit.WAV",2
return
main_menu:
if music playing(1)=0 then loop music 1
if music playing(2) then pause music 2 : mainmusic=1
set current bitmap 0
for s=1 to 5
if sprite exist(s) then hide sprite s
next s
load image "Media/Images/mainmenu.png",200
paste image 200,0,0
ink rgb(0,255,255),0
Choice=0 : play=0 : help=0 : credits=0 : exitf=0
repeat
if mouseover(300,290,380,325)=1
line_box(300,290,380,325)
if mouseclick()=1 then Play=1
endif
if mouseover(300,325,375,365)=1
line_box(300,325,375,365)
if mouseclick()=1 then Help=1
endif
if mouseover(300,365,405,395)=1
line_box(300,365,395,400)
if mouseclick()=1 then Credit=1
endif
if mouseover(300,400,365,435)=1
line_box(300,400,365,435)
if mouseclick()=1 then end
endif
sync
cls 0
paste image 200,0,0
Choice=Play + (2*Help) + (3*Credit)
until Choice>0
select Choice
case 2
rem Help
gosub Instructions
endcase
case 3
rem Credits
gosub Credits
endcase
endselect
set current bitmap 1 : cls : set current bitmap 0 : cls
for s=1 to 5
if sprite exist(s) then show sprite s
next s
stop music 1
if mainmusic=1 then loop music 2 : mainmusic=0
cls 0
return
check_input:
inc paddlex, 6*(rightkey() - leftkey() )
if paddlex<80 then paddlex=80
if paddlex>560 then paddlex=560
if spacekey()=1 and ballff=0
ballff=1
ballx#=paddlex
bally#=455
ballmovey#=1.5
ballmovex#=(rnd(1)-.5)*2
endif
if Die=1
dec NumberofLives
ballff=0
if NumberofLives < 1 then GoSub Main_Menu
Die=0
endif
return
update_stuff:
set current bitmap 1
count=0
cls 0
n=0
repeat
inc count
if brickdata(count,0)<>0
paste image brickdata(count,0)+100,brickdata(count,1)-32,brickdata(count,2)-8
if brickdata(count,0)>0 then inc n
endif
until count=brickdata(0,0)
brickdata(0,1)=n : rem number of currently alive bricks
get image 4,0,0,639,479
set current bitmap 2
cls rgb(255,255,255)
ink 0,0
score$=TenDigitScore$(score)
i=1
for x=0 to 380 step 40
paste image 301+val(mid$(score$,i)),x,0
inc i
next x
get image 5,0,0,400,40
set current bitmap 0
Rem Show Lives Remaining...
ink RGB(255,255,255),0
Center Text 470,420,"Lives"
Line 440,435,500,435
Center Text 470,440,Str$(NumberofLives)
sprite 1,0,0,1 : rem border
sprite 3,paddlex-40,460,3 : rem paddle
sprite 4,0,0,4 : rem bricks
sprite 5,230,5,5 : rem score
size sprite 5,380,30
return
check_collision:
col=sprite collision(2,0)
select col
case 1 : rem border collision
if ballx#<=45 and ballmovex#<0 then ballmovex#=-1*ballmovex#
if bally#<=45 and ballmovey#>0 then ballmovey#=-1*ballmovey#
if ballx#>=595 and ballmovex#>0 then ballmovex#=-1*ballmovex#
endcase
case 3 : rem paddle collision
oldballmovex#=ballmovex#
ballmovey#=1.5
ballmovex#=(1/30.0)*(ballx#-paddlex)
ballmovex#=(ballmovex#+oldballmovex#)/2
endcase
case 4 : rem brick collision
if get_brick((ballx#-6),bally#)>0
b=get_brick(ballx#-6,bally#)
rem left of ball collision
brickAI = brickAI(b)
inc score,rgbr(brickAI)
if rgbg(brickAI)=1 and ballmovex#<0 then ballmovex#=-1*ballmovex#
endif
if get_brick(ballx#,bally#-6)>0
b=get_brick(ballx#,bally#-6)
rem top of ball collision
brickAI = brickAI(b)
inc score,rgbr(brickAI)
if rgbg(brickAI)=1 and ballmovey#>0 then ballmovey#=-1*ballmovey#
endif
if get_brick(ballx#+6,bally#)>0
b=get_brick(ballx#+6,bally#)
rem right of ball collision
brickAI = brickAI(b)
inc score,rgbr(brickAI)
if rgbg(brickAI)=1 and ballmovex#>0 then ballmovex#=-1*ballmovex#
endif
if get_brick(ballx#,bally#+6)>0
b=get_brick(ballx#,bally#+6)
rem bottom of ball collision
brickAI = brickAI(b)
inc score,rgbr(brickAI)
if rgbg(brickAI)=1 and ballmovey#<0 then ballmovey#=-1*ballmovey#
endif
endcase
endselect
return
move_ball:
if ballff=1
for i=1 to 3
inc ballx#,ballmovex#
dec bally#,ballmovey#
sprite 2,ballx#-5,bally#-5,2
col=sprite hit(2,1)+sprite hit(2,3)+sprite hit(2,4)
inc col,sprite collision(2,1)+sprite collision(2,3)+sprite collision(2,4)
if col>0 then gosub check_collision
if bally#>=545 then Die=1
next i
else
sprite 2,paddlex-5,450,2
endif
return
return
Instructions:
dim Instructions$(2,10)
open to read 1,"Instructions.txt"
for x=1 to 2
count=1
read string 1,s$
Instructions$(x,0)=right$(left$(s$,len(s$)-1),len(s$)-2)
read string 1,s$
repeat
Instructions$(x,count)=s$
read string 1,s$
inc count
until s$=";"
Instructions$(0,x)=str$(count-1)
next x
close file 1
currentpage=1
cls rgb(0,118,163)
ink 0,0
do
set text size 40
center text 320,0,Instructions$(Currentpage,0)
set text size 15
for l=1 to val(Instructions$(0,currentpage))
for c=0 to 4
st$=Instructions$(currentpage,l)
if mid$(st$,len(st$)-c)="~"
image=val(right$(st$,c))
st$=left$(st$,len(st$)-c-1)
exit
else
image=0
endif
next c
center text 320,l*(480/(val(Instructions$(0,currentpage))+1)),st$
if image>0 then paste image image,500,l*(480/(val(Instructions$(0,currentpage))+1))
next l
center text 60,455,"Enter to Exit"
do
sync
if currentpage<2
paste image 201,420,10,1
if rightkey() then inc currentpage : exit
endif
if currentpage>1
paste image 202,180,10,1
if leftkey() then dec currentpage : exit
endif
if returnkey() then goto instructionsexit
loop
cls rgb(0,118,163)
loop
instructionsexit:
repeat
until returnkey()=0
return
Credits:
return
`----------------------------------------------------
`FUNCTIONS
`----------------------------------------------------
function mouseover(x1,y1,x2,y2)
mx=mousex() : my = mousey()
if x1<mx and mx<x2
if y1<my and my<y2
exitfunction 1
endif
endif
endfunction 0
function line_box(x1,y1,x2,y2)
box x1,y1,x2,y1+1
box x1,y1,x1+1,y2
box x2,y1,x2+1,y2
box x1,y2,x2,y2+1
endfunction
function distance(x1,y1,x2,y2)
rem this is the standard distance formula:
rem ~~~[(x1-x2)` + (y1-y2)`] = d read the ~~~[] as square root and the ` as squared
rem however since square root is slow in DBC we square both sides of the equation to get:
rem (x1-x2)` + (y1-y2)` = d`
rem that is much faster
rem so any calls to this function must check for the normal check value SQUARED
dist = ((x1-x2) * (x1-x2)) + ((y1-y2) * (y1-y2))
endfunction dist
function get_brick(x#,y#)
for b=1 to brickdata(0,0)
if brickdata(b,1)-32<=x# and x#<=brickdata(b,1)+32
if brickdata(b,2)-8<=y# and y#<=brickdata(b,2)+8
if brickdata(b,0)<>0 then exitfunction b
endif
endif
next b
endfunction 0
function TenDigitScore$(score)
st$=str$(score)
while len(st$)<10
st$="0"+st$
endwhile
endfunction st$
function LoadLevel(filename$,level)
rem clear old level data
for b=0 to 182 : rem 182 is max number of bricks
for s=0 to 2
brickdata(b,s)=0 : rem lol, bs
next s
next b
open to read 1,filename$ : rem open the file
rem find the start of the specified level
repeat
read string 1,s$
until s$="l"+str$(level)
read string 1,s$ : rem get the total brick number
brickdata(0,0)=val(s$)
b=1
read string 1,s$ : rem get the first piece of brick data
repeat
brickdata(b,0)=val(s$)
read string 1,s$ : rem x coord of brick
brickdata(b,1)=val(s$)
read string 1,s$ : rem y coord of brick
brickdata(b,2)=val(s$)
read string 1,s$ : rem this will be either:
rem the next biece of brick data
rem the end of level character (;)
inc b : rem iterate the iterator
until s$=";"
close file 1
endfunction
function brickAI(brick)
rem this function returns a code using rgb():
rem red - the score increase to be applied
rem green - flag for telling if bounce should be applied
rem blue - nothing (for now....)
btype=brickdata(brick,0)
if btype>0 and btype<4
brickdata(brick,0)=btype-1
exitfunction rgb(50,1,0)
endif
if btype=-1
play sound 2
exitfunction rgb(0,1,0)
endif
if btype=4
brickdata(brick,0)=0
exitfunction rgb(50,0,0)
endif
endfunction 0
FUNCTION FindAngle(Xdiff#,YDiff#)
` ydiff#=ydiff#*(-1)
mag#=sqrt((xdiff#^2)+(ydiff#^2))
angle#=0
xcomp#=0
ycomp#=0
REPEAT
Inc angle#,.1
xcomp#=mag#*cos(angle#)
ycomp#=mag#*sin(angle#)
UNTIL abs(xcomp#-xdiff#)<.5 and abs(ycomp#-ydiff#)<.5
ENDFUNCTION angle#
therre u go...
EDIT)
Worked OUT a Bug causing the game to just start over without restoring your lives.
sync on : randomize timer()
gosub init_stuff
gosub load_media
gosub main_menu
loop music 2
loadlevel("levels.txt",1)
`--------------------------------------------------
`MAIN LOOP
`--------------------------------------------------
do
gosub check_input
gosub update_stuff
gosub move_ball
if returnkey()=1 then gosub main_menu
if brickdata(0,1)=0
inc currentlevelnumber
loadlevel("levels.txt",currentlevelnumber)
ballff=0
endif
sync
loop
`-----------------------------------------------
`SUBROUTINES
`-----------------------------------------------
init_stuff:
rem this array hold data concerning bricks
rem (x,0) = brick type
rem (x,1) = x coordinate
rem (x,2) = y coordinate
rem (0,0) = number of bricks in level
rem (0,1) = number of alive bricks
dim brickdata(200,2)
currentlevelnumber=1
rem Lives
NumberofLives=3
rem this bmp will hold the current score
create bitmap 2,420,40
rem this bmp will be updated with current brick data
create bitmap 1,640,480
return
load_media:
cls rgb(0,118,163) : rem this is the color of the menu
rem border
load image "Media/Images/backdrop.png",1
rem bricks, 4 types
load image "Media/Images/bricks.png",1000
paste image 1000,0,0
get image 99,0,48,64,64
get image 101,0,144,63,160
get image 102,0,0,63,16
get image 103,0,16,63,32
get image 104,0,160,64,176
delete image 1000
rem paddle
load image "Media/Images/Paddle.PNG",3
cls 0
rem ball
load image "Media/Images/Ball.png",2
rem score font
load image "Media/Images/font.PNG",300
rem split score font image into 10 digits
paste image 300,0,0
for dig=0 to 9
get image 301+dig,40*dig,0,40*(dig+1),40
next dig
cls 0
delete image 300
load image "Media/Images/rightarrow.PNG",201
load image "Media/Images/leftarrow.PNG",202
load music "Media/Audio/DNG_menu_2.mp3",1
load music "Media/Audio/DNG_maingame_v2.mp3",2
load sound "Media/Audio/Metal Brick hit.WAV",2
return
main_menu:
if music playing(1)=0 then loop music 1
if music playing(2) then pause music 2 : mainmusic=1
set current bitmap 0
for s=1 to 5
if sprite exist(s) then hide sprite s
next s
load image "Media/Images/mainmenu.png",200
paste image 200,0,0
ink rgb(0,255,255),0
Choice=0 : play=0 : help=0 : credits=0 : exitf=0 : NumberofLives=3
repeat
if mouseover(300,290,380,325)=1
line_box(300,290,380,325)
if mouseclick()=1 then Play=1
endif
if mouseover(300,325,375,365)=1
line_box(300,325,375,365)
if mouseclick()=1 then Help=1
endif
if mouseover(300,365,405,395)=1
line_box(300,365,395,400)
if mouseclick()=1 then Credit=1
endif
if mouseover(300,400,365,435)=1
line_box(300,400,365,435)
if mouseclick()=1 then end
endif
sync
cls 0
paste image 200,0,0
Choice=Play + (2*Help) + (3*Credit)
until Choice>0
select Choice
case 2
rem Help
gosub Instructions
endcase
case 3
rem Credits
gosub Credits
endcase
endselect
set current bitmap 1 : cls : set current bitmap 0 : cls
for s=1 to 5
if sprite exist(s) then show sprite s
next s
stop music 1
if mainmusic=1 then loop music 2 : mainmusic=0
cls 0
return
check_input:
inc paddlex, 6*(rightkey() - leftkey() )
if paddlex<80 then paddlex=80
if paddlex>560 then paddlex=560
if spacekey()=1 and ballff=0
ballff=1
ballx#=paddlex
bally#=455
ballmovey#=1.5
ballmovex#=(rnd(1)-.5)*2
endif
if Die=1
dec NumberofLives
ballff=0
if NumberofLives < 1 then GoSub Main_Menu
Die=0
endif
return
update_stuff:
set current bitmap 1
count=0
cls 0
n=0
repeat
inc count
if brickdata(count,0)<>0
paste image brickdata(count,0)+100,brickdata(count,1)-32,brickdata(count,2)-8
if brickdata(count,0)>0 then inc n
endif
until count=brickdata(0,0)
brickdata(0,1)=n : rem number of currently alive bricks
get image 4,0,0,639,479
set current bitmap 2
cls rgb(255,255,255)
ink 0,0
score$=TenDigitScore$(score)
i=1
for x=0 to 380 step 40
paste image 301+val(mid$(score$,i)),x,0
inc i
next x
get image 5,0,0,400,40
set current bitmap 0
Rem Show Lives Remaining...
cls
ink RGB(255,255,255),0
Center Text 470,420,"Lives"
Line 440,435,500,435
Center Text 470,440,Str$(NumberofLives)
sprite 1,0,0,1 : rem border
sprite 3,paddlex-40,460,3 : rem paddle
sprite 4,0,0,4 : rem bricks
sprite 5,230,5,5 : rem score
size sprite 5,380,30
return
check_collision:
col=sprite collision(2,0)
select col
case 1 : rem border collision
if ballx#<=45 and ballmovex#<0 then ballmovex#=-1*ballmovex#
if bally#<=45 and ballmovey#>0 then ballmovey#=-1*ballmovey#
if ballx#>=595 and ballmovex#>0 then ballmovex#=-1*ballmovex#
endcase
case 3 : rem paddle collision
oldballmovex#=ballmovex#
ballmovey#=1.5
ballmovex#=(1/30.0)*(ballx#-paddlex)
ballmovex#=(ballmovex#+oldballmovex#)/2
endcase
case 4 : rem brick collision
if get_brick((ballx#-6),bally#)>0
b=get_brick(ballx#-6,bally#)
rem left of ball collision
brickAI = brickAI(b)
inc score,rgbr(brickAI)
if rgbg(brickAI)=1 and ballmovex#<0 then ballmovex#=-1*ballmovex#
endif
if get_brick(ballx#,bally#-6)>0
b=get_brick(ballx#,bally#-6)
rem top of ball collision
brickAI = brickAI(b)
inc score,rgbr(brickAI)
if rgbg(brickAI)=1 and ballmovey#>0 then ballmovey#=-1*ballmovey#
endif
if get_brick(ballx#+6,bally#)>0
b=get_brick(ballx#+6,bally#)
rem right of ball collision
brickAI = brickAI(b)
inc score,rgbr(brickAI)
if rgbg(brickAI)=1 and ballmovex#>0 then ballmovex#=-1*ballmovex#
endif
if get_brick(ballx#,bally#+6)>0
b=get_brick(ballx#,bally#+6)
rem bottom of ball collision
brickAI = brickAI(b)
inc score,rgbr(brickAI)
if rgbg(brickAI)=1 and ballmovey#<0 then ballmovey#=-1*ballmovey#
endif
endcase
endselect
return
move_ball:
if ballff=1
for i=1 to 3
inc ballx#,ballmovex#
dec bally#,ballmovey#
sprite 2,ballx#-5,bally#-5,2
col=sprite hit(2,1)+sprite hit(2,3)+sprite hit(2,4)
inc col,sprite collision(2,1)+sprite collision(2,3)+sprite collision(2,4)
if col>0 then gosub check_collision
if bally#>=545 then Die=1
next i
else
sprite 2,paddlex-5,450,2
endif
return
return
Instructions:
dim Instructions$(2,10)
open to read 1,"Instructions.txt"
for x=1 to 2
count=1
read string 1,s$
Instructions$(x,0)=right$(left$(s$,len(s$)-1),len(s$)-2)
read string 1,s$
repeat
Instructions$(x,count)=s$
read string 1,s$
inc count
until s$=";"
Instructions$(0,x)=str$(count-1)
next x
close file 1
currentpage=1
cls rgb(0,118,163)
ink 0,0
do
set text size 40
center text 320,0,Instructions$(Currentpage,0)
set text size 15
for l=1 to val(Instructions$(0,currentpage))
for c=0 to 4
st$=Instructions$(currentpage,l)
if mid$(st$,len(st$)-c)="~"
image=val(right$(st$,c))
st$=left$(st$,len(st$)-c-1)
exit
else
image=0
endif
next c
center text 320,l*(480/(val(Instructions$(0,currentpage))+1)),st$
if image>0 then paste image image,500,l*(480/(val(Instructions$(0,currentpage))+1))
next l
center text 60,455,"Enter to Exit"
do
sync
if currentpage<2
paste image 201,420,10,1
if rightkey() then inc currentpage : exit
endif
if currentpage>1
paste image 202,180,10,1
if leftkey() then dec currentpage : exit
endif
if returnkey() then goto instructionsexit
loop
cls rgb(0,118,163)
loop
instructionsexit:
repeat
until returnkey()=0
return
Credits:
return
`----------------------------------------------------
`FUNCTIONS
`----------------------------------------------------
function mouseover(x1,y1,x2,y2)
mx=mousex() : my = mousey()
if x1<mx and mx<x2
if y1<my and my<y2
exitfunction 1
endif
endif
endfunction 0
function line_box(x1,y1,x2,y2)
box x1,y1,x2,y1+1
box x1,y1,x1+1,y2
box x2,y1,x2+1,y2
box x1,y2,x2,y2+1
endfunction
function distance(x1,y1,x2,y2)
rem this is the standard distance formula:
rem ~~~[(x1-x2)` + (y1-y2)`] = d read the ~~~[] as square root and the ` as squared
rem however since square root is slow in DBC we square both sides of the equation to get:
rem (x1-x2)` + (y1-y2)` = d`
rem that is much faster
rem so any calls to this function must check for the normal check value SQUARED
dist = ((x1-x2) * (x1-x2)) + ((y1-y2) * (y1-y2))
endfunction dist
function get_brick(x#,y#)
for b=1 to brickdata(0,0)
if brickdata(b,1)-32<=x# and x#<=brickdata(b,1)+32
if brickdata(b,2)-8<=y# and y#<=brickdata(b,2)+8
if brickdata(b,0)<>0 then exitfunction b
endif
endif
next b
endfunction 0
function TenDigitScore$(score)
st$=str$(score)
while len(st$)<10
st$="0"+st$
endwhile
endfunction st$
function LoadLevel(filename$,level)
rem clear old level data
for b=0 to 182 : rem 182 is max number of bricks
for s=0 to 2
brickdata(b,s)=0 : rem lol, bs
next s
next b
open to read 1,filename$ : rem open the file
rem find the start of the specified level
repeat
read string 1,s$
until s$="l"+str$(level)
read string 1,s$ : rem get the total brick number
brickdata(0,0)=val(s$)
b=1
read string 1,s$ : rem get the first piece of brick data
repeat
brickdata(b,0)=val(s$)
read string 1,s$ : rem x coord of brick
brickdata(b,1)=val(s$)
read string 1,s$ : rem y coord of brick
brickdata(b,2)=val(s$)
read string 1,s$ : rem this will be either:
rem the next biece of brick data
rem the end of level character (;)
inc b : rem iterate the iterator
until s$=";"
close file 1
endfunction
function brickAI(brick)
rem this function returns a code using rgb():
rem red - the score increase to be applied
rem green - flag for telling if bounce should be applied
rem blue - nothing (for now....)
btype=brickdata(brick,0)
if btype>0 and btype<4
brickdata(brick,0)=btype-1
exitfunction rgb(50,1,0)
endif
if btype=-1
play sound 2
exitfunction rgb(0,1,0)
endif
if btype=4
brickdata(brick,0)=0
exitfunction rgb(50,0,0)
endif
endfunction 0
FUNCTION FindAngle(Xdiff#,YDiff#)
` ydiff#=ydiff#*(-1)
mag#=sqrt((xdiff#^2)+(ydiff#^2))
angle#=0
xcomp#=0
ycomp#=0
REPEAT
Inc angle#,.1
xcomp#=mag#*cos(angle#)
ycomp#=mag#*sin(angle#)
UNTIL abs(xcomp#-xdiff#)<.5 and abs(ycomp#-ydiff#)<.5
ENDFUNCTION angle#
(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )