ruccus, there is no media. you can just copy paste it into db and run
here is the dbp version. i had to change the variable "point" to "pnt" because dbp won't allow point as a var name
`-------------------------------------------------
title$ = "Rocky the dog-bot V1.0"
`-------------------------------------------------
`Change Rocky's laziness here...
`----
laziness=2
`----
`(1: Not lazy, 2: Kinda lazy, 3: Very lazy)
`setup
sync on
sync rate 0
autocam off
hide mouse
set camera range 1,999999
backdrop on
color backdrop rgb(0,0,255)
`----------------------
`Arrays
dim aimode(3)
dim food(10)
`----------------------
`Players
objid=1
objai=2
seeobj=3
foodobj=4
make object cone objid,300
make object cone objai,300
xrotate object objid,180
fix object pivot objid
xrotate object objai,90
fix object pivot objai
color object objid,rgb(0,255,0)
color object objai,rgb(255,0,0)
make object plain seeobj,5,5 : hide object seeobj
make object plain foodobj,5,5 : hide object foodobj
x#=5000
y#=50
z#=5000
aix#=0
aiy#=50
aiz#=0
`----------------------
`Environment
make object plain 6,10000,10000
xrotate object 6,90 : fix object pivot 6
create bitmap 1,50,50
set current bitmap 1
cls rgb(0,0,0)
ink rgb(255,255,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
get image 1,0,0,50,50
set current bitmap 0
delete bitmap 1
texture object 6,1
scale object texture 6,40,40
position object 6,5000,-200,5000
`create food for bot
make object cube 7,200
scale object 7,50,500,50
color object 7,rgb(128,0,40)
fhx#=6000
fhz#=6000
position object 7,fhx#,200,fhz#
make object sphere 8,800
color object 8,rgb(0,128,0)
position object 8,fhx#,500,fhz#
`----------------------
`Variables
spd#=7.0
aispd#=spd#-1.0
inf#=-60
txch#=0.0
`--AI mode - 1: chase, 2: wander, 3: bored, 4: hungry
aimode=2
`timers
bottime=1
chasetime=1
wandertime=1
boretime=1
`hunger - rocky's a dog, dogs get hungry
hunger#=0
hungry=0
`change mode time
if laziness=1
changetime=3000
endif
if laziness=2
changetime=1000
endif
if laziness=3
changetime=600
endif
`number of points (wander mode)
pnt=1
tp1x#=100
tp1z#=100
tp2x#=5000
tp2z#=2000
tp3x#=2000
tp3z#=5000
tp4x#=8000
tp4z#=8000
tp5x#=9000
tp5z#=4000
`----------------------
`Main Loop>>
`----------------------
DO
`----------------------
`Control player
if keystate(200)=1
x#=newxvalue(x#,a#,spd#)
z#=newzvalue(z#,a#,spd#)
endif
if keystate(208)=1
x#=newxvalue(x#,a#,0-spd#)
z#=newzvalue(z#,a#,0-spd#)
endif
if keystate(203)=1
a#=curveangle(wrapvalue(a# - 3.0),a#,5.0)
endif
if keystate(205)=1
a#=curveangle(wrapvalue(a# + 3.0),a#,5.0)
endif
`Update positions
y#=50
position object objid,x#,y#,z#
rotate object objid,0,a#,0
`Camera
ca#=curveangle(a#,ca#,100.0)
cx#=newxvalue(x#,ca#,-1300)
cy#=y#+500
cz#=newzvalue(z#,ca#,-1300)
position camera cx#,cy#,cz#
yrotate camera wrapvalue(ca#)
`-------------------------------------
`=-A.I.-=
`old positions
oldaix#=aix#
oldaiz#=aiz#
`position seeing object at bot
aiy#=50
position object objai,aix#,aiy#,aiz#
position object seeobj,aix#,aiy#,aiz#
position object foodobj,aix#,aiy#,aiz#
`timers
if aimode=4 then inc hunger#,0.05
if aimode=3 then chasetime=1 : inc boretime : inc hunger#,0.05
if aimode=2 then chasetime=1 : inc wandertime : inc hunger#,0.005
if aimode=1 then wandertime=1 : inc chasetime : inc hunger#,0.005
if wandertime>changetime then aimode=3 : wandertime=0
if chasetime>changetime and dist#>1000 then aimode=2 : aiang#=wrapvalue(aiang#+180) : chasetime=0
if boretime>changetime then aimode=2 : boretime=0
if hunger#>99 and aimode=1 then aimode=4
if hunger#>99 and aimode=2 then aimode=4
if hunger#>99 and aimode=3 then aimode=4
if hunger#>98
aimode=4
hunger#=100
endif
if hunger#>98
hungry=1
endif
if hungry=1 then aimode=4
if hungry=1 and aimode<4 then aimode=4
if aimode<f and hunger#>99 then hungry=1 : aimode=4
if aimode=1 and dist#>3100 then aimode=2
if aimode=1 and dist#>3100 and hunger#>99 then aimode=4 : hungry=1
`point eye at player
point object seeobj,x#,y#,z#
aiang#=object angle y(objai)
eyeang#=object angle y(seeobj)
if aiang#>eyeang# then see#=wrapvalue(aiang#-eyeang#)
if aiang#<eyeang# then see#=wrapvalue(eyeang#-aiang#)
if aiang#=eyeang# then see#=0
`point eye at food
fhx#=object position x(7)
fhz#=object position z(7)
point object foodobj,fhx#,50,fhz#
foodang#=object angle y(foodobj)
`get distance
dist#=sqrt((aix#-x#)^2+(aiy#-y#)^2+(aiz#-z#)^2)
`if distance is less than 4000
if dist#<3100
`...and bot can see player
if see#<90
`set ai to "chase"
see=1
aimode=1
`otheriwse
else
`set ai to wander
see=0
aimode=2
`end
endif
endif
`If bot is set to chase
if aimode=2
`point bot at player
aiang#=curveangle(eyeang#,aiang#,700.0)
`and move
aix#=newxvalue(aix#,aiang#,aispd#)
aiz#=newzvalue(aiz#,aiang#,aispd#)
`end
endif
`If bot is set to wander
if aimode=1
`change points
if pnt=1
point object objai,tp1x#,50,tp1z#
if aix#>tp1x#-25 and aix#<tp1x#+25
if aiz#>tp1z#-25 and aiz#<tp1z#+25
pnt=2
endif
endif
if see=1 then pnt=6
endif
if pnt=2
point object objai,tp2x#,50,tp2z#
if aix#>tp2x#-25 and aix#<tp2x#+25
if aiz#>tp2z#-25 and aiz#<tp2z#+25
pnt=3
endif
endif
if see=1 then pnt=6
endif
if pnt=3
point object objai,tp3x#,50,tp3z#
if aix#>tp3x#-25 and aix#<tp3x#+25
if aiz#>tp3z#-25 and aiz#<tp3z#+25
pnt=4
endif
endif
if see=1 then pnt=6
endif
if pnt=4
point object objai,tp4x#,50,tp4z#
if aix#>tp4x#-25 and aix#<tp4x#+25
if aiz#>tp4z#-25 and aiz#<tp4z#+25
pnt=5
endif
endif
if see=1 then pnt=6
endif
if pnt=5
point object objai,tp5x#,50,tp5z#
if aix#>tp5x#-25 and aix#<tp5x#+25
if aiz#>tp5z#-25 and aiz#<tp5z#+25
pnt=1
endif
endif
if see=1 then pnt=6
endif
`switch modes
if pnt=6 then aimode=1 : point object objai,x#,50,z#
`and rotate bot
aiang#=object angle y(objai)
`move bot
move object objai,aispd#
aix#=object position x(objai)
aiz#=object position z(objai)
`end
endif
`if bot gets bored
if aimode=3
`position bot where it is
aix#=oldaix#
aiz#=oldaiz#
position object objai,aix#,50,aiz#
`end
endif
`if bot gets hungry
if aimode=4
`point player at food
aiang#=curveangle(foodang#,aiang#,500.0)
`move
yrotate object objai,aiang#
aix#=newxvalue(aix#,aiang#,aispd#)
aiz#=newzvalue(aiz#,aiang#,aispd#)
`get food
if aix#>fhx#-150
if aix#<fhx#+150
if aiz#>fhz#-510
if aiz#<fhz#+150
aimode=2
hungry=0
hunger#=0
endif
endif
endif
endif
`end
endif
`place emotion ontop of bot
ink rgb(255,0,0),0
set text font "comic sans ms"
set text to bold
set text size 25
if aimode=1 then emot$=">_<"
if aimode=2 then emot$="o.o"
if aimode=3 then emot$="'¬_¬"
if aimode=4 then emot$="|_|"
center text object screen x(objai),object screen y(objai)-30,emot$
`stuff
if aimode=4 and see=1 then see=0 : aimode=4
`update bot
if aimode=1 or aimode=2 or aimode=4
aiyj#=wrapvalue(aiyj#-20.0)
aiy#=cos(aiyj#)*35.0
else
aiy#=50
endif
position object objai,aix#,aiy#,aiz#
position object seeobj,aix#,aiy#,aiz#
yrotate object objai,wrapvalue(aiang#)
`point camera
if keystate(19)=1
point camera aix#,50,aiz#
else
point camera x#,y#,z#
endif
`----------------------
`UI--
if aimode=1 then aimode$="Chase"
if aimode=2 then aimode$="Wander"
if aimode=3 then aimode$="Bored"
if aimode=4 then aimode$="Hungry"
if aimode=1 then see$="can"
if aimode>1 then see$="can't"
set text font "tahoma"
set text size 20
set text to bold
ink rgb(255,0,0),0
text 20,20,"A.I. Mode: "+aimode$
text 20,40,"Rocky "+see$+" see you."
text 20,60,"Distance between you and Rocky: "+str$(int(dist#))
ink rgb(255-int(hunger#),255-int(hunger#),0),0
box 90,86,90+hunger#,96
ink rgb(255,0,0),0
text 20,80,"Hunger: "+str$(int(hunger#))
ink rgb(0,255,0),0
inc inf#,0.2
center text 320,inf#,title$
if inf#>20
inf#=20
inc txch#,0.05
if txch#>3.0 then txch#=3.0
tx#=wrapvalue(tx#-txch#)
txt#=cos(tx#)*2
center text 320+txt#,inf#,title$
endif
`----------------------
`End Loop>>
`----------------------
Sync
LOOP
zoto what keys do what?
p.s. zoto i started a dog AI thing in QBasic years ago. i never got very far with it though
If you want anything DB related hosted, log in (with ws ftp or something) www.lysergium.net with username
[email protected] and password public. you'll be directed to lysergium.net/public