Thank you for the help. Your suggestion worked very well. Is there a way to find out what face of an object the sphere is colliding with? Is there a way to make the sphere slide on tilted objects?
When you collide with the red sphere it is supposed to ask you if you want to play again. Why doesn't it do this?
Here is the new code:
start:
sync on
sync rate 0
score = 0
load image "ground.bmp",1
make object sphere 1,50
make object collision box 1,-25,-25,-25,25,25,25,0
make object sphere 10,50
make object collision box 10,-25,-25,-25,25,25,25,0
color object 10,rgb(255,0,0)
position object 10,-1000,50,-1000
make object box 26,15,5,20
make object collision box 26,-7.5,-2.5,-10,7.5,2.5,10,0
color object 26,rgb(255,0,0)
position object 26,-500,50,500
make matrix 1,10000,10000,100,100
randomize matrix 1,50
prepare matrix texture 1,1,1,1
set matrix texture 1,1,1
position matrix 1,-5000,0,-5000
make object box 2,75,75,75
position object 2,75,75,75
make object collision box 2,-37.5,-37.5,-37.5,37.5,37.5,37.5,0
make object box 3,75,75,75
position object 3,75,125,150
make object collision box 3,-37.5,-37.5,-37.5,37.5,37.5,37.5,0
make object box 4,75,75,75
position object 4,75,175,225
make object collision box 4,-37.5,-37.5,-37.5,37.5,37.5,37.5,0
make object box 5,300,50,350
position object 5,600,150,600
make object collision box 5,-150,-25,-175,150,25,175,0
make object box 6,300,50,350
position object 6,600,0,600
make object collision box 6,-150,-25,-175,150,25,175,0
make object box 7,50,300,350
position object 7,475,0,600
make object collision box 7,-25,-150,-175,25,150,175,0
make object box 8,50,300,350
position object 8,725,0,600
make object collision box 8,-25,-150,-175,25,150,175,0
make object box 9,300,300,50
position object 9,600,0,450
make object collision box 9,-175,-150,-25,175,150,25,0
for I = 11 to 20
make object box I,25,25,25
make object collision box I,-12.5,-12.5,-12.5,12.5,12.5,12.5,0
next I
make object box 21,75,75,75
position object 21,200,175,100
make object collision box 21,-37.5,-37.5,-37.5,37.5,37.5,37.5,0
make object box 22,75,75,75
position object 22,200,175,-100
make object collision box 22,-37.5,-37.5,-37.5,37.5,37.5,37.5,0
make object box 23,75,75,75
position object 23,200,175,-300
make object collision box 23,-37.5,-37.5,-37.5,37.5,37.5,37.5,0
make object box 24,75,75,75
position object 24,200,175,-500
make object collision box 24,-37.5,-37.5,-37.5,37.5,37.5,37.5,0
make object box 25,500,25,500
position object 25,200,175,-1050
make object collision box 25,-250,-17.5,-250,250,17.5,250,0
position object 11,75,250,225
position object 12,600,200,600
position object 13,800,200,600
position object 14,600,200,300
position object 15,600,200,500
position object 16,100,200,-1050
position object 17,300,200,-1050
position object 18,100,200,-900
position object 19,200,225,-500
position object 20,200,225,-100
jump = 0
do
set cursor 0,0
print "Score: ",score
Rem Get object angle
oby#= object angle y(1)
Rem allow object to respond to keypresses
if upkey()=1 then move object 1,2.5
if downkey()=1 then move object 1,-5.5
if leftkey()=1 then yrotate object 1,wrapvalue(oby#-2.5)
if rightkey()=1 then yrotate object 1,wrapvalue(oby#+2.5)
if spacekey()=1 and jump=0 then move object up 1,125 : jump = 1
obpx#= object position x(1)
obpz#= object position z(1)
obpy#= object position y(1)
if obpy# > get ground height (1,obpx#,obpz#) + 30 then obpy# = obpy# - 1 : jump = 1
if obpy# < get ground height (1,obpx#,obpz#) + 30 then obpy# = get ground height (1,obpx#,obpz#) + 30
if obpy# = get ground height (1,obpx#,obpz#) + 30 then jump=0
rem object collisions
y = get ground height (1,obpx#,obpz#) + 30
for I = 11 to 20
if object exist(I)
if object collision(1,I) then delete object I : score = score + 10
endif
next I
if object collision(1,0)
dec obpx#,get object collision x()
dec obpy#,get object collision y()
dec obpz#,get object collision z()
jump = 0
endif
Rem position object at these co-ordinates
position object 1,obpx#,obpy#,obpz#
Rem Using the newxvalue and newzvalue functions, work out a
Rem camera position based upon objects location i.e. 100 Rem world units away and slightly above.
camx#= newxvalue(obpx#,oby#-180,100)
camz#= newzvalue(obpz#,oby#-180,100)
position camera camx#,obpy#+50,camz#
rem point camera at object
point camera obpx#,obpy#,obpz#
if object collision(1,10)
set camera view 0,0,1,1
ink rgb(255,255,255),rgb(0,0,0)
cls
set cursor 400,400
print "YOU LOSE!!!"
input "play again? y/n ", d$
if d$="n" then end
if d$="y"
for I = 1 to 30
if object exist(I)
delete object I
endif
next I
delete image 1
delete matrix 1
set camera view 0,0,1024,768
goto start
endif
endif
if object collision(1,26)
set cursor 0,0
set camera view 0,0,1,1
ink rgb(255,255,255),rgb(0,0,0)
cls
set cursor 400,400
print "YOU LOSE!!!"
input "play again? y/n ", d$
if d$="n" then end
if d$="y"
for I = 1 to 30
if object exist(I)
delete object I
endif
next I
delete image 1
delete matrix 1
set camera view 0,0,1024,768
goto start
endif
endif
rem enemy box
if avoid2 = 0
point object 26,obpx#,obpy#,obpz#
move object 26,1
endif
enmx2# = object position x(26)
enmy2# = object position y(26)
enmz2# = object position z(26)
if object collision(26,0)
dec enmx2#,get object collision x()
dec enmy2#,get object collision y()
dec enmz2#,get object collision z()
avoid2 = 1
endif
if enmy2# > 500 then enmy2# = 500
if enmy2# < 200 then enmy2# = 200
position object 26,enmx2#,enmy2#,enmz2#
if avoid2 = 1
turn object right 26,145
avoid2 = 2
endif
if avoid2 = 2
move object 26,1.25
avoid2 = 0
endif
rem enemy sphere
if avoid = 0
point object 10,obpx#,0,obpz#
move object 10,2
endif
enmx# = object position x(10)
enmy# = object position y(10)
enmz# = object position z(10)
if object collision(10,0)
dec enmx#,get object collision x()
dec enmy#,get object collision y()
dec enmz#,get object collision z()
avoid = 1
endif
if enmy# > get ground height (1,enmx#,enmz#)+ 30 then enmy# = enmy# - 1
if enmy# < get ground height (1,enmx#,enmz#)+ 30 then enmy# = get ground height (1,enmx#,enmz#)+ 30
position object 10,enmx#,enmy#,enmz#
if avoid = 1
turn object right 10,145
avoid = 2
endif
if avoid = 2
move object 10,2
avoid = 0
endif
if score = 100
set camera view 0,0,1,1
ink rgb(255,255,255),rgb(0,0,0)
cls
set cursor 400,400
print "YOU WIN!!!"
input "Play again y/n? ", d$
if d$ = "y"
for I = 1 to 26
if object exist(I)
delete object I
endif
next I
for I = 1 to 2
if mesh exist (I) then delete mesh I
next I
delete image 1
delete matrix 1
set camera view 0,0,1024,768
goto start
endif
if d$="n"
end
endif
endif
rem refresh screen and loop
sync
loop