Simple snippet to detect whether you are seen or not
no media needed
Rem Project: LineOfSight/VisibleToEnemy
Rem Created: 27/06/05
Rem by Scorpyo
Top:
Rem ***** Main Source File *****
set display mode 800,600,16
hide mouse
sync on
backdrop on
gosub Vars1
gosub Setupland1
gosub setambient
gosub makeobjects
gosub Character
set global collision off
sync rate 50
set camera range 10,landsize*2
gosub Resetcam
sync
Code:
do
gosub Playercontrol
gosub Printdata
gosub camera_controls
gosub update_camera
x#=newxvalue(x#,a#,s#)
z#=newzvalue(z#,a#,s#)
h#=get ground height(1,x#,z#)
position object 9999,x#,h#+5,z#
yrotate object 9999,a#
gosub checksight
rem Update screen
sync
loop
Setupland1:
make matrix 1,landsize,landsize,grid,grid
rem seed for matrix randomize
randomize 1
randomize matrix 1,mtxrandomize
update matrix 1
return
setambient:
rem Create fog and ambience
set ambient light 60
return
rem make and position cubes
makeobjects:
for n=1 to objnum
make object cube n,500
xpos#=rnd(landsize):zpos#=rnd(landsize)
position object n,xpos#,get ground height(1,xpos#,zpos#)+250,zpos#
objpos(n)=xpos#:objpos(n+10)=zpos#
next n
make object sphere 11,300
color object 11,rgb(255,0,0)
position object 11,landsize/2,150,landsize/2+3000
return
rem ******** VARIABLES ******
Vars1:
rem
mtxrandomize=30
landsize=10000
grid=40
rem **Player Start position**
x#=landsize/2
z#=landsize/2-3000
s#=0
rem initial cam settings
camdist=-500
camhgt=200
camrot=0
camlen=200
cx#=0
cy#=0
cz#=0
objnum=10
dim objpos(objnum*2)
return
rem ***** PLAYERCONTROL *****
Printdata:
set cursor 0,0
set text opaque
rem debug check
print "Polygons=",statistic(1)
print "Fps=",screen fps()
print "x#=",x#
print "z#=",z#
print "a#=",a#
print
print "sightcheck#=",sightcheck#
print
print a$
return
Playercontrol:
rem ****Character walk ****
if upkey()=1 and s#<12 then s#=s#+2
if downkey()=1 and s#>-12 then s#=s#-2
if leftkey()=1 then a#=wrapvalue(a#-4)
if rightkey()=1 then a#=wrapvalue(a#+4)
return
rem ****BUILD PLAYER****
rem object 9999
Character:
rem make cone
make object cone 9999,100
scale object 9999,80,100,140
rem point tip forward
xrotate object 9999,60
set object cull 9999,0
return
rem **********CAMERA*****************
camera_controls:
if inkey$()="<" then camrot2=wrapvalue(camrot2)+2
if inkey$()="z" then camdist=camdist+2
if inkey$()="x" then camdist=camdist-2
if inkey$()="b" then camrot=camrot+2
if inkey$()="n" then camrot=camrot-2
if inkey$()="c" then camhgt=camhgt+2
if inkey$()="v" then camhgt=camhgt-2
if inkey$()="m" then camlen=camlen+2
if inkey$()="," then camrot = 180
if inkey$()="." then gosub Resetcam
return
rem camera update
update_camera:
rem Position camera to the back of the character
ca#=wrapvalue(a#+camrot)
cx#=newxvalue(x#,ca#,camdist)
cz#=newzvalue(z#,ca#,camdist)
cy#=get ground height(1,x#,z#)
position camera cx#,cy#+camhgt,cz#
rem Point camera at object
point camera x#,cy#+camhgt,z#
return
rem camera reset
Resetcam:
camdist=-800
camhgt=400
camrot=0
camlen=200
return
checksight:
tox#=object position x(11)
toz#=object position z(11)
for n=1 to 10
infrontcheck#=intersect object(n,x#,50,z#,tox#,50,toz#)
if infrontcheck#>0 then sightcheck#=intersect object(11,x#,50,z#,tox#,50,toz#)
if infrontcheck#>0 and infrontcheck#<sightcheck# then a$="NOT VISIBLE":return
sightcheck#=0:a$="VISIBLE"
next n
return
end