Hello. I have tried to add GOSUB functions to my code to add explosion effects, implement 3d sound, as well as add particle effects. Now, since I added the explosion effects, when I shoot the bullet, the sound effect of the explosion keeps going off and the bullet is
tiny and lodged in the ground at my feet. WTF?!? I checked the bullet code several times and cannot figure out what is going on!
roject: gosub2
Rem Created: 8/7/2004 11:17:19 AM
Rem ***** Main Source File *****
sync on
sync rate 30
backdrop on
hide mouse
rem load sounds
load 3dsound "Large explosion 2.wav",2
set sound volume 2, 100
rem set up scene
set camera range 1,5000
fog on
fog distance 4000
fog color rgb(128,128,128)
color backdrop rgb(128,128,128)
rem make matrix
make matrix 1,10000,10000,20,20
load image "rustyIron.bmp",1
prepare matrix texture 1,1,1,1
fill matrix 1,0,1
randomize matrix 1,125
rem load alien model
load object "L-Alien Mutant-Idle.x",4
scale object 4,5000,5000,5000
loop object 4
position object 4,4500,get ground height (1,4500,4500),4500
set object collision to boxes 4
autocam off
position camera 4999,4999,4999
X# = 4999
Y# = 4999
Z# = 4999
rem make gun
make object cylinder 30,2
xrotate object 30,90
fix object pivot 30
scale object 30,100,100,500
position object 30,0,-7,15
lock object on 30
rem make bullets
make object sphere 2,2
hide object 2
set object collision to spheres 2
load sound "music triumph loop.wav",1
loop sound 1
rem load particles
load image "firez.bmp",2
for x = 0 to 10
make object plain x+10,5,5
texture object x+10,2
set object x+10,1,0,0
ghost object on x+10
next x
rem Make Explosion
Make Object Sphere 31,20
texture object 31,2
ghost object on 31
Hide Object 31
Make Object Sphere 32,20
texture object 32,2
ghost object on 32
Hide Object 32
Load 3Dsound "Large explosion 1.wav",3
rem initialize particle counter
pn = 10
rem main game loop
do
set cursor 0,0
print screen fps()
print X#
print Y#
print Z#
rem get camera angles
oldcamangleY# = camangleY#
oldcamangleX# = camangleX#
camangleY# = wrapvalue(camangleY#+mousemoveX()*0.2)
camangleX# = wrapvalue(camangleX#+mousemoveY()*0.2)
if explode > 0 then gosub ExplodeRocket
rem get control input
if upkey()=1
xtest#=newxvalue(x#,camangleY#,20)
ztest#=newzvalue(z#,camangleY#,20)
if xtest#>=0 and xtest<=10000 and ztest#>=0 and ztest#<=10000
X#=xtest#
Z#=ztest#
endif
endif
if downkey()=1
xtest#=newxvalue(X#,wrapvalue(camangleY#-180),10)
ztest#=newzvalue(Z#,wrapvalue(camangleY#-180),10)
if xtest#>=0 and xtest<=10000 and ztest#>=0 and ztest#<=10000
X# = xtest#
Z# = ztest#
endif
endif
rem Here is where I added the strifing
if leftkey()=1
xtest#=newxvalue(X#,WrapValue(camangleY#-90),10)
ztest#=newzvalue(Z#,wrapvalue(camangleY#-90),10)
if xtest#>=0 and xtest#<=10000 and ztest#>=0 and ztest#<=10000
X# = xtest#
Z# = ztest#
endif
endif
rem more strifing here
if rightkey()=1
xtest#=newxvalue(X#,wrapvalue(camangleY#+90),10)
ztest#=newzvalue(Z#,wrapvalue(camangleY#+90),10)
if xtest#>=0 and xtest#<=10000 and ztest#>=0 and ztest#<=10000
X# = xtest#
Z# = ztest#
endif
endif
rem position listener for 3-D sound
position listener X#,Y#+50,Z#
rotate listener 0,camangleY#,0
rem get mouse input and prepare bullet
if mouseclick()=1 and explode = 0
if bulletlife < 50
position object 2,X#,Y#-7,Z#
set object to camera orientation 2
Bulletlife = 120
show object 2
loop sound 2
endif
endif
if bulletlife>0 then gosub ShootBullet
rem set so player cannot look past 360 degrees
if camangleX#>270
if camangleX# - 270 > 90 then camangleX# = 270
else
if camangleX# > 90 and camangleX#-270 < 270 then camangleX# = 90
endif
Yrotate camera curveangle(camangleY#,oldcamangleY#,24)
Xrotate camera curveAngle(camangleX#,oldcamangleX#,24)
y# = get ground height(1,X#,Z#)
position camera X#,Y#+50,Z#
sync
loop
rem the subfunction for the bullet --Think the problem is here--
ShootBullet:
Dec bulletlife
move object 2,20
if object collision(4,2) then stop sound 1
bX# = object position x(2)
bY# = object position y(2)
bZ# = object position z(2)
rem patricles
inc pn
if pn>20 then pn=10
scale object pn,100,100,100
position object pn,bX#,bY#,bZ#
point object pn,bX#,bY#,bZ#
Zrotate object pn,rnd(180)
rem part of tut, not sure what this does
for x = 1 to 10
scale object int((Wrapvalue((Pn-9+x)*36))/36)+10,100+x*25,100+x*25,100+x*25
set cursor 10,10
print int((wrapvalue(pn+x)*36))/36+10
next x
rem 3-D sound and stop bullet and particles if bullet life = 0
position sound 2,bX#,bY#,bZ#
if bulletlife = 0
hide object 2
stop sound 2
for x = 10 to 20
hide object x
next x
explode = 20
endif
if bY# < get ground height(1,bX#,bZ#) then bulletlife=0
return
rem set up the explosion.
rem when this was added, the code really started messing up
ExplodeRocket:
position object 31,bX#,bY#,bZ#
show object 31
position object 32,bX#,bY#,bZ#
show object 32
Escale=20*(30-explode)
scale object 31,Escale,Escale,Escale
Yrotate object 31,Wrapvalue(explode*37)
scale object 32,Escale/1.5,Escale/1.5,Escale/1.5
Yrotate object 32,Wrapvalue(359-explode*37)
dec explode
if explode = 0
hide object 31
hide object 32
endif
if explode = 18
position sound 3,bX#,bY#,bZ#
play sound 3
endif
if explode < 15 then position sound 3,X#,Y#,Z#
return
Before adding the explosion, the bullet would shoot streight ahead and have a particle fire effect after it. Now, unless you look down, you will not see a bullet. The bullet is stuck in the ground at the players feet! Can someone please help!
Fraggles where quite the scary lot...