you could use an intersect object routine to check distance from map and trigger death when so close to hit it
REM Project: Astro
REM Created: 4/25/2008 8:14:21 PM
REM
REM ***** Main Source File *****
REM
Rem Set up sync etc
Sync On
Sync Rate 30
Autocam Off
Hide Mouse
Rem Load things
Gosub LoadImages
Gosub LoadShip
Gosub LoadBullet
Gosub LoadFog
Gosub LoadLevel
Gosub LoadSky
Gosub LoadSound
Gosub LoadVariables
Gosub LoadExplosion
Gosub LoadAnimation
Gosub LoadEnemy
Gosub LoadEnemyBullet
Gosub LoadLight
Gosub MakeCamera
Rem Go to main menu
Gosub MainMenu
Rem Set up sky and fog
LoadFog:
Fog on
Fog distance 4000
Fog color RGB(150,150,150)
Return
Rem Make spaceship
LoadShip:
Load Object "SPCVEH11.X",1
Scale object 1,1,1,1
rem make aim sphere:
make object sphere 100,5
Return
PositionObjects:
Rem Position objects
Position object 1,0,1000,0
Hide object 2
Hide object 3
Position object 4,1000,150,1000
Hide object 5
T# = 5
M = 1
shoot = 1
Show object 4
Goto Main
Rem Make bullet
LoadBullet:
Load Object "BULLET1.X",2
Scale Object 2,50000,50000,50000
Rotate object 2,90,0,0
Fix object pivot 2
Hide object 2
Return
Rem Make matrix
LoadLevel:
Make Matrix 1,5000,5000,20,20
Load image "grass08.bmp",1
Prepare matrix texture 1,1,1,1
Fill matrix 1,1,1
Randomize Matrix 1,100
Position matrix 1,0,0,0
Backdrop on
Load object "valley.x",10
Scale object 10,500,500,500
Position object 10,0,100,0
Texture object 10,1
Return
Rem Make skybox
LoadSky:
Load object "set 16/skybox.x",9
Set object 9,1,1,0,0,0
Scale object 9,70000,70000,70000
Return
Rem Load music/sound
LoadSound:
Load music "SphereinSpace.mid",1
Load sound "explode4.wav",1
Load music "Shady Valley.mid",2
Return
LoadVariables:
Rem Set timer to 5
T# = 5
Rem Set mobility to true
M = 1
Rem Set enemy shooting to true
shoot = 1
Return
LoadExplosion:
Rem Load explosion
Load object "explode.x",3
Hide object 3
Return
LoadAnimation:
Rem Load animation
Load animation "failed1.avi",1
Return
LoadEnemy:
Rem Make enemy spaceships
Load object "SPCSHIP.X",4
Scale object 4,500,1000,500
Rotate object 4,90,0,0
Fix object pivot 4
Return
LoadEnemyBullet:
Rem Make enemy bullet
Load object "BULLET2.X",5
Scale object 5,50000,50000,50000
Rotate object 5,90,10,0
Fix object pivot 5
Hide object 5
Return
MakeCamera:
Rem Make camera object
Make object sphere 6,10
Return
LoadCamera:
Rem Settings for camera
Delete image 3
Set camera range 1,1000000
Set camera view 0,0,640,480
Goto PositionObjects
LoadImages:
Rem Load menu images
Load image "stars.bmp",2
Return
LoadLight:
Set ambient light 50
Make light 1
Set point light 1,0,100,0
Return
Main:
Do
set cursor 0,0
print "distance= ",distance#
Rem Store object angle y in aY#
aY# = Object Angle Y(1)
aX# = Object Angle X(1)
Rem Start timer
If T# > 0 then Dec T#
Rem Store old position values for player
OX# = Object position X(1)
OY# = Object position Y(1)
OZ# = Object position Z(1)
Rem Control input for player
If Y# > 5000 then Position Object 1,X#,4950,Z#
If Z# > 7000 then Position Object 1,X#,Y#,Z#-10
If X# > 7000 then Position Object 1,X#-10,Y#,Z#
If Z# < 0 then Position Object 1,X#,Y#,Z#+10
If X# < 0 then Position Object 1,X#+10,Y#,Z#
G# = Get ground height(1,X#,Z#)
If Y# <= G#
If T# = 0
Gosub Dead
Endif
Endif
If Shiftkey() = 1
If M = 1
Move object 1,10
Move camera 10
Endif
Endif
If Leftkey() = 1
If M = 1
Turn object left 1,1
Endif
Endif
If Rightkey() = 1
If M = 1
Turn object right 1,1
Endif
Endif
If Upkey() = 1
If M = 1
Pitch object down 1,1
Endif
Endif
If Downkey() = 1
If M = 1
Pitch object up 1,1
Endif
Endif
Rem Get player object position and store in X# and Z#
X# = Object Position X(1)
Z# = Object Position Z(1)
Y# = Object Position Y(1)
Rem Get back position of object for camera
Pitch object down 1,11
Move object 1,-50
Position object 6,Object position X(1),Object position Y(1),Object position Z(1)
Move object 1,50
Pitch object up 1,11
Rem Place camera and set orientation to object
Position camera Object position X(6),Object position Y(6),Object position Z(6)
Set camera to object orientation 1
Rem Shoot bullet
If Controlkey() = 1 and b = 0 and M = 1 and Object exist(19) = 0
Instance object 19,2
Position Object 19,X#,Y#,Z#
Rotate object 19,90,0,0
Fix object pivot 19
Set object to camera orientation 19
Show Object 19
Scale object 19,50000,50000,50000
bulletlife = 50
b = 25
Endif
If Controlkey() = 1 and b = 0 and M = 1 and Object exist(20) = 0 and Object exist(19) = 1
Instance object 20,2
Position object 20,X#,Y#,Z#
Rotate object 20,90,0,0
Fix object pivot 20
Set object to camera orientation 20
Show object 20
Scale object 20,50000,50000,50000
bulletlife2 = 50
b = 25
Endif
If bulletlife > 0
Dec bulletlife
Move Object 19,20
If bulletlife = 0
Delete object 19
Endif
Endif
If bulletlife2 > 0
Dec bulletlife2
Move object 20,20
If bulletlife2 = 0
Delete object 20
Endif
Endif
If b > 0 then Dec b
If object exist(19)
bX# = Object position X(19)
bY# = Object position Y(19)
bZ# = Object position Z(19)
Endif
If object exist(20)
b2X# = Object position X(20)
b2Y# = Object position Y(20)
b2Z# = Object position Z(20)
Endif
Rem Control enemy spaceship
Point object 4,X#,Y#,Z#
If enemybulletlife = 0 and RND(2) = 1 and shoot = 1
Position object 5,eX#,eY#,eZ#
Set object to object orientation 5,4
Show object 5
enemybulletlife = 25
Endif
If enemybulletlife > 0
Dec enemybulletlife
Move object 5,20
If enemybulletlife = 0
Hide object 5
Position object 5,-100,0,-100
Endif
Endif
Rem Detect collisions
eX# = Object position X(4)
eY# = Object position Y(4)
eZ# = Object position Z(4)
ebX# = Object position X(5)
ebY# = Object position Y(5)
ebZ# = Object position Z(5)
If Sqrt((X#-ebX#)^2 + (Y#-ebY#)^2 + (Z#-ebZ#)^2) < 20
Gosub Dead
Endif
If object exist(19)
If Sqrt((eX#-bX#)^2 + (eY#-bY#)^2 + (eZ#-bZ#)^2) < 20
Gosub EnemyDead
Endif
Endif
If object exist(20)
If Sqrt((eX#-b2X#)^2 + (eY#-b2Y#)^2 + (eZ#-b2Z#)^2) < 20
Gosub EnemyDead
Endif
Endif
rem intersect object collision
rem calculate aim coords
frontx#=newxvalue(x#,ay#,1000)
frontz#=newzvalue(z#,ay#,1000)
fronth#=y#+sin(ax#)*-1000
rem put aim sphere for visual purpose only, not mandatory
position object 100,frontx#,fronth#,frontz#
distance#=intersect object(10,x#,y#,z#,frontx#,fronth#,frontz#)
if distance#>0 and distance#<10 then gosub dead
remstart
Set object collision to polygons 10
Set object collision to spheres 1
If object hit(1,10) = 1
Gosub Dead
Endif
remend
Rem Hide explosion
If object playing(3) = 0 then hide object 3
Rem Move skybox
Position object 9,X#,Y#,Z#
Rem Refresh screen
Sync
Loop
Dead:
Load animation "failed1.avi",1
Play sound 1
Rem Move explosion to player
Position object 3,X#,Y#,Z#
Show object 3
Play object 3
Rem Hide player
Hide object 1
Position object 1,X#,Y#+10,Z#
Rem Prevent movement
M = 0
Rem Start timer to show animations
Time = 60
If Time > 0
Do
Dec Time
Sync
If Time = 0 then exit
Loop
Endif
If Time = 0
Time = 60
Rem Reset everything
Show object 1
Position object 1,100,150,100
Rotate object 1,0,0,0
M = 1
Place animation 1,0,0,640,480
Play animation 1
If Time > 0
Do
Dec Time
Sync
If Time = 0 then exit
Loop
Endif
Stop animation 1
Delete animation 1
Goto MainMenu
Endif
EnemyDead:
Play sound 1
Rem Move explosion to enemy
Position object 3,eX#,eY#,eZ#
Show object 3
Play object 3
Rem Hide enemy
Hide object 4
shoot = 0
Position object 4,-2000,0,-2000
Return
MainMenu:
Rem Place background
Load image "title.bmp",3
Paste image 2,0,0
Paste image 2,256,0
Paste image 2,0,256
Paste image 2,256,256
Paste image 2,512,0
Paste image 2,512,256
Paste image 3,150,100
blue = RGB(0,128,255)
white = RGB(255,255,255)
selecteditem = 1
if music looping(1) = 1 then stop music 1
set camera view 0,0,1,1
Do
loop music 2
Rem Print text
If selecteditem = 1 then ink blue,0 else ink white,0
Text 200,300,"Start"
If selecteditem = 2 then ink blue,0 else ink white,0
Text 285,300,"Secret"
If selecteditem = 3 then ink blue,0 else ink white,0
Text 385,300,"Exit"
Rem Select menu items
If leftkey() = 1 and hold = 0 then dec selecteditem : hold = 1
If rightkey() = 1 and hold = 0 then inc selecteditem : hold = 1
If leftkey() = 0 and rightkey() = 0 then hold = 0
If selecteditem > 3 then selecteditem = 1
If selecteditem < 1 then selecteditem = 3
Rem Choose what to do when an item is selected
If returnkey() = 1
Rem Play game
If selecteditem = 1 then stop music 2 : loop music 1 : goto LoadCamera
Rem Quit game
If selecteditem = 3 then end
Endif
Sync
Loop