I have been making a car game but recently for no apparent reason it suddenly seems to be crashing.
When I run the program, it suddenly stops and the only way to end it is by using task manager.
Is there a reason? Does this happen for you?
topsp#=0.5
sync on
gosub setup
`**************************************************************************
mainloop:
do
gosub cam_control
gosub movementcontrol
sync
loop
return
`**************************************************************************
cam_control:
REM MAKE THE CAMERA FOLLOW THE TAXI
set camera to follow x#,y#,z#,ay#,5,y#+1.5,5,1
return
`**************************************************************************
setup:
REM LOAD AND SET UP TAXI
Load object \"cars/H-taxi-move.x\",2
yrotate object 2,180;fix object pivot 2
set object collision to polygons 2
rem get the sizes and offset for sparky tilt
xsize#=object size x(2)
zsize#=object size z(2)
scale object 2,50,50,50
rem since the object has scaled, let\'s calibrate the offsets and sizes
xsize#=xsize#*.5
zsize#=zsize#*.5
xoffset#=xsize#/2.0
zoffset#=zsize#/2.0
rem need a pivot object
make object box 1,object size x(2)-1,object size y(2),object size z(2)-2.55
REM MAKE BLACK IMAGE FOR TAXI PIVOT
create bitmap 1,1,1
ink 0,0
dot 1,1
get image 1001,0,0,1,1
delete bitmap 1
texture object 1,1001
delete image 1001
ghost object on 1
glue object to limb 2,1,0
piv=1
car=2
terrain=1000
maxy#=10000
miny#=-10000
lmb=0
REM CREATE TEMPORARY MATRIX AND TEXTURE
load image \"ground\\road2.jpg\",1000
load object \"ground\\terrainraised.x\",1000
scale object 1000,4000,1000,4000
texture object 1000,1000
setupObjectDBC(1000,0,0)
updateobjectdbc(1000)
gosub load_buildings
gosub mainloop
return
`**************************************************************************
Load_Buildings:
rem ThatchedHouse1
load image \"buildings/thatchedhouse1.jpg\",1001
load object \"buildings/thatchedhouse1.x\",1001
position object 1001,0,10,100
yrotate object 1001,90
scale object 1001,300,300,300
texture object 1001,1001
set object collision to polygons 1001
set global collision on
return
`**************************************************************************
building_hit:
if object collision(1001,1)=0
if sp#>0 then spdirection#=1
if sp#=0 then spdirection#=0
if sp#<0 then spdirection#=-1
endif
if object collision(1001,1)=1
if spdirection#=1 then if sp#>0 then sp#=0
if spdirection#=-1 then if sp#<0 then sp#=0
endif
return
`**************************************************************************
Movementcontrol:
REM MAKING YOU SPEED UP WHEN YOU PRESS UP
if upkey()=1 and sp#<topsp# then sp#=sp#+0.0025
REM MAKING YOU SLOW DOWN WHEN YOU AREN\'T PRESSING UP OR DOWN
if upkey()=0 and downkey()=0 and sp#>0 then sp#=sp#-0.001
if sp#>-0.002 and sp#<0.002 then sp#=0
REM MAKING YOU GO BACKWARDS WHEN YOU PRESS BACK
if downkey()=1 then sp#=sp#-0.0025
REM IF YOU BRAKE THEN SLOW DOWN
if spacekey()=1
if sp#>0 then sp#=sp#-0.007
if sp#<0 then sp#=sp#+0.007
endif
REM IF YOU ARE TRYING TO TURN YOU TURN
if rightkey()=1
if returnkey()=0
ay#=ay#+sp#*1.5
else
ay#=ay#+sp#*3
endif
endif
if leftkey()=1
if returnkey()=0
ay#=ay#-sp#*1.5
else
ay#=ay#-sp#*3
endif
endif
if ay#<0 then ay#=ay#+360
if ay#>360 then ay#=ay#-360
y#=sparky_tilt(piv,car,lmb,terrain,xsize#,zsize#,xoffset#,zoffset#,maxy#,miny#)
gosub building_hit
text 0,0,str$(sp#)
REM MAKING YOU MOVE AT THE CURRENT SPEED
x#=newxvalue(x#,ay#,sp#);z#=newzvalue(z#,ay#,sp#)
REM POSITION THE TAXI AT X# AND Z#
position object 1,x#,y#,z#;yrotate object 1,ay#;xrotate object 1,ax#
return
`**************************************************************************
function setupObjectDBC(objNum,groupNum,objectType)
commonSetup(objNum)
vertData = get memblock ptr(254)
objectData = get memblock ptr(255)
call dll 1,\"setupObject\",objNum,groupNum,objectType,vertData,objectData
delete memblock 254
endfunction
function setupComplexObjectDBC(objNum,groupNum,facesPerNode)
commonSetup(objNum)
vertData = get memblock ptr(254)
objectData = get memblock ptr(255)
call dll 1,\"setupComplexObject\",objNum,groupNum,facesPerNode,vertData,objectData
delete memblock 254
endfunction
function commonSetup(objNum)
if dll exist(1)=0 then load dll \"DBCcollision.dll\",1
if memblock exist(255)=0 then make memblock 255,24
x#=object position x(objNum)
y#=object position y(objNum)
z#=object position z(objNum)
angx#=object angle x(objNum)
angy#=object angle y(objNum)
angz#=object angle z(objNum)
write memblock float 255,0,x#
write memblock float 255,4,y#
write memblock float 255,8,z#
write memblock float 255,12,angx#
write memblock float 255,16,angy#
write memblock float 255,20,angz#
position object objNum,0,0,0
rotate object objNum,0,0,0
make mesh from object 255,objNum
make memblock from mesh 254,255
delete mesh 255
position object objNum,x#,y#,z#
rotate object objNum,angx#,angy#,angz#
endfunction
function updateObjectDBC(objNum)
if memblock exist(255)=0 then make memblock 255,24
write memblock float 255,0,object position x(objNum)
write memblock float 255,4,object position y(objNum)
write memblock float 255,8,object position z(objNum)
write memblock float 255,12,object angle x(objNum)
write memblock float 255,16,object angle y(objNum)
write memblock float 255,20,object angle z(objNum)
objectData = get memblock ptr(255)
call dll 1,\"updateObject\",objNum,objectData
endfunction
function intersectObjectDBC(objNum,groupFlag,oldx#,oldy#,oldz#,x#,y#,z#,excludeObj)
collide=call dll(1,\"intersectObject\",objNum,groupFlag,oldx#,oldy#,oldz#,x#,y#,z#,excludeObj)
endfunction collide
function setObjectCollisionOnDBC(objNum)
call dll 1,\"set_object_collision_on\",objNum
endfunction
function setObjectCollisionOffDBC(objNum)
call dll 1,\"set_object_collision_off\",objNum
endfunction
function collisionStatusDBC(objNum)
result=call dll(1,\"collisionstatus\",objNum)
endfunction result
function getStaticCollisionX()
result#=call dll(1,\"getStaticCollisionX\")
endfunction result#
function getStaticCollisionY()
result#=call dll(1,\"getStaticCollisionY\")
endfunction result#
function getStaticCollisionZ()
result#=call dll(1,\"getStaticCollisionZ\")
endfunction result#
function getCollisionNormalX()
result#=call dll(1,\"getCollisionNormalX\")
endfunction result#
function getCollisionNormalY()
result#=call dll(1,\"getCollisionNormalY\")
endfunction result#
function getCollisionNormalZ()
result#=call dll(1,\"getCollisionNormalZ\")
endfunction result#
function sparky_tilt(piv,car,lmb,terrain,xsize#,zsize#,xoffset#,zoffset#,maxy#,miny#)
remstart
Vehicle tilt on object terrain
by Latch
september 7 2008
calculate the x angle tilt and the z angle tilt
of Object or Limb car on Terrain terrain.
piv is the pivot object or root object to a limb.
lmb is a flag to indicate if car is a limb or an object
lmb = 0 object
lmb = 1 limb
xsize# is the x size of obj
zsize# is the z size of obj
xoffset# is xsize#/2
zoffset# is zsize#/2
maxy# is the highest y from which to cast a collision ray
miny# is the lowest end y of the collision ray
I decided to have these as parameters so they can be calculated
once outside of the function to keep processing overhead down.
It is possible to calculate them every iteration in the function
but it isn\'t necessary unless the shape and size of obj is changing
constantly.
This function requires Sparky\'s collision dll and
accompanying DBC library
for this I\'ll need to cast 5 rays:
center of vehicle
front of vehicle
back of vehicle
left of vehicle
right of vehicle
based on the the y values returned by Sparky\'s collision,
I pivot the vehicle on x and z based on the angle of the terrain
I can use a limb or a hidden object as the pivot
point for the vehicle so that it can be tilted on x and z
without changing the direction it gets moved
returns the height of the pivot object
remend
rem limb flag
if lmb >= 1
lmb=1
else
lmb=0
endif
rem calculate the 5 car positions
rem car center
carx#=object position x(piv)
carz#=object position z(piv)
carangy#=object angle y(piv)
rem front and back
fx#=newxvalue(carx#,carangy#,zoffset#) : fz#=newzvalue(carz#,carangy#,zoffset#)
bx#=newxvalue(carx#,wrapvalue(carangy#+180),zoffset#) : bz#=newzvalue(carz#,wrapvalue(carangy#+180),zoffset#)
rem left and right
lx#=newxvalue(carx#,wrapvalue(carangy#-90),xoffset#) : lz#=newzvalue(carz#,wrapvalue(carangy#-90),xoffset#)
rx#=newxvalue(carx#,wrapvalue(carangy#+90),xoffset#) : rz#=newzvalue(carz#,wrapvalue(carangy#+90),xoffset#)
rem now figure out positions of all five rays to cast
rem I use extremes for the y values that are larger than
rem the highest point on the terrain. Makes things
rem easy... but not necessarily the best way
y1#=maxy#
y2#=miny#
rem center ray
intersectObjectDBC(terrain,0,carx#,y1#,carz#,carx#,y2#,carz#,0)
hc#=getStaticCollisionY()
rem front
intersectObjectDBC(terrain,0,fx#,y1#,fz#,fx#,y2#,fz#,0)
hf#=getStaticCollisionY()
rem back
intersectObjectDBC(terrain,0,bx#,y1#,bz#,bx#,y2#,bz#,0)
hb#=getStaticCollisionY()
rem left
intersectObjectDBC(terrain,0,lx#,y1#,lz#,lx#,y2#,lz#,0)
hl#=getStaticCollisionY()
rem right
intersectObjectDBC(terrain,0,rx#,y1#,rz#,rx#,y2#,rz#,0)
hr#=getStaticCollisionY()
rem x tilt
xang#=atanfull(hb#-hf#,zsize#)
finalx#=curveangle(xang#,object angle x(car),10)
rem z tilt
zang#=atanfull(hr#-hl#,xsize#)
finalz#=curveangle(zang#,object angle z(car),10)
if lmb=0
rotate object car,finalx#,object angle y(car),finalz#
else
rotate limb piv,obj,finalx#,limb angle y(piv,obj),finalz#
endif
endfunction hc#
This is the code, I have also attached the files needed and the .dba file.
If it is necessary then I will find out my pc specs and tell u guys.
thanks,,,
Codeeater