Im working on a simple game, where two ships move back and forth over the screen and fire on each other. There also exist two
blocks, that blocks the bullets. This is something the AI is having trubble with. Im trying to make so it dont fire when there is an
block between the two players. But I cant. The following code SHOULD do it. AI fiering:
rem Fire the weapon
if n=1 and sprite x(objects(1).objectNr)>sprite x(objects(2).objectNr)-10 and sprite x(objects(1).objectNr)<sprite x(objects(2).objectNr)+10
if CollisionCheck(1)=0 then WeaponsPlayerOne()
endif
if n=2 and sprite x(objects(2).objectNr)>sprite x(objects(1).objectNr)-10 and sprite x(objects(2).objectNr)<sprite x(objects(1).objectNr)+10
if CollisionCheck(2)=0 then WeaponsPlayerTwo()
endif
. The function that checks if its a clear shot:
function CollisionCheck(player)
rem Create the sprite
sprite 25000,sprite x(objects(player).objectNr)+23.5,sprite y(objects(player).objectNr),weaponArray(1,1).imageBullet
rem Determine the sprite direction
if player=1 then direction=1
if player=2 then direction=-1
rem Move and check the collision
for n=1 to screen height()
move sprite 25000,direction
if sprite collision(25000,3)=1 or sprite collision(25000,4)=1
returnvalue=1
else
returnvalue=0
endif
next n
rem Delete the sprite
delete sprite 25000
endfunction returnvalue
. Any ideas about whats wrong?