The ghost goes around and if you get too near he follows you. If he catches you, your dead
If you get to far away and hes following you, then he goes back to moving around.
Play around and learn.
DBPro
Sync On : Randomize Timer()
`Make Grass Texture
Create Bitmap 1,256,256
box 0,0,256,256,rgb(10,75,5),rgb(10,75,5),rgb(10,75,5),rgb(10,75,5)
for dots=1 to 100000
dot rnd(256),rnd(256),rgb(rnd(50),150-rnd(100),rnd(10))
next dots
Get Image 10,0,0,256,256
Delete bitmap 1
cls
`Make Ground
Make Matrix 1,100,100,8,8 : prepare matrix texture 1,10,4,4
`Ghost
Make Object box 1,3,8,3 : Position Object 1,40,5,40
`Dummy Camera Object
make object cube 2,4 : hide object 2
`Set Follow Variable
Follow#=0
`Make Waypoints
Dim Waypoint(5,2)
For WP=1 to 5
Waypoint(WP,1)=(40-11)+rnd(22)
Waypoint(WP,2)=(40-11)+rnd(22)
Make object cube WP+10,2
Position object WP+10,Waypoint(WP,1),5,Waypoint(WP,2)
hide object WP+10
next WP
WP#=1
`Move the camera up a bit
Move object up 2,4
Position camera object position x(2),object position y(2),object position z(2)
Do
`Control Camera
control camera using arrowkeys 0,.3,.3
`Place Dummy for Camera
position object 2, camera position x(), camera position y(), camera position z()
`If the ghost isn't following
if Follow#=0
`Find the angle from the ghost to the waypoint
ANG#=AngleY(1,WP#+10)
Yrotate object 1, ANG#
`Move the Ghost
Move Object 1,.075
`Check if the ghost has reached the waypoint
Dis#=Distance(1,WP#+10)
`If the ghost has reached the waypoint, choose a random new one
If Dis#<.1 then WP#=rnd(4)+1
`Check if the player gets near the ghost
Dist#=Distance(1,2)
`If the ghost is near, then make him follow
If Dist#<18 then Follow#=1
`If the ghost is following you
else
`Find the angle from the ghost to the player
ANG#=AngleY(1,2)
Yrotate object 1, ANG#
`Move the Ghost
Move Object 1,.058
`Check if the ghost has reached you
Dis#=Distance(1,2)
`If the ghost has reached you, then its game over
If Dis#<2.5 then goto gameover
`If the ghost is too far, make him not follow anymore
If Dis#>50 then Follow#=0
endif
Sync
Loop
gameover:
cls
repeat
sync
until scancode()=0
repeat
text 20,20,"Game Over!"
sync
until scancode()>0
end
function Distance(Object1,Object2)
dist#=sqrt((object position x(Object1)-object position x(Object2))^2+(object position y(Object1)-object position y(Object2))^2+(object position z(Object1)-object position z(Object2))^2)
endfunction dist#
function AngleY(Object1,Object2)
angy#=atanfull(object position x(Object2)-object position x(Object1),object position z(Object2)-object position z(Object1))
endfunction angy#
DBC
Sync On : Randomize Timer()
`Make Ground
Make Matrix 1,100,100,8,8
`Ghost
Make Object box 1,3,8,3 : Position Object 1,40,5,40
`Dummy Camera Object
make object cube 2,4 : hide object 2
`Set Follow Variable
Follow#=0
`Make Waypoints
Dim Waypoint(5,2)
For WP=1 to 5
Waypoint(WP,1)=(40-11)+rnd(22)
Waypoint(WP,2)=(40-11)+rnd(22)
Make object cube WP+10,2
Position object WP+10,Waypoint(WP,1),5,Waypoint(WP,2)
hide object WP+10
next WP
WP=1
point camera 40,camera position y(),40
Do
`Control Camera
move camera upkey()-downkey()*.3
Yrotate Camera wrapvalue(camera angle y()+(rightkey()-leftkey())*2)
`Place Dummy for Camera
position object 2, camera position x(), camera position y(), camera position z()
`If the ghost isn't following
if Follow#=0
`Find the angle from the ghost to the waypoint
ANG#=AngleY(1,WP+10)
Yrotate object 1, wrapvalue(ANG#)
`Move the Ghost
Move Object 1,.075
`Check if the ghost has reached the waypoint
Dis#=Distance(1,WP+10)
`If the ghost has reached the waypoint, choose a random new one
If Dis#<.1 then WP=rnd(4)+1
`Check if the player gets near the ghost
Dist#=Distance(1,2)
`If the ghost is near, then make him follow
If Dist#<18 then Follow#=1
`If the ghost is following you
else
`Find the angle from the ghost to the player
ANG#=AngleY(1,2)
Yrotate object 1, ANG#
`Move the Ghost
Move Object 1,.058
`Check if the ghost has reached you
Dis#=Distance(1,2)
`If the ghost has reached you, then its game over
If Dis#<2.5 then goto gameover
`If the ghost is too far, make him not follow anymore
If Dis#>50 then Follow#=0
endif
Sync
Loop
gameover:
cls
repeat
sync
until scancode()=0
repeat
text 20,20,"Game Over!"
sync
until scancode()>0
end
function Distance(Object1,Object2)
dist#=sqrt((object position x(Object1)-object position x(Object2))^2+(object position y(Object1)-object position y(Object2))^2+(object position z(Object1)-object position z(Object2))^2)
endfunction dist#
function AngleY(Object1,Object2)
angy#=wrapvalue(atanfull(object position x(Object2)-object position x(Object1),object position z(Object2)-object position z(Object1)))
endfunction angy#