rem PINBALL by Lewis Yates
 
make object sphere 1,2
 
make object cube 2,5 ; scale object 2,150,30,30
make object cube 3,5 ; scale object 3,150,30,30
 
rem objects 4 to 10 are walls
for x=4 to 10
  make object cube x,5
  scale object x,300,25,25
next x
 
rem make a wall, that will make the ball
rem bounce to the flipper more betterer :)
zrotate object 4,45
position object 4,26,4.5,0
rem same thing, on the other side
zrotate object 5,315
position object 5,4,4.5,0
rem make the four vertical walls with
rem a gap in between for the fans to go in!
for x=6 to 7
 scale object x,150,25,25
  zrotate object x,90
 next x
 
for x=8 to 9
 scale object x,300,25,25
  zrotate object x,90
 next x
 
rem make fans!
for x=11 to 12
  make object cube x,4
  if x=11 then position object x,-2,19,0
  if x=12 then position object x,32,19,0
next x
 
position object 6,-1,13,0
position object 7,31,13,0
position object 8,-1,28,0
position object 9,31,28,0
 
rem put the roof on the arena
scale object 10,670,25,25
position object 10,15,36,0
 
rem put the flippers in the right places and
rem put the ball a little way up so it can fall
position object 2,10,-1,0
position object 3,20,-1,0
position object 1,15,25,0
position camera 15,20,-30
 
rem set up collision
for x=2 to 10
  set object collision to polygons x
next x
 
set object collision to spheres 1
 
 
rem begin polishing!
rem set object colours:
 
for x=4 to 10
  color object x,RGB(255,128,192)
next x
cls rgb(255,255,0) ; get image 1,0,0,16,16
color object 1,rgb(255,0,0)
color object 2,rgb(0,0,255)
color object 3,rgb(0,0,255)
color backdrop rgb(0,0,0)
make light 1
color light 1,0,255,0
set ambient light 10
color object 11,rgb(0,0,0)
color object 12,rgb(0,0,0)
make particles 1,1,10000,1
set particle life 1,20
 
 
rem set variables
x#=object position x(1)
y#=object position y(1)
velocity#=0.1
direction#=51
lives=4
 
sync on
 
 
 
 
do
 
if gravity#<0.001 then gravity#=gravity#+0.00001
 
wind#=0
 
rem control flippers
if keystate(30)=1 then leftflipper#=leftflipper#+10
if LeftFlipper#>90 then leftflipper#=90
if leftflipper#>0 then leftflipper#=leftflipper#-5
zrotate object 2,wrapvalue(leftflipper#)
 
if keystate(32)=1 then rightflipper#=rightflipper#-10
if RightFlipper#<-90 then Rightflipper#=-90
if Rightflipper#<0 then Rightflipper#=Rightflipper#+5
zrotate object 3,wrapvalue(Rightflipper#)
 
rem control wind
if rightkey()=1
  wind#=0.001
  xrotate object 11,object angle x(11)+10
endif
if leftkey()=1
  wind#=-0.001
  xrotate object 12,object angle x(12)+10
endif
 
 
               rem control ball
               for x=4 to 12
                  if object collision(1,x)=1
                    direction#=wrapvalue(direction#+45)
                    x#=newxvalue(x#,direction#,1)
                    y#=newzvalue(y#,direction#,1)
                    velocity#=velocity#/1.2
                    gravity#=0
                  endif
               next x
 
               if object collision(1,2)=1
                 if leftflipper#>oldleft# then velocity=velocity*2
                 direction#=wrapvalue(direction#+90)
                 x#=newxvalue(x#,direction#,1)
                 y#=newzvalue(y#,direction#,1)
                 gravity#=0
               endif
 
               if object collision(1,3)=1
                 if rightflipper#<oldright# then velocity#=velocity#*2
                 direction#=wrapvalue(direction#+90)
                 x#=newxvalue(x#,direction#,1)
                 y#=newzvalue(y#,direction#,1)
                 gravity#=0
               endif
 
               rem do wind
               if y#>15 and y#<23 then x#=x#+wind#
 
               rem sort out gravity
               y#=y#-gravity#
 
               x#=newxvalue(x#,direction#,velocity#)
               y#=newzvalue(y#,direction#,velocity#)
 
               position object 1,x#,y#,0
 
               cx#=curvevalue(x#,cx#,100)
               cy#=curvevalue(y#,cy#,100)
 
               position camera cx#,cy#,-25
               position light 1,x#,y#,-2
               position light 0,cx#,cy#,-10
               point light 0,x#,y#,0
               position particle emissions 1,x#,y#,0
               oldleft#=leftflipper#
               oldright#=rightflipper#
 
               a#=15-x#
               b#=15-y#
               c#=(a#*a#)+(b#*b#)
               dis#=sqrt(c#)
               if dis#>40
                 lives=lives-1
                 x#=rnd(10)+15
                 y#=rnd(10)
                 direction#=rnd(360)
               endif
 
 
text 0,0,"Lives Remaining: "+str$(lives)
 
rem recalculate direction, to calculate for any changes
direction#=ATANFULL(x#-oldx#,y#-oldy#)
oldx#=x#
oldy#=y#
 
rem end of loop
sync
loop