REM ***********************************************
REM Title: Line-of-sight Bullets
REM Author: Phaelax
REM Downloaded from: http://dbcc.zimnox.com/
REM ***********************************************
 
set display mode 800,600,32
REM make a random image
for x=1 to 32
   for y=1 to 32
      dot x, y, rgb(0,rnd(255),0)
   next y
next x
get image 1,1,1,32,32
 
 
 
sync on
backdrop on
autocam off
hide mouse
randomize timer()
 
REM VARIABLES
y#=100.0
line#=1000.0
 
REM OBJECTS
for i=1 to 5
   make object cube i, 100
   position object i, rnd(1000),100,rnd(1000)
next i
 
for i=6 to 10
   make object sphere i, rnd(100)+50
   position object i, rnd(1000),100,rnd(1000)
next i
 
rem make some ground
make object plain 11, 1000,1000
xrotate object 11, 90
position object 11, 500,0,500
texture object 11, 1
scale object texture 11,10,10
set object light 11, 0
 
 
REM END OF LINE OBJECT
make object sphere 100,10
color object 100,rgb(255,0,0)
 
 
REM ================== MAIN LOOP ===============
DO
 
 
   gosub PLAYER_CONTROLS
   gosub CAMERA_STATUS
 
 
 
   d# = cos(cxa#) * line#
   ty# = y# - sin(cxa#) * line#
   tx# = newxvalue(x#,a#,d#)
   tz# = newzvalue(z#,a#,d#)
 
 
   olddist# = line#
   for obj=1 to 11
      dist# = intersect object(obj, x#,y#,z#,tx#,ty#,tz#)
      if dist# < olddist# and dist# > 0
         olddist# = dist#
      endif
   next obj
 
   dist# = olddist#
 
   if dist# = 0 then dist# = line#
 
   gdist# = cos(cxa#)*dist#
   tx# = newxvalue(x#, a#, gdist#)
   ty# = y# - sin(cxa#)*dist#
   tz# = newzvalue(z#, a#, gdist#)
 
 
   position object 100,tx#,ty#,tz#
 
 
 
   text 1,1,"FPS: "+str$(screen fps())
   text 1, 10,"Distance: "+str$(dist#)
   set cursor 0,20
   print object position x(100)
   print object position y(100)
   print object position z(100)
 
sync
loop
 
 
REM control player's movement
PLAYER_CONTROLS:
  runspeed#=0
  if shiftkey()=1 then runspeed#=-5.5
  if upkey()=1
    x#=newxvalue(x#,a#,6+runspeed#)
    z#=newzvalue(z#,a#,6+runspeed#)
  endif
  if downkey()=1
    x#=newxvalue(x#,a#,-6-runspeed#)
    z#=newzvalue(z#,a#,-6-runspeed#)
  endif
  if leftkey()=1
    x#=newxvalue(x#,wrapvalue(a#-90.0),6.0+runspeed#)
    z#=newzvalue(z#,wrapvalue(a#-90.0),6.0+runspeed#)
  endif
  if rightkey()=1
    x#=newxvalue(x#,wrapvalue(a#+90.0),6.0+runspeed#)
    z#=newzvalue(z#,wrapvalue(a#+90.0),6.0+runspeed#)
  endif
 
RETURN
 
 
REM control player's angle of site/rotation and position
CAMERA_STATUS:
  rem rotate camera according to mouse
  a#=wrapvalue(a#+(mousemovex()/3.0))
  rem position and rotate camera
  cxa#=cxa#+(mousemovey()/3.0)
  if cxa#<-90.0 then cxa#=-90.0
  if cxa#>90.0 then cxa#=90.0
  position camera x#,y#,z#
  rotate camera wrapvalue(cxa#),a#,0
RETURN