MORE CODE
Shootin' Gallery
Revisited
Checks multiple targets for collision.

`Shootin' Gallery Re-visited
`Testing Multiple Targets for Collision
`Author: Hop A Long
`July 1, 2004

`************************************************
`  Get Ready
`************************************************
   Autocam off
   Sync On
   Sync Rate 40
   Hide Mouse

`************************************************
`  Make "Target" Objects
`************************************************
   For ob = 4 To 12
   Make Object Sphere ob,20
   Color Object ob, RGB(Rnd(250),Rnd(250),Rnd(250))
   Next ob

   t = 4
   For x = 1 To 3
    For y = 1 To 3
      Position Object t,(x*30-60),(y*30-60),200
      Inc t
    Next y
   Next x

`************************************************
`  Make Gun
`************************************************
   Make object cylinder 2,2
   Color Object 2, RGB(250,250,0)
   XRotate Object 2,90
`  Reset the object's axis to zero in it's present location
   Fix object pivot 2
   Scale object 2,100,100,500
   position object 2,0,39,10

`************************************************
`  Make bullet
`************************************************
   Make Object Sphere 3,2
   Color Object 3, RGB(0,250,0)
   Hide Object 3

`********************************************************************
`  START MAIN  LOOP
`********************************************************************
   Do

      `******************************************
      `  Tex Output
      `******************************************
         Center Text 320,20, "SHOOTIN' GALLERY RE-VISITED"
         Center Text 320,50,"Mouse to aim and shoot"

      `******************************************
      `  BULLETS
      `******************************************
      `  Left Click returns 1, Right Click returns 2
         If Mouseclick()=1 and BulletLife = 0
         `  Place the bullet in the gun
            Position object 3, 0,39,10
         `  The bullet faces the same direction as the gun,
            Set object to object orientation 3,2
            BulletLife =25
            Record_Score = 1
            Show object 3
         Endif

         If BulletLife > 0
            Dec BulletLife
            Move object 3,10
            If BulletLife = 0 then Hide object 3
         Endif

      `******************************************
      `  GUN MOVEMENT
      `******************************************

      `  Store the Gun angle y in cy# (change in y)
         cy# = Object Angle Y(2)
         cx# = Object Angle X(2)

      `  Rotate the Gun's direction but keep within bounds
         y_range# = wrapvalue(cy#+(mousemovex()*0.5))
         x_range# = wrapvalue(cx#+(mousemovey()*0.5))

      `  Declare test variables
         y_temp# = y_range#
         x_temp# = x_range#

      `  Allow for a continual range from left to right
         If y_temp# > 0.0 and y_temp# < 180.0
            y_temp# = y_temp# + 360.0
         Endif
         If x_scale# > 0.0 and x_scale# < 180.0
            x_scale# = x_scale# + 360.0
         Endif

      `  Set the left bound and an exception for start conditions
         If y_temp# < 315.0 and y_temp# <> 0.0 then y_range# = 315.0
         If x_scale# < 315.0 and x_scale# <> 0.0 then x_range# = 315.0

      `  Set the right bound
         If y_temp# > 404.0 then y_range# = 45.0
         If x_scale# > 404.0 then x_range# = 45.0

      `  Rotate the Gun
         Yrotate Object 2, y_range#
         Xrotate Object 2, x_range#

      `******************************************
      `  COLLISION DETECTION CODE
      `******************************************
      `  The Object Collision Command returns the
      `  number of the oject that is hit.
         col_return = Object Collision(3,0)

      `  If there is a hit, find which object is hit.
      `  Delete it and end the bullet.
         If col_return<>0
            GOSUB Collision_Test
            BulletLife = 0
            Hide object 3
            While Record_Score = 1
               Inc Hit
               Record_Score = 2
            Endwhile
         Endif

      `  The bullet is almost spent, consider it a miss
         If BulletLife = 1
            Inc Miss
         Endif

         Text 10,150,"MISSED :  "+str$(Miss)
         Text 500,150,"HIT :  "+str$(Hit)

      `******************************************
      ` CAMERA ROUTINES
      `******************************************
      `  Place the camera
         Position Camera 0,50,0
      `  Point the camera at the player object
         Point camera 0,25,100
      `  Refresh Screen
         Sync

   Loop
`**************************************************************************************************
`  END MAIN LOOP
`**************************************************************************************************

`************************************************
` COLLISION_TEST SUBROUTINE
`************************************************
`  Compare all the objects to the return
`  value from the Collision Command
   Collision_Test:
      For ob = 4 To 12
         If ob = col_return
            Delete Object ob
         Endif
      Next ob
   RETURN