It is a simple problem - you forgot to reset the
distance variable after the
delete object 1 command.
Try the following:
HIDE MOUSE
SYNC ON
DISTANCE=0
DO
IF MOUSECLICK()=1 AND OBJECT EXIST(1)=0
MAKE OBJECT SPHERE 1,3
POSITION OBJECT 1,0,0,0
ENDIF
IF OBJECT EXIST(1)=1
MOVE OBJECT 1,15
DISTANCE=DISTANCE+15
IF DISTANCE>=150 THEN DELETE OBJECT 1 : DISTANCE=0
ENDIF
SET CURSOR 0,0
PRINT "OBJECT EXIST: ",OBJECT EXIST(1)
PRINT "MOUSE CLICK: ",MOUSECLICK()
SYNC
LOOP
Here's an example I made for just this purpose. It's a bit rough but I think you will be able to follow it.
REM *************************************************************************
REM DEMO: ADVANCED SHOOTING
REM DATE: 5th December 2005
REM AUTHOR: HWT
REM This is an add-on to the previous resemblance of a demo (simple shooting
REM which showed no sound effects / flares (both of which this demo displays
REM together with faster bullet speeds (due to increased curvyness and value
REM destination.
REM *************************************************************************
`SET EMULATION ON
`SET DISPLAY MODE 320,240,16
`SET CAMERA VIEW 100,100,200,200
rem Making reticule
HIDE MOUSE
rem Making world
sync on
make matrix 1,2500,2500,15,15
make object cube 59,250
position object 59,1250,0,1250
rem Make gun
make object cylinder 1,5
xrotate object 1,90 : fix object pivot 1
scale object 1,100,100,500 : lock object on 1 : position object 1,10,-10,20
rem Making accessories
make object sphere 60,5
hide object 60
rem Resetting
gunpower=0
bulletlife=0
recoil#=0.0
maxrecoil#=5
recoilcurvyness#=2.5
maxrecoilangle#=-50
reload#=0.0
maxreload#=5.0
reloadcurvyness#=2.5
maxreloadangle#=12
ammo=10
do
rem Reticule
line 320,240-25,320,240+25
line 320-25,240,320+25,240
rem Simple camera movement
if leftkey()=1 then yrotate camera wrapvalue((camera angle y()-3.0))
if rightkey()=1 then yrotate camera wrapvalue((camera angle y()+3.0))
if upkey()=1 then x#=newxvalue(camera position x(),camera angle y(),5.0) : z#=newzvalue(camera position z(),camera angle y(),5.0)
if downkey()=1 then x#=newxvalue(camera position x(),camera angle y(),-5.0) : z#=newzvalue(camera position z(),camera angle y(),-5.0)
position camera x#,25.0,z#
REM *** HANDLING SHOOTING AND THE GUN ***
rem Preventing shooting if ammo is out
if ammo=0 and bulletlife=0 then bulletlife=0
rem Allowing for shooting
if ammo>0
if mouseclick()=1 and bulletlife=0 and gunpower=0
position object 60,x#,y#+25.0,z#
rotate object 60,camera angle x(),camera angle y(),0.0
bulletlife=25
gunpower=25
recoil#=maxrecoil#
dec ammo
endif
endif
rem Handling bullet life
if bulletlife > 0
dec bulletlife
move object 60,curvevalue(20000.0,0.0,50.0)
else
position object 60,x#,y#+25.0,z#
rotate object 60,camera angle x(),camera angle y(),0.0
endif
rem Handling gun power meter
if gunpower>0 then dec gunpower
if gunpower=0 then gunpower=0
rem Handling gun recoil
if recoil#>0.0
dec recoil#
if recoil#>maxrecoil#/2.0 then xrotate object 1,curveangle(maxrecoilangle#,object angle x(1),recoilcurvyness#)
if recoil#<=maxrecoil#/2.0 then xrotate object 1,curveangle(0.0,object angle x(1),recoilcurvyness#) : reload#=maxreload#+10
endif
if reload#>0.0
dec reload#
if reload#>(maxreload#/2.0) then xrotate object 1,curveangle(maxreloadangle#,object angle x(1),reloadcurvyness#)
if reload#<=(maxreload#/2.0) then xrotate object 1,curveangle(0.0,object angle x(1),reloadcurvyness#)
endif
rem Handling gun power meter
ink rgb(245,245,245),0 : text screen width()-105, screen height()-20,"POWER:"
set text font "system"
if gunpower=20 then ink rgb(255,51,0),0 : text screen width()-40,screen height()-20,""
if gunpower=15 then ink rgb(204,102,0),0 : text screen width()-40,screen height()-20,""
if gunpower=10 then ink rgb(153,153,0),0 : text screen width()-40,screen height()-20,""
if gunpower=5 then ink rgb(102,204,0),0 : text screen width()-40,screen height()-20,""
if gunpower=0 then ink rgb(51,255,0),0 : text screen width()-40,screen height()-20,""
rem Handling simple cube AI
move object 59,5
dec changeanglelife
if changeanglelife<=0
cubey#=rnd(360.0)
yrotate object 59,wrapvalue(cubey#)
changeanglelife=100
endif
rem Output
ink rgb(255,255,255),0
center text 320,0,"USE CONTROLKEY TO FIRE"
center text 320,25,"USE ARROW KEYS TO MOVE"
text 0,450,"AMMO:"+str$(ammo)
if object collision(60,59)>0 then ouchy#=1.0
if ouchy#>0.0 then dec ouchy#,0.1 : color object 59,rgb(ouchy#*600.0,0,0)
if ouchy#<=0.0 then color object 59,rgb(200,200,200)
sync
loop
HelloWorld Tommorrow