autocam off
`make ai
global ai as integer
ai = 1
`ai state as in movement for idle,patrol,chase
dim AIState(2) as integer
`different waypoint's for the ai to move
dim WayPoint(5) as integer
`oldtimer as integer
oldtimer = 0
`make waypoint's
waypoint1 as integer
waypoint1 = 2
waypoint2 as integer
waypoint2 = 3
waypoint3 as integer
waypoint3 = 4
waypoint4 as integer
waypoint4 = 5
waypoint5 as integer
waypoint5 = 6
waypoint6 as integer
waypoint6 = 7
set display mode 1024,768,32
sync on
sync rate 60
`make light
point light 0,0,0,0
`make the ai and load there position
make object cube ai,64
position object ai,200,0,0
color object ai,rgb(0,255,0)
`my ai state as in behavior
AIState(0)=idle: AIState(1)=patrol: AIState(2)=chase
AIState(2) = AIState(2) * - 1
`my waypoint's for the ai to go to
WayPoint(0)=waypoint1:WayPoint(1)=waypoint2: WayPoint(2)=waypoint3:WayPoint(3)=waypoint4:WayPoint(4)=waypoint5:WayPoint(5)=waypoint6
WayPoint(5) = WayPoint(5) * -1
`make waypoint's
make object cube waypoint1,10
position object waypoint1,-100,250,-289
make object cube waypoint2,10
position object waypoint2,300,-400,150
make object cube waypoint3,10
position object waypoint3,200,300,-200
make object cube waypoint4,10
position object waypoint4,-800,50,900
make object cube waypoint5,10
position object waypoint5,-300,-300,-200
make object cube waypoint6,10
position object waypoint6,300,-300,-900
oldtimer = timer()
randomize timer()
position camera 0,0,-880
set camera range 0,10,-4000
do
mousex#=mousex#+(mousemovey()/0.5)
mousey#=mousey#+(mousemovex()/0.5)
rotate camera wrapvalue(mousex#),wrapvalue(mousey#),0
if timer() >= oldtimer + 20000
oldtimer = oldtimer + 1
WayPoint=0+rnd(4)
oldtimer = timer()
endif
if (inkey$()="i"=1 and AIState=0) or (inkey$()="i"=1 and AIState=1) or (inkey$()="i"=1 and AIState=2)
AIState=0
endif
if AIState=0
move object ai,0.0
endif
if (inkey$()="p"=1 and AIState=0) or (inkey$()="p"=1 and AIState=1) or (inkey$()="p"=1 and AIState=2)
AIState=1
endif
if AIState=1
move object ai,0.5
endif
if (inkey$()="c"=1 and AIState=0) or (inkey$()="c"=1 and AIState=1) or (inkey$()="c"=1 and AIState=2)
AIState=2
endif
if AIState=2
move object ai,3.1
endif
if (inkey$()="a"=1 and WayPoint=0) or (inkey$()="a"=1 and WayPoint=1)
WayPoint=0
endif
if WayPoint=0
point object ai,object position x(waypoint1),object position y(waypoint1),object position z(waypoint1)
endif
if (inkey$()="b"=1 and WayPoint=0) or (inkey$()="a"=1 and WayPoint=1)
WayPoint=1
endif
if WayPoint=1
point object ai,object position x(waypoint2),object position y(waypoint2),object position z(waypoint2)
endif
if WayPoint=2
point object ai,object position x(waypoint3),object position y(waypoint3),object position z(waypoint3)
endif
if WayPoint=3
point object ai,object position x(waypoint4),object position y(waypoint4),object position z(waypoint4)
endif
if WayPoint=4
point object ai,object position x(waypoint5),object position y(waypoint5),object position z(waypoint5)
endif
if WayPoint=5
point object ai,object position x(waypoint6),object position y(waypoint6),object position z(waypoint6)
endif
`object collision on waypoint's
if object collision(ai,waypoint1)
WayPoint=0+rnd(5)
endif
if object collision(ai,waypoint2)
WayPoint=0+rnd(5)
endif
if object collision(ai,waypoint3)
WayPoint=0+rnd(5)
endif
if object collision(ai,waypoint4)
WayPoint=0+rnd(5)
endif
if object collision(ai,waypoint5)
WayPoint=0+rnd(5)
endif
if object collision(ai,waypoint6)
WayPoint=0+rnd(5)
endif
if upkey()=1 then move camera 10
if downkey()=1 then move camera -10
set text size 32
text 300,0,"VeRsUaL's Easy to do AI Demo for Nano"
text 20,20,"fps: " + str$(screen fps())
text 20,40,"Press i,p,c to control the ai state:"
text 20,60,"a,b is used for testing"
sync
loop