Before you read, I did not write all of these, they are just code all over the place and thought it would be nice for anyone who just wants to look in one place. Here they are.
Enemy Check Points
By, TDK
Randomize Timer()
Sync ON : Sync rate 60
AutoCam Off
DIM CowWander(4,2)
CowWander(1,1)=Rnd(500):CowWander(1,2)=Rnd(500)
CowWander(2,1)=Rnd(500):CowWander(2,2)=Rnd(500)
CowWander(3,1)=Rnd(500):CowWander(3,2)=Rnd(500)
CowWander(4,1)=Rnd(500):CowWander(4,2)=Rnd(500)
Rem 4 Flags Placed At Waypoints Using Objects 2 to 5
For N=1 To 4
Make Object Cube N+1,1
Scale Object N+1,100,400,100
Color Object N+1,RGB(255,0,0)
Position Object N+1,CowWander(N,1),1,CowWander(N,2)
rem Hide Object N+1
Next N
Make Matrix 1,500,500,50,50
Make Object Cube 1,3
position object 1,CowWander(1,1),1.5,CowWander(1,2)
NextFlag = 2
point object 1,CowWander(NextFlag,1),1.5,CowWander(NextFlag,2)
Do
CurrentFlag = Object Hit(1,0)
If CurrentFlag > 1
NextFlag = CurrentFlag+1: If NextFlag=6 Then NextFlag=2
point object 1,CowWander(NextFlag-1,1),1.5,CowWander(NextFlag-1,2)
Endif
move object 1,1
Set Camera To Follow object position x(1),1.5,object position z(1),Object Angle Y(1),10,5,50,0
Sync
Text 0,0,\"Heading For Waypoint: \"+Str$(NextFlag)
loop
Object Hit returns the number of the waypoint you bump into and you can use this number to calculate the number of the next waypoint - and thus the element of the array to get that waypoint\'s X and Z location to point the cube at.
The waypoints are objects 2, 3, 4 and 5, so if Object Hit returns a 3 then we know that the next waypoint is object 4.
The cube is object 1, so if any value greater than 1 is returned then we have reached a waypoint. If the \'NextFlag\' is 6 then it doesn\'t exist so we set it to the first waypoint which is object 2.
If you remove the Rem on line 16, the waypoints are invisible, but until you know it works, it\'s useful to be able to see them.
TDK_Man
********************************************************************
Enemy
By, Lucas W
remstart
-------------------------------------------------------------------
program name: A.I. Function
-------------------------------------------------------------------
written by: Lukas Wadenhof a.k.a n0id
date: 04 Oct. 2004
-------------------------------------------------------------------
comments: Today is 2 months to my birthday!;D (and till we (my band) plays our secound concert!!) (and that is exact count!)
This is a simple AI demo
If I knew slide collision, I would use that, but I dont know it,
so I had to use this bad, sucky, but easy Static collision type thing.
Total Lines: 175
Time Spent: about 5-6 hours.. (yes, I suck at programming, I allready know that :) )
This was written in dbc 1.13
-------------------------------------------------------------------
remend
_total = 10 : ` total enemies
bullet = 16 : ` bullet object number
rem AI arrays
dim _AI(0) :` object number to start counting AI objects from
dim _Pos#( _total , 3 ) :` A.I. position x, y, z
dim _View_Distance( _total , 2) :` A.I view and hear distance
dim _Distance#( _total ) :` A.I. distance check
dim _State$( _total ) :` A.I. state
dim _Timer( _total, 2 ) :` A.I. timer
rem Other nescesary arrays for function to work properly.
dim _Player_Lives(0) :` Player life
dim _player(0) :` player object
rem VARIABLES
_AI(0) = 500 :` start counting AI objects from 500 and up
_Player_Lives(0) = 200 :` player lives
_Player(0) = 1 :` player object
` _______________________________________________________________________
set display mode 640,480,16 :` you can change this command, I like to use 1024x768
sync on : sync rate 0 : hide mouse : randomize timer : set normalization on : autocam off :` this is just for setting up the demo
` _______________________________________________________________________
` make ai objects
for x = 1 to _total
make object cube x+_AI(0), 25
set object rotation zyx x+_AI(0)
position object x+_AI(0) , rnd(1000) , 12.5 , rnd(1000)
yrotate object x+_AI(0), rnd(359)
_State$(x) = \"idle\"
_View_Distance( x , 1) = 400 :` seeing range
_View_Distance( x , 2) = 50 :` hearing range
next x
` ----------------- this is nothing important. (it makes a cone that displays where the AI is looking)
for x = 1 to _total
id = (x+_AI(0)) +100
make object cone id, 100 : scale object id, 100, 100, 100 : rotate object id, 90, 180, 0 : fix object pivot id : ghost object on id
next x
` -----------------
` _______________________________________________________________________
` make player
make object box _player(0),25,50,25
` _______________________________________________________________________
` make room and boxes
make object box 5, 1000,10,1000 : position object 5,500,-10,500 : color object 5,rgb(64,64,64)
make object box 6, 1000,250,10 : position object 6,500,75,0 : color object 6,rgb(64,64,64)
make object box 7, 10,250,1000 : position object 7,0,75,500 : color object 7,rgb(64,64,64)
make object box 8, 10,250,1000 : position object 8,1000,75,500 : color object 8,rgb(64,64,64)
make object box 9, 1000,250,10 : position object 9,500,75,1000 : color object 9,rgb(64,64,64)
` and make some boxes inside scene that AI can collide with
for x = 10 to 15
make object box x, 50+rnd(50),50+rnd(50),50+rnd(50)
position object x, rnd(1000), 0+(object size y(x)/2), rnd(1000)
color object x, rgb(rnd(255) , rnd(255) , rnd(255))
next x
` _______________________________________________________________________
do
rem Print some info
ink 0,0 :text 0,0, \"fps: \"+str$( screen fps() )
ink 0,0 :text 0,15, \"polys: \"+str$( statistic(1) )
ink 255,0: text 0,45, \"life: \"+str$( _Player_Lives(0) )
ink rgb(255,255,255), 0
rem Handle Player Movement
if upkey() =1 then x#=newxvalue(x#, cya#, 10):z#=newzvalue(z#, cya#, 10)
if downkey() =1 then x#=newxvalue(x#, cya#, -10):z#=newzvalue(z#, cya#, -10)
if leftkey() =1 then x#=newxvalue(x#, cya#-90, 10):z#=newzvalue(z#, cya#-90, 10)
if rightkey()=1 then x#=newxvalue(x#, cya#+90, 10):z#=newzvalue(z#, cya#+90, 10)
position camera x#, 25, z#
position object _player(0), x#, 25, z#
cya#=wrapvalue(cya#+mousemovex()/3)
cxa#=wrapvalue(cxa#+mousemovey()/3)
rotate camera cxa#,cya#,0
rotate object _player(0), 0, cya#, 0
rem HANDLE AI
for x = 1 to _total : Handle_AI(x) : next x
rem fire
Fire_bullet( _total, bullet )
rem Color backdrop
color backdrop rgb(64, 95, 64)
` ----------------- this is nothing important. (This displays where AI is looking)
for x = 1 to _total
id = (x+_AI(0)) +100
position object id, object position x(id-100), object position y(id-100), object position z(id-100)
rotate object id, object angle x(id-100), object angle y(id-100), object angle z(id-100)
move object id, 50
next x
` -----------------
sync
loop
` _______________________________________________________________________
` FUNCTIONS
function Handle_AI( id )
` get object number
id2 = id+_AI(0)
` get ai position
_Pos#(id , 1 ) = object position x( id2 )
_Pos#(id , 2 ) = object position y( id2 )
_Pos#(id , 3 ) = object position z( id2 )
` get camera position
camx# = camera position x()
camy# = camera position y()
camz# = camera position z()
` get distance
_Distance#(id) = sqrt( (camx#-_Pos#(id , 1 ))^2 + (camz#-_Pos#(id , 3 ))^2 )
if _State$(id)<>\"attack\" and _State$(id)<>\"die\"
` Check if AI see player
if (_Distance#(id) < _View_Distance( id , 1)) and AI_See_Me(id2)=1 then _State$(id)=\"goto\"
` Check if AI hear player
if _distance#(id) < _View_Distance( id , 2) then _State$(id)=\"goto\"
` Check if AI is idle
if (_Distance#(id) > _View_Distance( id , 2)) and (_Distance#(id) > _View_Distance( id , 1)) then _State$(id)=\"idle\"
endif
if _State$(id)=\"goto\"
Move_AI( id , 2.5 , 1)
color object id2, rgb( 0, 0, 255 )
if _Distance#(id) < 50 then _State$(id) = \"attack\"
endif
if _State$(id)=\"idle\"
Move_AI( id , 0.0 , 0)
color object id2, rgb( 255, 255, 255 )
_Timer(id, 1) = _Timer(id, 1) + 1
if _Timer(id, 1) > 20+rnd(300) then _Timer(id, 1)=0:_State$(id)=\"move around\"
endif
if _state$(id)=\"attack\"
Move_AI( id , 0.0 , 1)
color object id2, rgb( 255, 0, 0 )
_Timer(id, 1) = _Timer(id, 1) + 1
if _Timer(id, 1) > 10
_Player_Lives(0)=_Player_Lives(0)-5+rnd(5)
_Timer(id, 1)=0
_state$(id)=\"goto\"
endif
endif
if _state$(id)=\"die\"
color object id2, rgb(255,255,255) : ghost object on id2
Move_AI( id , 0.0 , 0)
_Timer( id, 1 ) = _Timer( id, 1 ) + 5
_Timer( id, 2 ) = _Timer( id, 1 ) * -1
color object id2, rgb(_Timer( id, 2 ), _Timer( id, 2 ), _Timer( id, 2 ))
if _Timer( id, 1 ) > 255
ghost object off id2 : position object id2 , rnd(1000) , 12.5 , rnd(1000) : yrotate object id2, rnd(359)
_state$(id)=\"idle\" : _Timer( id, 1 ) = 0
endif
endif
if _State$(id)=\"move around\"
color object id2, rgb(0,255,0)
Move_AI( id, 2.5, 0)
_Timer( id, 1 ) = _Timer( id, 1 ) + 1
_Timer( id, 2 ) = _Timer( id, 2 ) + 1
if _Timer( id, 1 ) > 100+rnd(50)
yrotate object id2, rnd(359)
endif
_Timer( id, 2 ) = _Timer( id, 2 ) + 1
if _Timer( id, 2 ) > 200+rnd(500)
_State$(id)=\"idle\"
_Timer(id, 1)=0 : _Timer(id, 2)=0
endif
endif
if object in screen(id2) then text object screen x(id2), object screen y(id2)-(object size(id2)), _state$(id)
endfunction
function Move_AI( id , speed#, check)
id2 = id+_AI(0)
oldx# = object position x(id2)
oldy# = object position y(id2)
oldz# = object position z(id2)
move object id2, speed#
if check=1 then point object id2, camera position x() , 12.5 , camera position z()
x# = object position x(id2)
y# = object position y(id2)
z# = object position z(id2)
collide = Check_AI_Collision(id2,0)
if collide > 0
x# = oldx#
z# = oldz#
endif
position object id2, x# , y# , z#
endfunction
function Fire_Bullet(total,bullet)
if mouseclick() > 0
make object box bullet,10,10,50000
color object bullet, rgb(128,128,0)
yrotate object bullet, camera angle y()
position object bullet, camera position x(), camera position y() - 10, camera position z()
for x = 1 to total
if object collision(bullet,x+_AI(0))
_state$(x) = \"die\"
endif
next x
sync
delete object bullet
endif
endfunction
function Check_AI_Collision(id1, id2)
if object collision(id1,id2)>0 then exitfunction 1
endfunction 0
function AI_See_Me(id)
oldx# = camera position x() : oldy# = camera position y() : oldz# = camera position z()
oldax# = camera angle x() : olday# = camera angle y() : oldaz# = camera angle z()
position camera _Pos#(id-_AI(0) , 1 ), _Pos#(id-_AI(0) , 2 ), _Pos#(id-_AI(0) , 3 )
rotate camera object angle x(id), object angle y(id), object angle z(id)
if object in screen(_Player(0))
position camera oldx#, oldy#, oldz#
rotate camera oldax#, olday#, oldaz#
exitfunction 1
endif
position camera oldx#, oldy#, oldz#
rotate camera oldax#, olday#, oldaz#
endfunction 0
********************************************************************
So far that is all there is now. Please post your own AI tutorials, remember if I wrote these, my name would be under the title. I will be updating this thread.
Drew G
Free Ipod
http://ipods.freepay.com/?r=24268699