Can anybody tell me what is wrong with my level loading code?i cant load my levels and it continue to clear up the "infinitely" after i managed to pick up the last waypoint. Please help me
#include "LoadMatrix.dba"
`------
`ARRAYS
`------
`declare the MatEdit variables
Dim BigMatrix(600,600,1)
Dim StartLoc_X(1): Dim StartLoc_Z(1):Dim Info(2)
Dim TArrayX(1): Dim TArrayZ(1): Dim FKey(10,1)
Dim ColData(100): Dim ZoneData(100): Dim Tiles(500,500)
Dim OverTexture$(100): Dim OverName$(20): Dim ReplaceTex(100)
Dim MOffsetX(25): Dim MOffsetY(25)
Dim MWire(20): Dim MGhost(20): Dim Lock(20)
Dim MatX#(20): Dim MatY#(20): Dim MatZ#(20)
Dim MatWidth#(20): Dim MatHeight#(20)
Dim TilesX(20): Dim TilesZ(20)
Dim MatHi#(20): Dim MatLo#(20)
dim gravity#(0):gravity#(0)=0.1
`player arrays
dim xSpeed#(2)
dim ySpeed#(2)
dim zSpeed#(2)
dim friction#(2)
dim movedist#(2)
dim xSpot#(32)
dim zSpot#(32)
dim spot(0)
dim spot2(0)
dim score(2)
WORLD=1
` choose()
`WORLD1()
do
clear()
gosub choose
main()
loop
`end
function main()
do
if spacekey()=1
clear()
endif
`update the player
move_player(1,forward,backward,left,right)
watch(1)
`control_player(2)
`update the camera
chase_cam(1)
for id=1 to 2
if score(id)=2
if id=1
exitfunction
`exitfunction
else
lose()
`:exit:exitfunction
endif
endif
next id
` if score(1)=2
` exit
`clear()
`endif
collide()
text 1,80,str$(world)
`update the screen
sync
loop
`exitfunction
endfunction
function collide()
for id=1 to 2
xPos#=object position x(id)
yPos#=object position y(id)
zPos#=object position z(id)
collide=object collision(id,0):rem checks collision between racers
if collide > 0
xPos#=xPos#-(get object collision x()/2)
zPos#=zPos#-(get object collision z()/2)
endif
Position object id,xPos#,yPos#,zPos#
next id
endfunction
function win()
yAng=object angle y(1)
time=0
do
control_player(2)
`camera tricks
yAng=yAng+2
xCamPos#=newxvalue(object position x(1),yAng,25)
zCamPos#=newzvalue(object position z(1),yAng,25)
yCamPos#=get ground height(1,xCamPos#,zCamPos#)+3
position camera xCamPos#,yCamPos#,zCamPos#
point camera object position x(1),object position y(1),object position z(1)
collide()
inc time
if time>=60 then exit
` world=world+1
` clear()
`exitfunction
`exit
`gosub choose
`11 gosub main1
`endif
sync
loop
endfunction
`player lose
function lose()
yAng=object angle y(1)
do
for id=1 to 2
control_player(id)
next id
`camera tricks
xCamPos#=curvevalue(250,camera position x(),50)
zCamPos#=curvevalue(250,camera position z(),50)
yCamPos#=curvevalue(100,camera position y(),50)
position camera xCamPos#,yCamPos#,zCamPos#
point camera object position x(2),object position y(2),object position z(2)
collide()
sync
loop
endfunction
`-----------------------------------
`racing artificial intelligence
`-----------------------------------
function control_player(id)
xPos#=int(object position x(id))
zPos#=int(object position z(id))
xSpot#(spot)=int(xSpot#(spot))
zSpot#(spot)=int(zSpot#(spot))
forward=1
if xPos# >= xSpot#(spot) - 5 And xPos# <= xSpot#(spot) + 5 and zPos# >= zSpot#(spot) - 5 and zPos# <= zSpot#(spot) + 5
inc spot
score(id)=score(id)+1
if spot > 32 then spot=0
else
point object id,xSpot#(spot),object size y(id)/2,zSpot#(spot)
endif
move_player(id,forward,backward,left,right)
text 1,50,str$(score(id))
endfunction
`-----scoring 4 player1
function watch(id)
xPos#=int(object position x(id))
zPos#=int(object position z(id))
xSpot#(spot2)=int(xSpot#(spot2))
zSpot#(spot2)=int(zSpot#(spot2))
`yAng=object angle y(id)
` forward=1
if xPos# >= xSpot#(spot2) - 10 And xPos# <= xSpot#(spot2) + 10 and zPos# >= zSpot#(spot2) - 10 and zPos# <= zSpot#(spot2) + 10
inc spot2
score(id)=score(id)+1
if spot2 > 32 then spot2=0
endif
if spot2 >0
`for spot2 =1 to 32
angleway1#=atanfull(xSpot#(spot2-1)-xSpot#(spot2),zSpot#(spot2-1)-xSpot#(spot2))+yAng
angleway2#=atanfull(xSpot#(spot2)-xPos#,zSpot#(spot2)-zSpot#)
` angledet#=angleway1# + yAng
` If angleway1# < 90 Or angleway1# > 270
`print "hi"
`Car facing right direction
` Else
` print "no"
`Car facing wrong direction
` EndIf
`
`sed# = sqrt(sqr(xPos#-xSpot#(spot2))+sqr(zPos#-zSpot#(spot2)))
`next spot2
endif
`If spot2 >0
` angleway2#=atanfull(xSpot#(spot2)-xPos#,zSpot#(spot2)-zSpot#)
`endif
text 1,30,str$(score(id))
text 1,10,str$(angleway2#)
text 1,0,str$(angleway1#)
`text 1,10,str$(zpos#)
`text 1,0,str$(xpos#)
endfunction
`---------------------
`---------
`chase cam
`---------
function chase_cam(id)
`work out the angle of the object being chased
yAng#=wrapvalue(object angle y(id)+180)
`grab the cameras current position
xPos#=object position x(id)
yPos#=object position y(id)
zPos#=object position z(id)
`other variables
camDist=5
camHeight=2
`work out new position
xCamPos#=newxvalue(xPos#,yAng#,camDist)
zCamPos#=newZvalue(zPos#,yAng#,camDist)
`work out camera height
yCamPos#=get ground height(1,xCamPos#,zCamPos#)+camHeight
if yCamPos#<yPos#+camHeight then yCamPos#=yPos#+camHeight
xCamPos#=curvevalue(xCamPos#,camera position x(),4)
yCamPos#=curvevalue(yCamPos#,camera position y(),4)
zCamPos#=curvevalue(zCamPos#,camera position z(),4)
`update camera position
position camera xCamPos#,yCamPos#,zCamPos#
point camera xPos#,yPos#+camHeight,zPos#
endfunction
`-------------------------
`move the specified player
`-------------------------
function move_player(id,forward, backward, left, right)
if upkey()=1 then forward=1 :`else forward=0
if downkey()=1 then backward=1 :`else backward=0
if leftkey()=1 then left=1 :`else left=0
if rightkey()=1 then right=1 :`else right=0
`----------------------------------
`get the required object properties
`----------------------------------
xPos#=object position x(id)
yPos#=object position y(id)
zPos#=object position z(id)
yAng#=object angle y(id)
`-----------------------
`sort out basic movement
`-----------------------
`apply forward movement
if forward=1
xSpeed#(id)=xSpeed#(id)+newxvalue(0,yAng#,moveDist#(id))
zSpeed#(id)=zSpeed#(id)+newzvalue(0,yAng#,moveDist#(id))
endif
`apply backward movement
if backward=1
xSpeed#(id)=xSpeed#(id)+newxvalue(0,yAng#,moveDist#(id)*-1)
zSpeed#(id)=zSpeed#(id)+newzvalue(0,yAng#,moveDist#(id)*-1)
endif
`apply left rotation
if left=1
yrotate object id,wrapvalue(yAng#-4)
endif
`apply right rotation
if right=1
yrotate object id,wrapvalue(yAng#+4)
endif
`--------------------------------------------------
`sort out friction and other physics related things
`--------------------------------------------------
`work out value with friction
xSpeed#(id)=xSpeed#(id)*friction#(id)
ySpeed#(id)=ySpeed#(id)+gravity#(0)
zSpeed#(id)=zSpeed#(id)*friction#(id)
`work out the new position
xPos#=xPos#+xSpeed#(id)
yPos#=yPos#-ySpeed#(id)
zPos#=zPos#+zSpeed#(id)
`work out the height of the character
if yPos#< get ground height(1,xPos#,zPos#)
ySpeed#(id)=ySpeed#(id)+(yPos#-get ground height(1,xPos#,zPos#))
yPos#=get ground height(1,xPos#,zPos#)
`------------------------------------------
`player tilting
`------------------------------------------
distVal#=1
ang#=yAng#
frontX#=newxvalue(xPos#,ang#,distVal#)
frontZ#=newzvalue(zPos#,ang#,distVal#)
ang#=yAng#+180
backX#=newxvalue(xPos#,ang#,distVal#)
backZ#=newzvalue(zPos#,ang#,distVal#)
ang#=yAng#+90
leftX#=newxvalue(xPos#,ang#,distVal#)
leftZ#=newzvalue(zPos#,ang#,distVal#)
ang#=yAng#-90
rightX#=newxvalue(xPos#,ang#,distVal#)
rightZ#=newzvalue(zPos#,ang#,distVal#)
`work out the heights
frontHeight#=get ground height(1,frontX#,frontZ#)
backHeight#=get ground height(1,backX#,backZ#)
leftHeight#=get ground height(1,leftX#,leftZ#)
rightHeight#=get ground height(1,rightX#,rightZ#)
`compute tilt angles
xAng#=curveangle((backHeight#-frontHeight#)*30,object angle x(id+10),5)
zAng#=curveangle((leftHeight#-rightHeight#)*30,object angle z(id+10),5)
`update rotation
rotate object id+10,xAng#,0,zAng#
`-------------------
`slide down slopes
`-------------------
xMoveDist#=(backHeight#-frontHeight#)/30
zMoveDist#=(leftHeight#-rightHeight#)/30
`adjust momentum up/down
xSpeed#(id)=xSpeed#(id)+newxvalue(0,yAng#,xMovedist#)
zSpeed#(id)=zSpeed#(id)+newxvalue(0,yAng#,xMovedist#)
`adjust momentum left/right
xSpeed#(id)=xSpeed#(id)+newxvalue(0,yAng#-90,zMovedist#)
zSpeed#(id)=zSpeed#(id)+newxvalue(0,yAng#-90,zMovedist#)
endif
`reposition the player object
position object id,xPos#,yPos#,zPos#
endfunction
function clear()
for n=1 to 1000
if object exist(n)=1
delete object n
endif
if matrix exist(n)=1
delete matrix n
endif
if light exist(n)=1
delete light n
endif
if image exist(n)=1
delete image n
endif
next n
exitfunction
` for n=1 to 1000
`if (object exist(n)=0 and matrix exist(n)=0 and light exist(n)=0 and image exist(n)=0)then exit
` next n
endfunction
`function choose()
choose:
if world=1
`clear()
` world=2
world1()
` main()
endif
if world >1
`clear()
`world=1
world2()
`main()
endif
`endfunction
return
function world1()
sync on
sync rate 40
hide mouse
autocam off
`load the matrix
LoadMatrix("race1",1)
`set ambient light amount
set ambient light 20
`colour main light
color light 0,RGB(233,233,233)
`make a light
make light 1
set point light 1,600,200,450
color light 1,RGB(255,255,100)
for id=1 to 2
`make a temporary player object
make object cube id,1
load object "media/hovercraft.3ds",10+id
scale object 10+id,75,75,75
glue object to limb 10+id,id,0
hide limb id,0
make object collision box id,-1,0,-1,1,2,1,0
friction#(id)=0.95
moveDist#(id)=0.065
xSpeed#(id)=0
zSpeed#(id)=0
next id
`-----------------
`work out position
`-----------------
xPos1#= 143.5:xPos2#=150.5
zPos1#= 143.5:zPos2#=150.5
yPos1#=get ground height(1,xPos1#,zPos1#):yPos2#=get ground height(1,xPos2#,zPos2#)
position object 1,xPos1#,yPos1#,zPos1#
position object 2,xPos2#,yPos2#,zPos2#
xSpot#(0)=146.0:zSpot#(0)=308.7
xSpot#(1)=448.8:zSpot#(1)=308.7
xSpot#(2)=448.8:zSpot#(2)=113.8
xSpot#(3)=547.9:zSpot#(3)=113.8
xSpot#(4)=547.9:zSpot#(4)=188.7
xSpot#(5)=746.8:zSpot#(5)=188.7
xSpot#(6)=746.8:zSpot#(6)=54.3
xSpot#(7)=881.6:zSpot#(7)=54.3
xSpot#(8)=881.6:zSpot#(8)=868.1
xSpot#(9)=949.4:zSpot#(9)=868.1
xSpot#(10)=949.4:zSpot#(10)=907.6
xSpot#(11)=849.0:zSpot#(11)=912.0
xSpot#(12)=849.0:zSpot#(12)=924.0
xSpot#(13)=86.3:zSpot#(13)=928.2
xSpot#(14)=86.3:zSpot#(14)=712.5
xSpot#(15)=595.0:zSpot#(15)=712.5
xSpot#(16)=782.6:zSpot#(16)=712.5
xSpot#(17)=782.6:zSpot#(17)=250.9
xSpot#(18)=722.3:zSpot#(18)=250.9
xSpot#(19)=715.9:zSpot#(19)=564.8
xSpot#(20)=419.9:zSpot#(20)=571.5
xSpot#(21)=414.9:zSpot#(21)=628.3
xSpot#(22)=254.8:zSpot#(22)=628.3
xSpot#(23)=254.8:zSpot#(23)=575.3
xSpot#(24)=86.4:zSpot#(24)=575.3
xSpot#(25)=86.4:zSpot#(25)=494.9
xSpot#(26)=115.2:zSpot#(26)=494.9
xSpot#(27)=115.2:zSpot#(27)=352.4
xSpot#(28)=54.8:zSpot#(28)=352.4
xSpot#(29)=54.8:zSpot#(29)=33.35
xSpot#(30)=146.0:zSpot#(30)=31.3
xSpot#(31)=146.0:zSpot#(31)=72.6
endfunction
function world2()
sync on
sync rate 40
hide mouse
autocam off
`load the matrix
LoadMatrix("race1",1)
`set ambient light amount
set ambient light 20
`colour main light
color light 0,RGB(233,233,233)
`make a light
make light 1
set point light 1,600,200,450
color light 1,RGB(255,255,100)
for id=1 to 2
`make a temporary player object
make object cube id,1
load object "media/ab.x",10+id
scale object 10+id,75,75,75
glue object to limb 10+id,id,0
hide limb id,0
make object collision box id,-1,0,-1,1,2,1,0
friction#(id)=0.95
moveDist#(id)=0.065
xSpeed#(id)=0
zSpeed#(id)=0
next id
`-----------------
`work out position
`-----------------
xPos1#= 143.5:xPos2#=150.5
zPos1#= 143.5:zPos2#=150.5
yPos1#=get ground height(1,xPos1#,zPos1#):yPos2#=get ground height(1,xPos2#,zPos2#)
position object 1,xPos1#,yPos1#,zPos1#
position object 2,xPos2#,yPos2#,zPos2#
xSpot#(0)=146.0:zSpot#(0)=308.7
xSpot#(1)=448.8:zSpot#(1)=308.7
xSpot#(2)=448.8:zSpot#(2)=113.8
xSpot#(3)=547.9:zSpot#(3)=113.8
xSpot#(4)=547.9:zSpot#(4)=188.7
xSpot#(5)=746.8:zSpot#(5)=188.7
xSpot#(6)=746.8:zSpot#(6)=54.3
xSpot#(7)=881.6:zSpot#(7)=54.3
xSpot#(8)=881.6:zSpot#(8)=868.1
xSpot#(9)=949.4:zSpot#(9)=868.1
xSpot#(10)=949.4:zSpot#(10)=907.6
xSpot#(11)=849.0:zSpot#(11)=912.0
xSpot#(12)=849.0:zSpot#(12)=924.0
xSpot#(13)=86.3:zSpot#(13)=928.2
xSpot#(14)=86.3:zSpot#(14)=712.5
xSpot#(15)=595.0:zSpot#(15)=712.5
xSpot#(16)=782.6:zSpot#(16)=712.5
xSpot#(17)=782.6:zSpot#(17)=250.9
xSpot#(18)=722.3:zSpot#(18)=250.9
xSpot#(19)=715.9:zSpot#(19)=564.8
xSpot#(20)=419.9:zSpot#(20)=571.5
xSpot#(21)=414.9:zSpot#(21)=628.3
xSpot#(22)=254.8:zSpot#(22)=628.3
xSpot#(23)=254.8:zSpot#(23)=575.3
xSpot#(24)=86.4:zSpot#(24)=575.3
xSpot#(25)=86.4:zSpot#(25)=494.9
xSpot#(26)=115.2:zSpot#(26)=494.9
xSpot#(27)=115.2:zSpot#(27)=352.4
xSpot#(28)=54.8:zSpot#(28)=352.4
xSpot#(29)=54.8:zSpot#(29)=33.35
xSpot#(30)=146.0:zSpot#(30)=31.3
xSpot#(31)=146.0:zSpot#(31)=72.6
endfunction
phukol