i am making a game that is based off of cnc generals:zero hour, but it is more of an fps than a rts, but anyway, i am just trying to get the basics done and i have run into a small problem...
i have added some code that baiscally says when space is pressed the tank should fire, and when the shell is lower than the matrix then an explosion should be triggered, this all works fines, the shell is fired it goes to the marker and explodes, but when i try and fire a second shell for some reason it explodes where it generated rather than the travelling to the marker and exploding, i have looked thorugh my code and i can't find the problem, maybe someone with a more experienced eye can spot the problem...
set window on
rem Make matrix
make matrix 1,10000.0,10000.0,25,25
load bitmap "floor1.bmp",1
get image 1,0,0,256,256
delete bitmap 1
prepare matrix texture 1,1,2,2
randomize matrix 1,75.0
set matrix height 1,12,12,200.0
set matrix height 1,13,12,200.0
set matrix height 1,12,13,200.0
set matrix height 1,13,13,200.0
update matrix 1
rem Create Lighting
make light 1
set point light 1,50,50,100
point light 1,0,0,0
color light 1,-255,-255,-255
rem Create tank
Load object "box.x",1
set object speed 1,30
load mesh "wheel.x",1
add limb 1,2,1
offset limb 1,2,25,10,20
load mesh "wheel.x",2
add limb 1,3,2
offset limb 1,3,-25,10,20
load mesh "wheel.x",3
add limb 1,4,3
offset limb 1,4,25,10,-20
load mesh "wheel.x",4
add limb 1,5,4
offset limb 1,5,-25,10,-20
load mesh "turret.x",5
add limb 1,6,5
offset limb 1,6,0,25,0
make object sphere 2,125
position object 2,OBJECT POSITION X(1),OBJECT POSITION y(1),OBJECT POSITION z(1)
set object 2,0,1,0,1,0,1,1
color object 2,rgb(0,255,0)
load object "rocket.x",3
make object sphere 4,100
ghost object on 4
hide object 4
rem Set Variables for speed
s#=0
rem Set variables for character position
x#=2500
z#=2500
rx#=2500
rz#=2500
q#=10
air#=0
distance#=500
rem Activate manual sync
sync on
rem Begin loop
do
rem object frame
f# = object frame(1)
f2# = total object frames(1)
b#=0.5
t#=5
ms#=25
rem Control rocket buggy with arrow keys
if air#=0
if controlkey()=1 then b#=2 : t#=10 : ms#=15
if upkey()=1
s#=s#+2
if s#>ms# then s#=ms#
x#=newxvalue(x#,a#,s#)
z#=newzvalue(z#,a#,s#)
endif
if downkey()=1 then x#=newxvalue(x#,a#,-5) : z#=newzvalue(z#,a#,-5) : s#=1
pitch object down 1, p#
if leftkey()=1 and s#>0 then turn object left 1,t#: a#=wrapvalue(a#-t#) : as#=wrapvalue(as#-t#)
if rightkey()=1 and s#>0 then turn object right 1,t#: a#=wrapvalue(a#+t#) : as#=wrapvalue(as#+t#)
pitch object up 1, p#
if keystate(17)=1 then distance# = distance#+10
if keystate(31)=1 then distance# = distance#-10
if keystate(30)=1 then rotate limb 1,6,0,wrapvalue(limb angle y(1, 6)-4),0 : as#=wrapvalue(as#-4)
if keystate(32)=1 then rotate limb 1,6,0,wrapvalue(limb angle y(1, 6)+4),0 : as#=wrapvalue(as#+4)
if spacekey()=1 then az#=as# : height#=launch(distance#) : launch#=1
endif
rem choose camera angle
reverse#=0
if scancode()=2 then camera#=0
if scancode()=3 then camera#=1
if scancode()=4 then camera#=2
if scancode()=16 then reverse#=1
rem Gentle Stop
if air#=0
if upkey()=0
s#=s#-b#
if s#>0
x#=newxvalue(x#,a#,s#)
z#=newzvalue(z#,a#,s#)
endif
if s#<0 or s#=0 then s#=0
endif
endif
rem Update character
x3#=newxvalue(x#,a#,50)
z3#=newzvalue(z#,a#,50)
x4#=newxvalue(x#,a#,-50)
z4#=newzvalue(z#,a#,-50)
pitch object down 1, p#
p# = y3#-y4#
p# = p# * p#
p# = p# + 1000
p# = sqrt(p#)
p# = (y3#-y4#)/p#
p# = asin(p#)
set cursor 5,5
print "x: ", x#
print "y: ", y#
print "z: ", z#
print "distance: ", distance#
print "height: ",height#
print "height: ",object position y(3)
print "detonate: ", detonate#
print "vl#: ", vl#
print "object size: ",OBJECT SIZE X(4)
pitch object up 1, p#
p2# = p#
y2#=y#-(2*rate_fall#)
if y2#<get ground height(1,x#,z#)
y#=get ground height(1,x#,z#)
y3#=get ground height(1,x3#,z3#)
y4#=get ground height(1,x4#,z4#)
rate_fall#=1
air#=0
else
y#=y2#
rate_fall#=rate_fall#+0.3
air#=1
x#=newxvalue(x#,a#,s#)
z#=newzvalue(z#,a#,s#)
endif
position object 1,x#,y#,z#
rem yrotate object 1,a#
aim#=get ground height(1,newxvalue(x#,as#,distance#),newzvalue(z#,as#,distance#))
position object 2,newxvalue(x#,as#,distance#),aim#,newzvalue(z#,as#,distance#)
if distance#<300 then color object 2,rgb(255,0,0)
if distance#>900 then color object 2,rgb(255,0,0)
if distance#>300 and distance#<900 then color object 2,rgb(0,255,0)
wheel(s#)
if launch# = 1 then detonate#=update_shell(height#,az#)
if detonate# = 1 then launch# = 0 : vl#=detonate(vl#) : scale object 4,vl#,vl#,vl#
if vl#>150 then detonate# = 0 : hide object 4 : vl#=0 : position object 3,0,0,0
rem Position camera to the back of the buggy
if camera#=0
ca#=wrapvalue(curveangle(a#,ca#,12.0))
cx#=newxvalue(x#,wrapvalue(ca#+180),300)
cz#=newzvalue(z#,wrapvalue(ca#+180),300)
cy#=get ground height(1,cx#,cz#)+100.0
position camera cx#,cy#,cz#
yrotate camera wrapvalue(ca#)
endif
if reverse#=1
ca#=wrapvalue(curveangle(a#,ca#,12.0))
cx#=newxvalue(x#,wrapvalue(ca#+0),300)
cz#=newzvalue(z#,wrapvalue(ca#+0),300)
cy#=get ground height(1,cx#,cz#)+100.0
position camera cx#,cy#,cz#
yrotate camera wrapvalue(ca#+180)
endif
rem Syncronise
sync
rem End loop
loop
function wheel(s#)
for banana = 2 to 5
rotate limb 1,banana,wrapvalue(limb angle x(1, banana)+s#),0,0
next banana
endfunction
function launch(distance#)
y#=get ground height(1,object position x(1),object position z(1)) + 50
y2#=get ground height(1,object position x(2),object position z(2))
height#=y#-y2#
height#=height#/(distance#/50)
position object 3,object position x(1),object position y(1)+50,object position z(1)
endfunction height#
function update_shell(height#,az#)
yrotate object 3,az#
x#=newxvalue(object position x(3),az#,50)
z#=newzvalue(object position z(3),az#,50)
y#=object position y(3)-height#
position object 3,x#,y#,z#
if object position y(3)<get ground height(1,x#,z#) then detonate# = 1
endfunction detonate#
function detonate(vl#)
hide object 3
position object 4,object position x(3),get ground height(1,object position x(3),object position z(3)),object position z(3)
vl#=vl#+10
show object 4
scale object 4,vl#,vl#,vl#
endfunction vl#
NOTE: yeah i know my code is a mess