'+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
'+               Breakout by Gareth Bailey               +
'+                November/ December 2001                +
'+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +

hscr=2500
open window 640,512
gosub menu

label setup
dim level(5,6),exx(10),exy(10),edirx(10),ediry(10),ti$(4)
dim selec$(3)
selec$(1)="*! START GAME !*"
selec$(2)="*! INSTRUCTIONS !*"
selec$(3)="*! CREDITS !*"
 
 for a=1 to 10
  exy(a)=600
 next a

restore levels
 for a=1 to 6
  for b=1 to 5
   read level(b,a)
  next b
 next a

opt=1:x1=195
ps=10   :bx=215
x=245   :y=300
diry=-5 :dirx=0
level=1 :scr=0
lwin=1  :bn=3
tx=640  :ty=450

txtshow=16:txtlen=0
for a=1 to txtshow+5:msg$=msg$+" ":next a
msg$=msg$+"Use the ball to get rid of the blocks!   Dont "
msg$=msg$+"let the ball fall below the bat! or it game "
msg$=msg$+"over! hellos to everyone at the yabasic forums"

txtlen=len(msg$)
dim textdraw$(txtlen)

for a=1 to txtlen
textdraw$(a)=mid$(msg$,a,txtshow)
next a

mxlev=3
' + + + + + + + + + + + + + + + + + + + + + + + + + + + + 
' +    'mxlev' should be be 1 less than the number of   +
' +  predefined levels after this the levels are random +
' +     only change 'mxlev' is you add more levels      +
' + + + + + + + + + + + + + + + + + + + + + + + + + + + + 
return


label main
 gosub msg
   label gameloop
    clear window
    x=x-dirx
    y=y-diry
      gosub col
      gosub draw
      gosub conread
      gosub db
    goto gameloop
return

label conread
 con = peek("port1")
  if (and(con, 128) <> 0) bx = bx-ps   
  if and(con, 32) <> 0 bx =bx+ps
return

label col
 if lwin=0 then
  gosub timebonus
  gosub loadlevel
 fi

 if y>470 and y<485 and x+10>=bx and x<bx+70 then
  y=470
  if x+10>=bx and x<=bx+70 
  if x+10>=bx and x<bx+10 dirx=6
  if x>=bx+10 and x<bx+20 dirx=4
  if x>=bx+20 and x<bx+35 dirx=3
  if x>=bx+35 and x<bx+50 dirx=-3
  if x>=bx+50 and x<bx+60 dirx=-4
  if x>=bx+50 and x<bx+70 dirx=-6
  diry=0-diry
 fi

if bx+70>450 bx=380
if bx<50 bx=50

 if x<50 or x>440 then
   if x>440 x=440
   if x<50 x=50
   dirx=0-dirx
 fi

if y<0 diry=0-diry
  if y>512 then
    bn=bn-1
    if bn<1 gosub gameover
    gosub msg
  fi

bposx=int((x-50)/80)
bposy=int((y-40)/20)

 if bposy<6 and bposy>=0then
   if level(bposx+1,bposy+1)>0 then
     diry=0-diry
     gosub explode
      if level(bposx+1,bposy+1)=1 scr=scr+20
      if level(bposx+1,bposy+1)=2 scr=scr+50
      if level(bposx+1,bposy+1)=3 scr=scr+100
     level(bposx+1,bposy+1)=0
    fi 
  fi

return

label draw
'+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
'+         DRAW THE SCORE BOARD AND SCROLL TEXT          +
'+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
setrgb 1,51,102,204
gosub drawtext
setrgb 1, 20,20,20
fill rectangle 50,0 to 450,512
setrgb 1,51,102,204
rectangle 50,1 to 450,511
setrgb 1,255,153,51
fill rectangle x,y to x+10,y+10
setrgb 1,51,102,204
fill rectangle bx,480 to bx+70,490 

cc=cc+0.1
red=50+50*sin(cc/2)
blu=50+50*sin(cc/3)
grn=50+50*sin(cc/4)
setrgb 1,red,30,30
setrgb 2,30,grn,30
setrgb 3,30,30,blu
gtriangle 455,75 to 625,355 to 455,355
gtriangle 455,75 to 625,355 to 625,75

setrgb 1,51,102,204
text 520,30,"---B R E A K","cc"
text 550,45,"O  U  T---","cc"
setrgb 1,0,0,0
text 521,31,"---B R E A K","cc"
text 551,46,"O  U  T---","cc"

setrgb 1,175,175,175
line 460,110 to 620,110
line 460,210 to 620,210 
line 460,310 to 620,310 
text 460,100,"S C O R E" 
text 460,200,"B A L L S" 
text 460,300,"L E V E L" 
text 460,140,str$(scr)
text 460,240,str$(bn)
text 460,340,str$(level)
rectangle 455,75 to 625,355 

'+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
'+              DRAW THE REST OF THE GRAPHICS            +
'+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
if bposy>6 lwin=0
for b=1 to 6
 for a=0 to 4
  if level(a+1,b)>0 then
   lwin=1
   if level(a+1,b)=1 setrgb 1,0,150,0
   if level(a+1,b)=2 setrgb 1,0,0,150
   if level(a+1,b)=3 setrgb 1,150,0,0
   fill rectangle a*80+53,b*20+30 to a*80+127,b*20+40
  fi
 next a
next b

 if col=1 setrgb 1,0,150,0
 if col=2 setrgb 1,0,0,150
 if col=3 setrgb 1,150,0,0

for a=1 to 10
 fill rectangle exx(a),exy(a) to exx(a)+7,exy(a)+10
 exx(a)=exx(a)+edirx(a)
 exy(a)=exy(a)+ediry(a)
 ediry(a)=ediry(a)+.25
next a

if timeshow>0 then
  setrgb 1,255,255,255
  text x+10,y+10," Time Bonus: " + str$(tbonus)
  timeshow=timeshow-3
fi
return

label drawtext
rect 460,435 to 620,457
tx=460:ty=450
tm=tm+1
if tm=7 then:t=t+1:tm=0:fi
if t>txtlen t=0
text tx,ty,textdraw$(t)
return


label db
 setdispbuf draw
 draw = 1 - draw
 setdrawbuf draw
return

label explode
for a=1 to 5
 edirx(a)=ran(5)
 edirx(a+5)=-ran(5)
 ediry(a)=-ran(5)
 ediry(a+5)=-ran(5)
next a

for a=0 to 10
 exx(a)=x
 exy(a)=y
next a

  if level(bposx+1,bposy+1)=1 col=1
  if level(bposx+1,bposy+1)=2 col=2
  if level(bposx+1,bposy+1)=3 col=3
return 

label strttme
 num=token(time$,ti$(),"-")
 tstrt=val(ti$(4))
return


label timebonus
 num=token(time$,ti$(),"-")
 tend=val(ti$(4))
 tbonus=150-(tend-tstrt)
 if tbonus<0 tbonus=0
 timeshow=1000
 scr=scr+tbonus
gosub strttme
return


label msg
repeat 
  x=245  : y =300
  dirx=0 : bx=215
  clear window
  gosub draw
  setrgb 1,175,175,175
  clear fill rectangle 125,225 to 375,275
  rect 125,225 to 375,275
  text 250,250,"PRESS START TO CONTINUE","cc"
  gosub db
  until (peek("port1")=8)
gosub strttme
return

label gameover
repeat
clear window
setrgb 1,33,33,33
rectangle 50,100 to 600,500
setrgb 1,255,153,51
text 320,50,"- - -     B R E A K O U T     - - -","cc"
text 320,150,"G A M E  O V E R","cc"
text 320,175,"P L E A S E  T R Y  A G A I N","cc"
text 320,400, "PRESS START TO RETURN TO MAIN MENU","cc"

 if scr>hscr then
  c=c+2
  setrgb 1,75+50*sin(c/15),75+50*sin(c/17),75+50*sin(c/20)
  text 320,250,"NEW HIGH SCORE ACHIVED","cc"
  text 320,280,str$(scr),"cc"
 fi

gosub db
until (peek("port1")=8)
if scr>hscr hscr=scr
gosub menu
return

label loadlevel
clear window

if level>mxlev then 
  for a=1 to 6
    for b=1 to 5
     level(b,a)=int(ran(3))+1
    next b
  next a
else
  for a=1 to 6
    for b=1 to 5
     read level(b,a)
    next b
  next a
fi

level=level+1
diry=diry-1
return

label levels
'+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
'+ To make your own levels edit the code below. If you   +
'+ add levels rember to chyange the mxlev to 1 less then +
'+ number of levels you now have. Have Fun!              +
'+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
'---------------------------------------------------------
'+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
'+ 0=empty space                                         +
'+ 1=Green block (20  points)                            +
'+ 2=Blue Block  (50  points)                            +
'+ 3=Red Block   (100 points)                            +
'+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +

'lv1
data 3,3,3,3,3
data 2,2,2,2,2
data 1,1,1,1,1
data 0,0,0,0,0
data 0,0,0,0,0
data 0,0,0,0,0

'lv2
data 3,3,3,3,3
data 1,1,1,1,1
data 2,2,2,2,2
data 1,1,1,1,1
data 0,0,0,0,0
data 0,0,0,0,0

'lv3
data 0,0,0,0,0
data 2,2,2,2,2
data 3,0,3,0,3
data 0,3,0,3,0
data 2,2,2,2,2
data 1,1,1,1,1

'lv4
data 1,1,1,1,1
data 2,2,2,2,2
data 3,3,3,3,3
data 3,3,3,3,3
data 2,2,2,2,2
data 1,1,1,1,1

label menu
gosub setup
label menuloop
clear window
setrgb 1,33,33,33
rectangle 50,100 to 600,500
rectangle 100,160 to 540,290
rectangle 50,460 to 600,500
setrgb 2,51,102,204
setrgb 3,0,0,0
setrgb 1,0,0,0
gtriangle 120,150+(30*opt) to 170,165+(30*opt) to 120,180+(30*opt)
setrgb 1,255,153,51
text 320,50,"- - -     B R E A K O U T     - - -","cc"
setrgb 1,0,0,0
text 321,51,"- - -     B R E A K O U T     - - -","cc"

setrgb 1,255,153,51
text 320,200, "| S T A R T  N E W  G A M E |","cc"
text 320,230, "|  I N S T R U C T I O N S  |","cc"
text 320,260, "|  V I E W   C R E D I T S  |","cc"
text 320,400, "PRESS 'X' TO SELECT","cc"
text 320,415,"PRESS TRIANGLE TO EXIT","cc"
setrgb 1,250,30,30
msgx=320+(-10+ran(20))
msgy=340+(-10+ran(20))
text msgx,msgy,selec$(opt),"cc"

c=c+4
setrgb 1,75+50*sin(c/15),75+50*sin(c/17),75+50*sin(c/20)
text 320,485,"TODAYS HIGH SCORE IS: "+str$(hscr),"cc"
con = peek("port1")
if and(con, 16   ) <> 0 opt=opt-1
if and(con, 64   ) <> 0 opt=opt+1
if and(con, 4096 ) <> 0 end
if (opt<1) opt=1
if (opt>3) opt=3
if and(con, 16384) <> 0 then
if (opt=1) gosub main
if (opt=2) gosub instruct
if (opt=3) gosub credits
end if
gosub db
wait 0.09
goto menuloop
return

label instruct
repeat
clear window
setrgb 1,30,30,30
fill rect 50,100 to 600,130
fill rect 50,230 to 600,260
rectangle 50,100 to 600,500
setrgb 1,0,150,0
text 60,310,"+ GREEN block is worth 20  points"
setrgb 1,0,0,150
text 60,335,"+ BLUE  block is worth 50  points"
setrgb 1,150,0,0
text 60,360,"+ RED   block is worth 100 points"
setrgb 1,255,153,51
text 320,50,"- - - I N S T R U C T I O N S - - -","cc"
text 60,120,"C O N T R O L S"
text 60,480,"Press start to return..."
text 60,250,"R U L E S"
setrgb 1,0,0,0
text 321,51,"- - - I N S T R U C T I O N S - - -","cc"
setrgb 1,100,100,100
text 60,160," + Left and Right moves the bat - Simple :)"
text 60,290,"Points:"
text 320,380,"When all of the blocks are removed you go","cc"
text 320,400,"onto the next level.There ane 5 levels in","cc"
text 320,420,"total and each level becomes progressively","cc"
text 320,440,"quicker. Upon winning a level a bonus is","cc"
text 320,460,"given depending on the time taken. Enjoy!!","cc"
gosub db
until (peek("port1")=8)
return 

label credits
e=320
tty=512
repeat
clear window
setrgb 1,100,100,100
text e,tty,"- - -     B R E A K O U T     - - -","cc"
text e,tty+40, "Breakout was programmed by:","cc"
text e,tty+60, "Gareth Bailey (warpedmind)","cc"
text e,tty+80, "Email: warpedmind0@hotmail.com     ","cc"
text e,tty+100,"Web  : http://liquid2k.com/jinxyab/","cc"
text e,tty+120,"------------------------------------","cc"
text e,tty+140,"Thanks to Mr Shockwave(Nick Simpson)","cc"
text e,tty+160,"for all his support and ideas for my","cc"
text e,tty+180,"website and the excelent job he is  ","cc"
text e,tty+200,"doing at the yabasic.co.uk forums   ","cc"
text e,tty+240,"Thanks to Adam Lay,excelent website!","cc"
text e,tty+260,"Visit yabasic.co.uk for more ecelent","cc"
text e,tty+280,"Games/Demos                         ","cc"
text e,tty+320,"Hello everyone at the Yabasic forums","cc"
clear fill rectangle 0,101 to 640,0
clear fill rectangle 0,499 to 640,512
setrgb 1,30,30,30
rectangle 50,100 to 600,500
setrgb 1,255,153,51
text 320,50,"- - -      C R E D I T S      - - -","cc"
setrgb 1,0,0,0
text 321,51,"- - -      C R E D I T S      - - -","cc"
tty=tty-1
if tty+320<80 tty=512
gosub db
until (peek("port1")=8)
return










