i have a set of bullets in an array, and also a set of enemies in an array, what i need to have happen is that thwen of the bullets hits one of the enimies, it randomly puts the eneimes in another spot, is there any way to do that, because dont you have to have someting special when do an array-arry collision detection (and would it be easier if i have the bullets cubes too?) here is my bullet and enemy code (functions)
before main loop:
dim active(200,2)
maxwait=100
for b=1 to 100
make object sphere b+100,2.6
color object b+100,rgb(255,0,0)
hide object b+100
next b
ammo#=1000
enemies before loop too:
Number_of_Enemies=50
dim EnemyState(Number_of_Enemies)
Enemy_Aware#=50
Enemy_Speed#=.7
for x = 1 to Number_of_Enemies
make object cube x,4
color object x,rgb(128,0,0)
randomize timer()
position object x,rnd(Size),1,rnd(Size)
next x
and then their gosubfunctions called in loop:
shoot:
for b=1 to 100
if mouseclick()=1 and ammo#>0 and active(b+100,1)=0 and (timer()-lasttime)>maxwait
position object b+100,x1#,y1#,z1#
`set object to object orientation b+100,hero
active(b+100,1)=1
active(b+100,2)=30
show object b+100
ammo#=ammo#-1
lasttime=timer()
endif
pick screen mousex(),mousey(),camera position y()-object position y(Hero)
zdiff#=(object position z(hero)-(get pick vector z()+camera position z()))
angle#=atan((object position x(hero)-(get pick vector x()+camera position x()))/zdiff#)+(zdiff#>0)*180
yrotate object b+100,angle#
if active(b+100,1)=1
move object b+100,7
active(b+100,2)=active(b+100,2)-1
endif
if active(b+100,2)<0
active(b+100,1)=0
active(b+100,2)=0
hide object b+100
endif
next b
return
Enemies:
for x=1 to Number_of_Enemies
x2#=object position x(x)
z2#=object position z(x)
y2#=get ground height(World,x2#,z2#)
ay2#=object angle y(x)
if x2#<x1# then x2#=x2#+Enemy_Speed#
if x2#>x1# then x2#=x2#-Enemy_Speed#
if z2#<z1# then z2#=z2#+Enemy_Speed#
if z2#>z1# then z2#=z2#-Enemy_Speed#
position object x,x2#,y2#+1,z2#
rotate object x,object angle x(x),ay2#,object angle z(x)
next x
return
so when i do collision should i just have it be like for x=1 to maxenemies and then right below that for b=1 to 100, and then just be like if collision x,b+100 = true or 1 or whatever, then do my code. or would that only check for collision between the first bullet and first enemy?
edit: here is my full code, i did something and i dont kno what or when so that now my enemies just... well they dont go random but yea
sync on
sync rate 60
set display mode 1024,768,32
backdrop on
Autocam Off
hide mouse
Fog on
fog distance 350
Fog color RGB(128,128,128)
Color Backdrop RGB(128,128,128)
Image_Size=64
for x = 0 to Image_Size
for y = 0 to Image_Size
dot x,y,rgb(0,rnd(156),0)
next x
next y
get image 1,0,0,Image_Size,Image_Size
cls
`matrix stuff
World=1
Size=1000
Segments=10
make matrix World,Size,Size,Segments,Segments
prepare matrix texture 1,1,1,1
update matrix World
hero=400
make object cube hero,4
randomize timer()
position object Hero,rnd(size),1,rnd(size)
`SET UP VARIABLES FOR HERO SPEED
`speed for hero
speed#=0.0
`acceleration speed
acceleration#=.009
`max speed hero can move at
MaxSpeed#=1.4
`min speedhero can move at
MinSpeed=-1.0
`slowly move charector speed down when not moving
Friction#=.01
dim active(200,2)
maxwait=100
for b=1 to 100
make object sphere b+100,2.6
color object b+100,rgb(255,0,0)
hide object b+100
next b
ammo#=1000
Number_of_Enemies=50
Enemy_Speed#=.7
for x = 1 to Number_of_Enemies
make object cube x,4
color object x,rgb(128,0,0)
randomize timer()
position object x,rnd(Size),1,rnd(Size)
next x
`MAIN LOOP
do
`Here are our variables for the Hero. These are just position values
x1#=object position x(Hero)
z1#=object position z(Hero)
y1#=get ground height(World,x1#,z1#)
ax1#=object angle x(hero)
ay1#=object angle y(Hero)
`stay on matrix
if x1#>Size-200 then x1#=x1#-1
if x1#<200 then x1#=200
if z1#>Size-200 then z1#=z1#-1
if z1#<200 then z1#=200
position object Hero,x1#,y1#+3,z1#
position camera object position x(hero),object position y(hero)+200,object position z(hero)
point camera object position x(hero),object position y(hero),object position z(hero)
`if up arrow hit then increase hero speed
if Keystate(17)=1 then INC speed#,acceleration#
`down arrow decrease hero speed
if Keystate(31)=1 then DEC speed#,acceleration#
`strafe left
if Keystate(30)=1 then yrotate object hero,ay1#-1.4
`strafe right
if Keystate(32)=1 then yrotate object hero,ay1#+1.4
`cap the speed off
if speed#>MaxSpeed# then speed#=MaxSpeed#
`cap the speed off
if speed#<MinSpeed# then speed#=MinSpeed#
move object Hero,speed#
if Keystate(17)=0 and Keystate(31)=0
`if moving forward and not hitting up or down arrows, decrease speed
if speed#>=0.0
DEC speed#,Friction#
endif
`if moving backwards and not hitting up or down arrows, increase speed
if speed#<=0.0
INC speed#,Friction#
endif
endif
gosub Collision
gosub anti_stick
gosub enemies
gosub shoot
set cursor 900,600
print "Ammo: "; ammo#
set cursor 0,0
`display hero variables for viewing
print "X Position "; x1#
print "Z Position ";z1#
print "Y Position ";y1#
print "Speed ";speed#
posx=mousex()
posy=mousey()
set cursor posx,posy
print "+"
sync
loop
shoot:
for b=1 to 100
if mouseclick()=1 and ammo#>0 and active(b+100,1)=0 and (timer()-lasttime)>maxwait
position object b+100,x1#,y1#,z1#
`set object to object orientation b+100,hero
active(b+100,1)=1
active(b+100,2)=30
show object b+100
ammo#=ammo#-1
lasttime=timer()
endif
pick screen mousex(),mousey(),camera position y()-object position y(Hero)
zdiff#=(object position z(hero)-(get pick vector z()+camera position z()))
angle#=atan((object position x(hero)-(get pick vector x()+camera position x()))/zdiff#)+(zdiff#>0)*180
yrotate object b+100,angle#
if active(b+100,1)=1
move object b+100,7
active(b+100,2)=active(b+100,2)-1
endif
if active(b+100,2)<0
active(b+100,1)=0
active(b+100,2)=0
hide object b+100
endif
next b
return
Collision:
return
Enemies:
for x=1 to Number_of_Enemies
x2#=object position x(x)
z2#=object position z(x)
y2#=get ground height(World,x2#,z2#)
ay2#=object angle y(x)
if x2#<x1# then x2#=x2#+Enemy_Speed#
if x2#>x1# then x2#=x2#-Enemy_Speed#
if z2#<z1# then z2#=z2#+Enemy_Speed#
if z2#>z1# then z2#=z2#-Enemy_Speed#
position object x,x2#,y2#+1,z2#
rotate object x,object angle x(x),ay2#,object angle z(x)
next x
return
Anti_Stick:
colliding_objects=0
for x = 1 to Number_of_Enemies
for y = 1 to Number_of_Enemies
if x<>y
if object collision(x,y)=1
x2#=object position x(x)
z2#=object position z(x)
y2#=get ground height(World,x2#,z2#)
ay2#=object angle y(x)
inc colliding_objects,1
position object x,x1#,y2#+1,z1#+(object size(x)*colliding_objects)
move object left x,(Enemy_Speed#*.5)
endif
endif
next x
next y
return