Looking at your example Agent, I feel like mine is a little long winded and overly complicated, but here is my code anyway
//******************************************************************
// Bee Tut.
//******************************************************************
// http://forum.thegamecreators.com/?m=forum_view&t=184136&b=7
//
// I'm far from a n00b, but was at a loose end and thought I'd
// give this a go.
// As an aside, I'm writing this on a Clean install of DBP without
// using ANY plugins
// Start : 201104171149
// Finish: 201104171447
//******************************************************************
//******************************************************************
//
// System stuff
//
//******************************************************************
` ordinarily I'd put this in a separate source and Gosub to the init
` bit, but Gosub is forbidden in this project.
` disable the autocam
autocam off
` screen updates to manual and cap the fps to 60
sync on
sync rate 60
` stop closing the window stuff
set window on
set window layout 0,1,0
disable escapekey
//******************************************************************
//
// Variables
//
//******************************************************************
//******************************************************************
// Constants
//******************************************************************
#constant true 1
#constant false 0
#constant maxBees 100 : ` the number of Bees generated
` constants for findFreeMedia() function
#constant findObj 0
#constant findImg 1
#constant findSfx 2
#constant findMus 3
//******************************************************************
// Types
//******************************************************************
type tCharacter
objNo as integer : ` object number of bee
dist# as float : ` how far it's travelled
maxDist# as float : ` how far it will travel before changing
xPos# as float : ` position in 3d space
yPos# as float
zPos# as float
xAng# as float : ` orientation in 3d space
yAng# as float
zAng# as float
endtype
type tBGObjects
objNo as integer
imgNo as integer
endtype
//******************************************************************
// Dimmed arrays
//******************************************************************
dim bees(maxBees-1) as tCharacter
dim bgObjects(1) as tbgObjects
dim sounds(2) : ` id's for sound files
dim music(0)
//******************************************************************
// Assign Values
//******************************************************************
//******************************************************************
//
// Init Media
//
//******************************************************************
` make some bees
for a=0 to maxBees-1
` find object No
bees(a).objNo=findFreeMedia(findObj)
` make a cube
make object cube bees(a).objNo,1
` randomize the co'ords
bees(a).xPos#=-25+rnd(50)
bees(a).yPos#=-25+rnd(50)
bees(a).zPos#=-25+rnd(50)
bees(a).xAng#=rnd(359)
bees(a).yAng#=rnd(359)
bees(a).zAng#=rnd(359)
bees(a).maxDist#=rnd(25)
position object bees(a).objNo,bees(a).xPos#,bees(a).yPos#,bees(a).zPos#
rotate object bees(a).objNo,bees(a).xAng#,bees(a).yAng#,bees(a).zAng#
next a
` make bg image
bgObjects(0).objNo=findFreeMedia(findObj)
make object plane bgObjects(0).objNo,640,480
position object bgObjects(0).objNo,0,0,200
bgObjects(0).imgNo=findFreeMedia(findImg)
load image "files/beeBG.png",bgObjects(0).imgNo,1
texture object bgObjects(0).objNo,bgObjects(0).imgNo
` make hidey image
bgObjects(1).objNo=findFreeMedia(findObj)
make object plane bgObjects(1).objNo,25,150
position object bgObjects(1).objNo,-100,20,-50
bgObjects(1).imgNo=findFreeMedia(findImg)
load image "files/tree.png",bgObjects(1).imgNo,1
texture object bgObjects(1).objNo,bgObjects(1).imgNo
` position the camera
position camera 0,0,0,-200
point camera 0,0,0,0
` loads the sounds and music
sounds(0)=findFreeMedia(findSfx)
load sound "files/sound1.wav",sounds(0)
sounds(1)=findFreeMedia(findSfx)
load sound "files/sound2.wav",sounds(1)
sounds(2)=findFreeMedia(findSfx)
load sound "files/sound3.wav",sounds(2)
` loads the music
music(0)=findFreeMedia(findMus)
load music "files/music.mp3",music(0)
//******************************************************************
//
// Main Loop
//
//******************************************************************
do
pick screen mouseX(),mouseY(),250
mx=get pick vector x()
my=get pick vector y()
` move the bees
moveBees(mx,my)
` mouse click sound play bit
if mouseclick()<>0
playSound()
endif
` checks music is playing
checkMusic()
` draw debug
text 0,0,"Agent's Bee Challenge - By =PRoF="
text 0,40,"FPS: "+str$(screen fps())
text 0,60,"Polys: "+str$(statistic(1))
` update screen
sync
` check for exit condition (F1 pressed)
if keystate(59)=true
exit
endif
loop
` erase media
for a=1 to 1000
if object exist(a) then delete object a
if sound exist(a) then delete sound a
if music exist(a) then delete music a
if image exist(a) then delete image a
next a
end
//******************************************************************
//
// End of code - Avast! 'Ere be functions
//
//******************************************************************
//******************************************************************
// findFreeObject - Small kludge to replace IanM's funcs. in Matrix1
//******************************************************************
function findFreeMedia(mediaType as integer)
local count as integer : count=0
local condition as integer : condition=0
repeat
inc count
select mediaType
case 0 : ` object
if object exist(count)=false
condition=true
endif
endcase
case 1 : ` image
if image exist(count)=false
condition=true
endif
endcase
case 2 : ` sound
if sound exist(count)=false
condition=true
endif
endcase
case 3 : ` muisc
if music exist(count)=false
condition=true
endif
endcase
endselect
until condition=true
endfunction count
//******************************************************************
// Move bee's
//******************************************************************
function moveBees(mx,my)
for a=0 to maxBees-1
move object bees(a).objNo,1
inc bees(a).dist#
dist#=distCheck(bees(a).objNo,mx,my,0)
if dist#>(50*50)
bees(a).dist#=0
bees(a).maxDist#=25+rnd(25)
point object bees(a).objNo,mx,my,0
`rotate object bees(a).objNo,bees(a).xAng#,bees(a).yAng#,bees(a).zAng#
endif
if bees(a).dist#>bees(a).maxDist#
bees(a).dist#=0
bees(a).maxDist#=rnd(25)
bees(a).xAng#=rnd(359)
bees(a).yAng#=rnd(359)
bees(a).zAng#=rnd(359)
rotate object bees(a).objNo,bees(a).xAng#,bees(a).yAng#,bees(a).zAng#
endif
next a
endfunction
//******************************************************************
// distCheck()
//******************************************************************
function distCheck(objNo1 as integer, x# as float,y# as float,z# as float)
` find delta's
dx# = object position x(objNo1) - x#
dy# = object position y(objNo1) - y#
dz# = object position z(objNo1) - z#
` square the delta's
dx# = dx# * dx#
dy# = dy# * dy#
dz# = dz# * dz#
Dist# = dx# + dy# + dz#
endfunction Dist#
//******************************************************************
// playSound()
//******************************************************************
function playSound()
if sound playing(sounds(0))=false and sound playing(sounds(1))=false and sound playing(sounds(2))=false
newSound=rnd(2)
play sound sounds(newSound)
endif
endfunction
//******************************************************************
// checkMusic()
//******************************************************************
function checkMusic()
if music playing(music(0))=false
play music music(0)
endif
endfunction
P.S.
Please note how I am using a UDT, and my Bee's
do move in 3D
lol