Haven't made the revenge things yet.. but here's some more code (not quite finished yet).. it's similar to an fps that I'm making just now..
`Setup
Sync on : Sync rate 60
Hide mouse : set camera range 1,9999999
`Create World
Make matrix 1,3000,3000,30,30
`Enemy Data
enemies=10 :`This changes the amount of enemies.
Type enemy
x as float
y as float
z as float
state as integer
infront as boolean
health as integer
dist as float
ang as float
angdiff as float
Endtype
Dim enemy(enemies) as enemy
`Initialise enemies
for e=1 to enemies
enemy(e).x=rnd(3000)
enemy(e).z=rnd(3000)
enemy(e).y=get ground height(1,enemy(e).x,enemy(e).z)+25
enemy(e).state=1
enemy(e).health=100
next e
`Create Enemies
First=10 :`This is the first object used for the enemies
For e=1 to enemies
make object cube first+e,50
position object first+e,enemy(e).x,enemy(e).y,enemy(e).z
next e
`Create player (well... create the gun)
make object cylinder 1,100
xrotate object 1,90 : fix object pivot 1
scale object 1,20,100,20
make object cylinder 2,100 : xrotate object 2,90 : fix object pivot 2 : scale object 2,6,20,6
make mesh from object 1,2 : delete object 2
add limb 1,1,1 : offset limb 1,1,0,55,0
`Muzzle flash
make object plain 2,200,200 : glue object to limb 2,1,1 : hide object 2
set object cull 1,0
`Variables
speed#=10
e_speed#=speed#-2.0
`**Main Loop**
Do
`Control Player
xrotate camera curveangle(wrapvalue(camera angle x()+(mousemovey()*4)),camera angle x(),20.0)
yrotate camera curveangle(wrapvalue(camera angle y()+(mousemovex()*4)),camera angle y(),20.0)
xang#=camera angle x()
yang#=camera angle y()
if keystate(17)=1
x#=newxvalue(x#,yang#,speed#)
z#=newzvalue(z#,yang#,speed#)
endif
if keystate(31)=1
x#=newxvalue(x#,yang#,-speed#)
z#=newzvalue(z#,yang#,-speed#)
endif
y#=get ground height(1,x#,z#)+50
position camera x#,y#,z#
`Position gun
gxa#=wrapvalue(curveangle(xang#,gxa#,10.0))
gya#=wrapvalue(curveangle(yang#,gya#,10.0))
gx#=newxvalue(x#,wrapvalue(gya#+30),50.0)
gz#=newzvalue(z#,wrapvalue(gya#+30),50.0)
gy#=y#-25
position object 1,gx#,gy#,gz#
rotate object 1,wrapvalue(gxa#-recoil#),gya#,0
`Shooting - (All this doesn't actually fire a bullet object... it shoot only imitates shooting)
`(The actuall shooting will check oif you are "shooting" and check if you are pointing at the)
`(enemy, then make it act accordingly ... all will be explained)
if mouseclick()=1
inc shoot
endif
if mouseclick()=0 then shoot=0
if shoot=1
show object 2
recoil#=3.0
endif
if shoot<>1 then hide object 2 : shoot=0 : recoil#=0
point object 2,x#,y#,z#
`Artificial Intelligence
Gosub _AI
`**End Loop**
Sync
Loop
`**Subroutines**
_AI:
`Select all enemies
for e=1 to enemies
`Check distance between player and enemy
enemy(e).dist = sqrt( (x#-enemy(e).x)^2 + (y#-enemy(e).y)^2 + (z#-enemy(e).z)^2)
`Check angle differences
enemy(e).angdiff = atanfull(x#-enemy(e).x,z#-enemy(e).z)
`Shoot enemy
`Check if enemy is between you and gun and if you shoot - BAM! Change the enemy's state.
aimout#=10000
aimx#=newxvalue(gx#,gya#,aimout#)
aimz#=newzvalue(gz#,gya#,aimout#)
aimy#=gy#
infront#=intersect object(first+e,gx#,gy#,gz#,aimx#,aimy#,aimz#)
if infront#>0 then enemy(e).infront=1 else enemy(e).infront=0
if enemy(e).infront=1 and shoot=1
enemy(e).state=3
enemy(e).health=enemy(e).health-10
endif
`Respawn
if enemy(e).health<=0
enemy(e).health=100
enemy(e).x=rnd(3000)
enemy(e).z=rnd(3000)
endif
`If enemy sees you..
`If the enemy can see you then change state
if enemy(e).dist<500 and enemy(e).angdiff<90 and enemy(e).health>20
enemy(e).state=2
endif
`Make enemy wander
if enemy(e).dist>500 and enemy(e).health>20
enemy(e).state=1
endif
`make enemy run away
if enemy(e).health<20
enemy(e).state=4
endif
`Change enemies actions..
if enemy(e).state=1
enemy(e).ang=wrapvalue(enemy(e).ang+3.0)
enemy(e).x=newxvalue(enemy(e).x,enemy(e).ang,e_speed#)
enemy(e).z=newzvalue(enemy(e).z,enemy(e).ang,e_speed#)
endif
if enemy(e).state=2
enemy(e).ang=wrapvalue(enemy(e).angdiff)
enemy(e).x=newxvalue(enemy(e).x,enemy(e).ang,e_speed#)
enemy(e).z=newzvalue(enemy(e).z,enemy(e).ang,e_speed#)
endif
if enemy(e).state=3
enemy(e).ang=wrapvalue(enemy(e).angdiff)
enemy(e).x=newxvalue(enemy(e).x,enemy(e).ang,-e_speed#)
enemy(e).z=newzvalue(enemy(e).z,enemy(e).ang,-e_speed#)
endif
if enemy(e).state=4
enemy(e).ang=wrapvalue(enemy(e).angdiff+(180+enemy(e).angdiff/30))
enemy(e).x=newxvalue(enemy(e).x,enemy(e).ang,e_speed#)
enemy(e).z=newzvalue(enemy(e).z,enemy(e).ang,e_speed#)
endif
`Update enemies
enemy(e).y=get ground height(1,enemy(e).x,enemy(e).z)+25
position object first+e,enemy(e).x,enemy(e).y,enemy(e).z
yrotate object first+e,enemy(e).ang
`Deselect all enemies
next e
Return
There, I practically made a whole game for ya
now this can get stickied