collision detection

Discussion in 'JavaScript' started by EarthsExist, Jan 20, 2008.

  1. #1
    Hi, Following is a simple detection script..What im tring to achive is to make each target invisible one by one.
    but they become hidden all at a time..There is a logical mistake..
    will you please help me ...?

    Thanks in advance..


    
    <html>
    <body bgcolor="pink">	 
    <script>  
    setInterval("run()",10)
    function run()
    {	
    for(var i=0;i<=4;i++)
    { 
         oto1=document.getElementById("myOto"); 	 
         oto2=document.getElementById("iki"+i);	
      	 }
          oto1.style.posLeft+=2;
    	  oto2.style.posLeft+=1;
    	   x = ((oto1.style.posLeft >= oto2.style.posLeft) && (oto1.style.posLeft <= oto2.style.posLeft));
    	   y = ((oto1.style.posTop  >= oto2.style.posTop) && (oto1.style.posTop <= oto2.style.posTop));   
      
        if (x && y)
        {  
    	for(m=0;m<=4;m++)
    	{  
    	    oto=document.getElementById("iki"+m);
    	    oto.style.posLeft+=1;
    	    oto.style.visibility="hidden";	
    	}
        }	
    	} 
    	</script>  
    	<input type="text" value="myCar" id="myOto"style="position:absolute;top:220;left:10;width:10;">
    	<input type="text" value="target1" id="iki0" style="position:absolute;top:220;left:140;width:30;background-color:red;">
    	<input type="text" value="target2" id="iki1" style="position:absolute;top:220;left:200;width:30;background-color:red;">
    	<input type="text" value="target3" id="iki2" style="position:absolute;top:220;left:260;width:30;background-color:red;">
    	<input type="text" value="target4" id="iki3" style="position:absolute;top:220;left:320;width:30;background-color:red;">
    	<input type="text" value="target5" id="iki4" style="position:absolute;top:220;left:380;width:30;background-color:red;">
    	
    </body>
    </html>
    
    PHP:
     
    EarthsExist, Jan 20, 2008 IP