rem ------- Dark Pong -------
rem --- Competition entry ---
rem ---- By Gary Jeffery ----
 
set display mode 800,600,32
set window size 800,800
set window on
color backdrop rgb(0,0,0)
sync rate 60
autocam off
hide mouse
 
 
type bouncy
   angle as integer
   speed as float
endtype
 
ball as bouncy
global p1score
global p2score
 
 
p1score=1
p2score=1
BatAngle=0
 
Make_Score_Images()
Make_3DMedia()
Setup_Ball()
 
EndOfGame=0
repeat
   main_loop()
 
   if object position z(1)>30
      inc p1score
      Setup_Ball()
      if p1score=6 then EndOfGame=1
   endif
   if object position z(1)<-30
      inc p2score
      Setup_Ball()
      if p2score=6 then EndOfGame=1
   endif
until EndOfGame=1
ink rgb(255,255,0),0
repeat
    center text 400,300,"Game Over"
until inkey$()<>""
end
 
function main_loop()
 
   if object hit(1,2) or object hit(1,3) then Change_Ball_Angle(ball.angle,2)
   if object collision(1,4) or object collision(1,5) then Change_Ball_Angle(ball.angle,1)
 
   if rightkey() and object position x(2)<12 then position object 2,object position x(2)+0.4,0,-20
   if leftkey() and object position x(2)>-12 then position object 2,object position x(2)-0.4,0,-20
   move object 1,ball.speed
 
   if object position x(1)<object position x(3) and object position x(3)>-12 then move object up 3,0.3+(0.05*p1score)
   if object position x(1)>object position x(3) and object position x(3)<12 then move object down 3,0.3+(0.05*p1score)
 
   sprite 1,32,32,p1score
   sprite 2,700,32,p2score
 
endfunction
 
function Change_Ball_Angle(Old_Ball_Angle as integer,mode as integer)
   if mode=1
      Wall_Angle=int(ball.angle/90)*90
      if Wall_Angle=0 then Wall_Angle=360
      select Wall_Angle
         case 90 :
            ball.angle=wrapvalue(180+(180-Old_Ball_Angle))
         endcase
 
         case 180 :
            ball.angle=wrapvalue(180+(180-Old_Ball_Angle))
         endcase
 
         case 270 :
            ball.angle=wrapvalue(90-(Old_Ball_Angle-270))
         endcase
 
         case 360 :
            ball.angle=wrapvalue(360-Old_Ball_Angle)
         endcase
      endselect
   endif
   if mode=2
      Wall_Angle=int(ball.angle/90)*90
      if Wall_Angle=0 then Wall_Angle=360
      select Wall_Angle
         case 90 :
            ball.angle=wrapvalue(86+(90-Old_Ball_Angle)+rnd(8))
         endcase
 
         case 180 :
            ball.angle=wrapvalue(86-(Old_Ball_Angle-90)+rnd(8))
         endcase
 
         case 270 :
            ball.angle=wrapvalue(266+(270-Old_Ball_Angle)+rnd(8))
         endcase
 
         case 360 :
            ball.angle=wrapvalue(176+(360-Old_Ball_Angle)+rnd(8))
         endcase
      endselect
         inc ball.speed,0.01
   endif
 
   rotate object 1,0,ball.angle,0
 
endfunction
 
function Setup_Ball()
   ball.angle=rnd(20)+35
   ball.speed=0.5
   rotate object 1,0,ball.angle,0
   position object 1,0,0,0
   position object 2,0,0,-20
   position object 3,0,0,20
endfunction
 
function Make_Score_Images()
   create bitmap 1,50,50
   set current bitmap 1
   for x=1 to 5
      for m=0 to 4
         for n=0 to 4
            read a
            if a=1 then ink rgb(255,255,255),0 else ink 0,0
            box n*5,m*5,(n*5)+4,(m*5)+4
         next n
      next m
      get image x,0,0,24,24
   next x
   data 1,1,1,1,1,1,0,0,0,1,1,0,0,0,1,1,0,0,0,1,1,1,1,1,1
   data 0,0,1,0,0,0,1,1,0,0,0,0,1,0,0,0,0,1,0,0,0,1,1,1,0
   data 0,1,1,1,0,1,0,0,0,1,0,0,0,1,0,0,1,1,0,0,1,1,1,1,1
   data 0,1,1,1,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1,1,1,0
   data 0,0,0,1,0,0,0,1,1,0,0,1,0,1,0,1,1,1,1,1,0,0,0,1,0
   set current bitmap 0
endfunction
 
function Make_3DMedia()
   position camera 0,15,-33
   rotate camera 33,0,0
   make object sphere 1,1
   make object cylinder 2,1
   scale object 2,100,400,100
   make mesh from object 1,1
   make mesh from object 2,1
   make mesh from object 3,2
   delete object 2
   make object 2,3,0
   add limb 2,1,1
   add limb 2,2,2
   offset limb 2,1,0,2,0
   offset limb 2,2,0,-2,0
   make mesh from object 3,2
   delete object 2
   make object 2,3,0
   color object 2,rgb(255,0,0)
   set object ambient 2,0
   rotate object 2,0,0,90
   position object 2,0,0,-20
   clone object 3,2
   position object 3,0,0,20
   set object diffuse 1,rgb(128,128,128)
   set object specular 1,rgb(255,255,255)
   set object specular power 1,100
   set object ambient 1,0
   make object box 4,1,1,40
   color object 4,rgb(255,0,0)
   create bitmap 2,32,32
   set current bitmap 2
   box 1,1,32,32,rgb(255,0,0),rgb(255,255,0),rgb(255,0,0),rgb(255,255,0)
   get image 6,1,1,32,32
   set current bitmap 0
   texture object 4,6
   clone object 5,4
   position object 4,-15,0,0
   position object 5,15,0,0
   set object collision to boxes 1
   set object collision to boxes 2
   set object collision to boxes 3
   set object collision to boxes 4
   set object collision to boxes 5
endfunction