Rem Project: Target Practice by Ric
Rem Created: 18/01/2005 02:58:42
 
Rem ***** Main Source File *****
 
hide mouse
sync on
sync rate 100
autocam off
position camera 0,14,-5
color backdrop rgb(200,200,255)
fog on
fog distance 2500
 
 
for x=1 to 10
for y=1 to 10
ink rgb(rnd(100),rnd(155)+100,0),0
dot x,y
next y
next x
get image 1000,1,1,10,10
 
make object plain 1000,1000,1000
xrotate object 1000,-90
texture object 1000,1000
scale object texture 1000,10,10
set object texture 1000,2,0
 
`make rifle
make object cylinder 2000,1
scale object 2000,80,1500,80
set object cull 2000,0
color object 2000,rgb(40,30,20)
xrotate object 2000,90
fix object pivot 2000
position object 2000,0,10,0
 
`dummy object for crosshairs
make object cube 4000,1
hide object 4000
 
`make bullets
numberofbullets=60
dim bullet(numberofbullets) as usertype
 
type usertype
 
  xspeed as float
  yspeed as float
  inflight as boolean
 
endtype
 
for bullet=1 to numberofbullets
make object sphere bullet,2
position object bullet,0,10,0
set object collision on bullet
next bullet
 
bulletnumber=1
power#=40
reload=6
 
`make claypigeons
make object sphere 3000,14
scale object 3000,100,30,100
set object collision on 3000
position object 3000,-300,10,500
 
cppower#=2.0
gravity#=0.02
 
ink 0,0
set text font "arial"
set text size 20
 
createsound("explode",1,6200,7000,2000,20,0.2,0,0,0,0)
createsound("gun1",2,60,200,6000,0.001,1.2,.0,0,0,0)
createsound("gun2",4,2000,200,3000,-200,1.2,.0,0,0,0)
createsound("pull",3,800,1000,5000,100.0,0.3,.1,0,0,0)
 
 
 
do
 
inc t
if t>200 then t=0
if t=0 then gosub pull
gosub update_cp
gosub aim
gosub fire
gosub update_bullet
gosub collision
gosub score
text 0,20,"fps: "+str$(screen fps())
sync
loop
 
aim:
mx#=mousemovex()
my#=-mousemovey()
inc aimx#,mx#/2
inc aimy#,my#/2
 
position object 4000,aimx#,aimy#,200
line object screen x(4000)-5,object screen y(4000),object screen x(4000)+5,object screen y(4000)
line object screen x(4000),object screen y(4000)-5,object screen x(4000),object screen y(4000)+5
point object 2000,aimx#,aimy#,200
 
return
 
fire:
inc reload_time
if mouseclick()=1 and bullet(bulletnumber).inflight=0 and reload_time>reload
  set object to object orientation bulletnumber,2000
  bullet(bulletnumber).xspeed=power#
  bullet(bulletnumber).inflight=1
  play sound 2:play sound 4
  inc bulletnumber
  reload_time=0
  if bulletnumber>numberofbullets then bulletnumber=1
endif
 
 
return
 
update_bullet:
 
for updatebullet=1 to numberofbullets
  if bullet(updatebullet).inflight=1
    move object updatebullet,bullet(updatebullet).xspeed
    inc bullet(updatebullet).yspeed,gravity#
    move object down updatebullet,bullet(updatebullet).yspeed
    if object position z(updatebullet)>600
      bullet(updatebullet).inflight=0
      bullet(updatebullet).xspeed=0
      bullet(updatebullet).yspeed=0
      position object updatebullet,0,10,0
      reload_time=0
    endif
  endif
next updatebullet
 
return
 
pull:
 
if cpinflight=0
cpyspeed#=0
inc pulls
show object 3000
if object exist (3001) then delete object 3001
if object exist (3002) then delete object 3002
set object collision on 3000
position object 3000,-300,10,500
rotate object 3000,0,0,0
turn object right 3000,90
pitch object up 3000,40+rnd(10)
cpinflight=1
play sound 3
endif
 
return
 
update_cp:
 
if cpinflight=1
move object 3000,cppower#
move object down 3000,cpyspeed#
if object exist(3001) then position object 3001,object position x(3000)-deflection2#,object position y(3000)+deflection1#,object position z(3000)
if object exist(3002) then position object 3002,object position x(3000),object position y(3000)-deflection2#,object position z(3000)
inc cpyspeed#,gravity#/2
inc deflection1#,deflectionamount#
inc deflection2#,deflectionamount#/2
if object position y(3000)<0 then cpinflight=0
endif
 
return
 
collision:
 
object=object collision(3000,0)
if object>0 and object<=numberofbullets
  make object sphere 3001,7
  make object sphere 3002,7
  scale object 3001,100,30,100
  scale object 3002,100,30,100
  inc score
  deflection1#=0
  deflection2#=0
  deflectionamount#=(rnd(10)/10.0)+0.2
  hide object 3000
  set object collision off 3000
  play sound 1
endif
 
return
 
score:
 
text 0,0,"Score: "+str$(score)+" out of "+str$(pulls)
 
return
 
 
 
function createsound(name$,soundnumber,frequency#,length#,loudness#,bend#,decay#,vibratospeed#,vibratodepth#,tremelospeed#,tremelodepth#)
 
if file exist(name$+".wav")=1 then delete file name$+".wav"
open to write 1,name$+".wav"
chunk=int(((length#/1000)*44100*16)/8) `sample size (no of samples * bitrate * channels / 8)
samples=int((length#/1000)*44100) `length *44100
restore
for x=1 to 40
   read byte2
   write byte 1, byte2
next x
write long 1,chunk
rem generate and write wave
for x=1 to samples
  output#=int(sin((x/122.5)*(frequency#+vibratodepth#*sin(theta#)))*(loudness#+tremelodepth#*sin(phi#)))*3.0
  inc theta#,vibratospeed#
  inc phi#,tremelospeed#
  dec frequency#,bend#
  if loudness#>0 then dec loudness#,decay#
  write word 1,output#
next x
close file 1
 
load sound name$+".wav",soundnumber
 
data 82:data 73:data 70:data 70:data 208:data 59:data 1:data 0:data 87
data 65:data 86:data 69:data 102:data 109:data 116:data 32:data 16
data 0:data 0:data 0:data 1:data 0:data 2:data 0:data 34:data 86:data 0
data 0:data 136:data 88:data 1:data 0:data 4:data 0:data 16:data 0
data 100:data 97:data 116:data 97
 
endfunction