Ok, this aint quite finished yet, and it's not the smartest bot in the world but it'll do just now just as a simple enemy.
controls: mouse
in this there is a wall that you can hide behind, and there is also a marker behind you, which changes place after a short while (depending on the intelligence, which you can change), the marker is there so that if the enemy cant see you because your behind the wall then he chases the marker, then once he's got to it he'll see you, letting him chase you (I haven't made that yet because I'm gonna go to bed now, but I'll do that tomorrow)
It's besically my way of letting the enemy know that your behind the wall and give him a path to get to you, I don't really wanna go into A* and algorithms (yet), but this'll do fine.
Tomorrow I'll make it that the enemy only chases you if he can see both the marker and you.
P.S. The intelligence changes the amount of time before the marker changes place, and how far away it is. It can be changed in the source code by changing the "Intel" variable.
Title$= "Enemy A.I."
`--------------------------------------------------
`setup
sync on
sync rate 0
hide mouse
backdrop on
color backdrop 0
set camera range 1,999999999
`environment
landsize=30000
make object cube 6,landsize
create bitmap 1,50,50
set current bitmap 1
cls rgb(0,0,0)
ink rgb(0,0,255),rgb(0,0,0)
line 1,1,50,1
line 1,1,1,50
line 2,2,50,2
line 2,2,2,50
line 1,50,50,1
line 1,50,1,50
line 2,50,50,2
line 2,50,2,50
line 1,1,50,50
get image 1,0,0,50,50
set current bitmap 0
delete bitmap 1
texture object 6,1
scale object texture 6,20,20
set object 6,1,0,0,1,0
position object 6,landsize/4,landsize/2-50,landsize/4
`wall
make object box 5,500,300,50
color object 5,rgb(128,0,0)
position object 5,0,150,500
make static object 5
objx#=object position x(5)
objy#=object position y(5)
objz#=object position z(5)
objsx#=object size x(5)/2.0
objsy#=object size y(5)/2.0
objsz#=object size z(5)/2.0
make static collision box objx#-objsx#,objy#-objsy#,objz#-objsz#,objx#+objsx#,objy#+objsy#,objz#+objsz#
`create players
make object cube 1,100
make object cube 2,100
color object 1,rgb(0,255,0)
color object 2,rgb(255,0,0)
x#=0
y#=50
z#=0
ex#=1000
ey#=50
ez#=0
`create check
make object cube 3,10
`Variables
chase=0
chang=0
changm#=0
`flags
see=1
checked=0
plch=0
`modes
mode=1
`UI variables
mesx#=320
`intelligence
`1------------------------num
`Dumb-------------------Smart
intel=100
`main loop
do
`control player
oldx#=x#
oldz#=z#
if mouseclick()=1
x#=newxvalue(x#,a#,5.0)
z#=newzvalue(z#,a#,5.0)
endif
if mouseclick()=2
x#=newxvalue(x#,a#,-5.0)
z#=newzvalue(z#,a#,-5.0)
endif
if mouseclick()=0
x#=newxvalue(x#,a#,0)
z#=newzvalue(z#,a#,0)
endif
a#=wrapvalue(a#+mousemovex()*0.3)
y#=50
position object 1,x#,y#,z#
yrotate object 1,a#
s#=object size y(1)/2.0
if get static collision hit(oldx#-s#,oldy#-s#,oldz#-s#,oldx#+s#,oldy#+s#,oldz#+s#,x#-s#,y#-s#,z#-s#,x#+s#,y#+s#,z#+s#)=1
dec x#,get static collision x()
dec y#,get static collision y()
dec z#,get static collision z()
endif
position object 1,x#,y#,z#
yrotate object 1,a#
ca#=wrapvalue(curveangle(a#,ca#,30.0))
cx#=newxvalue(x#,wrapvalue(ca#+180),600)
cz#=newzvalue(z#,wrapvalue(ca#+180),600)
cy#=300.0
position camera cx#,cy#,cz#
yrotate camera wrapvalue(ca#)
point camera x#,y#,z#
inc chang
if chang>intel then chang=0
if chang<1
chx#=newxvalue(x#,wrapvalue(a#-180),intel*2)
chz#=newzvalue(z#,wrapvalue(a#-180),intel*2)
chy#=10
endif
position object 3,chx#,chy#,chz#
yrotate object 3,wrapvalue(a#)
`line of sight
if static line of sight(chx#,chy#,chz#,ex#,ey#,ez#,1,1)
see=0
else
see=1
endif
if see=0 and static line of sight(x#,y#,z#,ex#,ey#,ez#,1,1)=0
see=1
plch=1
else
plch=0
endif
`**AI**
oldex#=ex#
oldey#=ey#
oldez#=ez#
if see=1
mode=1
else
mode=2
endif
if mode=1
if plch=0
point object 2,chx#,ey#,chz#
ea#=object angle y(2)
yrotate object 2,ea#
ex#=newxvalue(ex#,ea#,2.5)
ez#=newzvalue(ez#,ea#,2.5)
else
point object 2,x#,y#,z#
ea#=object angle y(2)
yrotate object 2,ea#
ex#=newxvalue(ex#,ea#,2.5)
ez#=newzvalue(ez#,ea#,2.5)
endif
endif
if mode=2
inc changm#,1
ea#=wrapvalue(ea#-wrapvalue(cos(changm#))+wrapvalue(sin(changm#)/2))
ea#=wrapvalue(ea#+sin(cos(ea#)))
yrotate object 2,wrapvalue(ea#)
ex#=newxvalue(ex#,ea#,2.5)
ez#=newzvalue(ez#,ea#,2.5)
endif
se#=object size y(2)/2
if get static collision hit(oldex#-se#,oldey#-se#,oldez#-se#,oldex#+se#,oldey#+se#,oldez#+se#,ex#-se#,ey#-se#,ez#-se#,ex#+se#,ey#+se#,ez#+se#)=1
dec ex#,get static collision x()
dec ey#,get static collision y()
dec ez#,get static collision z()
endif
position object 2,ex#,ey#,ez#
`UI
ink rgb(255,255,255),0
text 10,10,"See flag: "+str$(see)
text 10,460,"FPS "+str$(screen FPS())
set text font "comic sans ms"
set text size 35
set text to bold
ink rgb(255,255,0),0
mes#=wrapvalue(mes#-3.0)
mesx#=cos(mes#)*50
ink rgb(255,255,0),0
center text mesx#+320,20,title$
`end loop
sync
loop
Your signature has been erased by a mod because it's larger than 600x120...