With the Help of merix, I have been edging toward completing my first game. I have, however encountered a strange problem. It deels with collision. I had an idea to create a simple pathfinding command for the enemy, or object e to move around object t(a barrier), here was that code...
for e=6 to 15
for t=204 to 206
if object collision(e,t)>0
position object e, object position x(e)+1, object position y(e), object position z(e)
endif
next e
next t
But it wont work, and now neither will the collision with the target object (object 202). I have encluded the complete source code in an effort to track down this problem....
rem Init display
randomize timer()
set display mode 1024,768,32
sync on
sync rate 60
autocam off
Set camera range 1,10000
position mouse screen width()/2, screen height()/2
backdrop on
color backdrop rgb(0,0,0)
dim selection(0)
dim player(0)
dim timeleft(0)
dim wavetime(0)
selection(0)=0
player(0)=1
timeleft(0)=200
wavetime(0)=200
rem the new mouse object to play with
make object cube 20,10
position object 20,100,0,100
set object collision to boxes 20
color object 20,RGB(128,128,0)
hide object 20
rem the new mouse object(s) to play with (blue)
for t=1 to 5
make object cube t,10
set object collision to boxes t
color object t,RGB(0,0,150)
set object collision on t
position object t,100+rnd(50),0,100+rnd(50)
while object collision(t,0) > 0
position object t,100+rnd(50),0,100+rnd(50)
endwhile
next t
`make barriers
for t=204 to 206
make object box t,30,10,10
set object collision on t
position object t, 100+rnd(50), 0,100+rnd(50)
next t
rem make machine gun nest A
m= 201
make object cube m, 10
set object collision to boxes m
color object m,RGB(50,50,0)
Position object m,100,0,100
rem make bullets
for b=1000 to 1001
make object sphere b,2
next b
for b=1000 to 1001
position object b,object position x(m),object position y(m),object position z(m)
next b
`make machine gun nest target
t = 202
make object box t,30,5,10
color object t,RGB(50,50,0)
position object t,100,0,-100
`make wave one (red)
for e=6 to 15
make object cube e, 4
set object collision to boxes e
set object collision on e
color object e,RGB(255,0,0)
position object e,100+rnd(60),0,-100+rnd(60)
while object collision(e,0) > 0
position object e,100+rnd(60),0,-100+rnd(60)
endwhile
next e
`make wave two (red)
for e=100 to 150
make object cube e,4
color object e,RGB(255,0,0)
set object collision to boxes e
set object collision on e
position object e,100+rnd(100),0,-400+rnd(100)
while object collision(e,0) > 0
position object e,100+rnd(100),0,-400+rnd(100)
endwhile
next e
`make landmines (green)
for k=16 to 19
make object cube k,3
color object k,RGB(0,255,0)
set object collision to boxes k
set object collision on k
position object k,100+rnd(50),0,80+rnd(50)
while object collision(k,0) > 0
position object k,100+rnd(50),0,80+rnd(50)
endwhile
next k
position camera -100,100,-100
xrotate camera 90
position camera 100,300,0
do
for e=6 to 15
k = object collision(e, 0)
if k > 0 and k < 20
if k <> selection(0)
hide object e
endif
endif
next e
for e=6 to 15
if object collision(e,202)
hide object e
endif
next e
for e=100 to 150
if object collision(e,202)
hide object e
endif
next e
for e=100 to 150
k = object collision(e, 0)
if k > 0 and k < 20
if k <> selection(0)
hide object e
endif
endif
next e
for e=6 to 15
for t=204 to 206
if object collision(e,t)>0
position object e, object position x(e)+5, object position y(e), object position z(e)
endif
next e
next t
fire=1
for b=1000 to 1001
t = 202
if fire=1
point object b,object position x(t),object position y(t),object position z(t)
move object b, 10
endif
if object collision(b,t)>0
fire=0
position object b,object position x(m),object position y(m),object position z(m)
endif
next b
rem print timer
set cursor 0,0
print "Player ",player(0)," Has ",timeleft(0)," Time Left "
if timeleft(0)=>0
gosub selection
endif
timeleft(0)=timeleft(0)-1
if timeleft(0)=<0
if player(0)=1
gosub wave
wavetime(0)=wavetime(0)-1
center text 70,400, "WAVE 1 INBOUND!"
set cursor 10,10
print "use the objects at your disposal and keep the enemy at bay for " ,wavetime(0),"milliseconds"
timeleft(0)=0
endif
endif
if returnkey()=1 then cls
if wavetime(0)=<0
wavetime(0)=0
endif
for e=6 to 15
if wavetime(0)=0
hide object e
center text 70,600,"wave 2 inbound!"
gosub wave2
endif
next e
sync
loop
end
rem ============================
wave:
for e=6 to 15
move object e,.1
next e
return
wave2:
for e=100 to 150
move object e,.1
next e
return
selection:
rem the new object selection code
if object screen x(20)=<mousex()
position object 20,object position x(20)+4,object position y(20),object position z(20)
endif
if object screen x(20)=>mousex()
position object 20,object position x(20)-4,object position y(20),object position z(20)
endif
if object screen y(20)=<mousey()
position object 20,object position x(20),object position y(20),object position z(20)-4
endif
if object screen y(20)=>mousey()
position object 20,object position x(20),object position y(20),object position z(20)+4
endif
rem the select bit (replace with distance equation) Player 1
if player(0)=1
if mouseclick()=1
t = object collision(20,0)
if t > 0 and t < 6
position object t,object position x(20),object position y(20),object position z(20)
selection(0)=t
endif
if t > 15 and t < 20
position object t,object position x(20),object position y(20),object position z(20)
selection(0)=t
endif
else
selection(0) = 0
endif
endif
if player(0)=1
if mouseclick()=1
t = object collision(20,0)
if t > 0 and t < 6
position object t,object position x(20),object position y(20),object position z(20)
selection(0)=t
endif
if t > 199 and t < 202
position object t,object position x(20),object position y(20),object position z(20)
selection(0)=t
endif
else
selection(0) = 0
endif
endif
if player(0)=1
if mouseclick()=1
t = object collision(20,0)
if t > 0 and t < 6
position object t,object position x(20),object position y(20),object position z(20)
selection(0)=t
endif
if t > 201 and t < 203
position object t,object position x(20),object position y(20),object position z(20)
selection(0)=t
endif
else
selection(0) = 0
endif
endif
if player(0)=1
if mouseclick()=1
t = object collision(20,0)
if t > 0 and t < 6
position object t,object position x(20),object position y(20),object position z(20)
selection(0)=t
endif
if t > 203 and t < 207
position object t,object position x(20),object position y(20),object position z(20)
selection(0)=t
endif
else
selection(0) = 0
endif
endif
return
I will sum up, what the code is supposed to to...
the bullets are supposed to be fired from the machine gun nest at a target object (202), when and enemy collides with object 202 its supposed to dissapear, the same applies for every other object except for the barriers (204 to 206) which are supposed to make the enemys go around them. The enemys are objects 6 to 15, and object 100 to 150.
Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.