Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Oct 2004
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Arrow array /collision detection

    Hi, There
    I am tring to create a simple collision test..The problem is I can not figure outhow to use an ARRAY..
    I mean.. my car is moving and it hits first car then it keeps moving and hits the second...and so on..it will stop till it hits all 5 cars..

    I will be very happy if you can fix my following codes..

    Thanks in advance.
    PHP Code:
    <script
    document.bgColor="pink"
    var 
    =setInterval('basla()',100
    var 
    tar=new array(); 
    function 
    basla() { 
            
    tar1a document.all.imX
             
            
    tar1a.style.posLeft += 5
            for (var 
    1<= 5i++) { 
    var 
    tar document.getElementById("im" i); 
                if ((
    tar1a.style.posLeft <= tar.style.posLeft tar.style.posWidth && 
                    
    tar1a.style.posLeft >= tar.style.posLeft) && 
                    
    tar1a.style.posTop <= tar.style.posTop tar.style.posHeight && 
                    
    tar1a.style.posTop >= tar.style.posTop) { 
                    
    tar.style.visibility "hidden"
                    
    clearInterval(a); 
                } 
            } 
        } 
    </script> 
    <bgsound src="#" id=ses loop=1 autostart="false"> 
    <img src="kap.gif" name=imX style="position:absolute;top:100;left:10;"><br><br> 
    <img src="kizss.gif" name=im1 style="position:absolute;top:100;left:50;"><br><br> 
    <img src="kizss.gif" name=im2 style="position:absolute;top:100;left:100;"><br><br> 
    <img src="kizss.gif" name=im3 style="position:absolute;top:100;left:150;"><br><br> 
    <img src="kizss.gif" name=im4 style="position:absolute;top:100;left:200;"><br><br> 
    <img src="kizss.gif" name=im5 style="position:absolute;top:100;left:250;"><br><br> 
    <img src="kizss.gif" name=im6 style="position:absolute;top:100;left:300;"><br><br> 
    Last edited by gencoglu4; 01-02-2008 at 03:46 PM.

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,960
    Thanks
    120
    Thanked 76 Times in 76 Posts
    The minutes invested in beautifying code posting here have emazing impact, learn from expiriences.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,296
    Thanks
    10
    Thanked 583 Times in 564 Posts
    Quote Originally Posted by BubikolRamios View Post
    The minutes invested in beautifying code posting here have emazing impact, learn from expiriences.


    Code:
        function basla() {
            tar1a = document.all.imX;
            tar = document.getElementById("im" + i);
            tar1a.style.posLeft += 5;
            for (var i = 1; i <= 5; i++) {
                if ((tar1a.style.posLeft <= tar[i].style.posLeft + tar[i].style.posWidth &&
                    tar1a.style.posLeft >= tar[i].style.posLeft) &&
                    tar1a.style.posTop <= tar[i].style.posTop + tar[i].style.posHeight &&
                    tar1a.style.posTop >= tar[i].style.posTop) {
                    tar[i].style.visibility = "hidden";
                    clearInterval(a);
                }
            }
        }
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #4
    New Coder
    Join Date
    Oct 2004
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post
    still there is a problem...it only hits the first one..
    any more help ..please .?

    thanks

  • #5
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by gencoglu4 View Post
    still there is a problem...it only hits the first one..
    How can it be doing that?
    This code can't even get started because it's riddled with errors that the console would indicate.

  • #6
    New Coder
    Join Date
    Oct 2004
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post
    I corrected it but still need help....I also need to asign onkeydown() function to move the object so that I can pick all of the objects on the screen just as in "PACKMAN games"
    PHP Code:
    <script
    document.bgColor="pink"
    var 
    =setInterval('basla()',100
    var 
    tar=new array(); 
    function 
    basla() { 
            
    tar1a document.all.imX
             
            
    tar1a.style.posLeft += 5
            for (var 
    1<= 5i++) { 
    var 
    tar document.getElementById("im" i); 
                if ((
    tar1a.style.posLeft <= tar.style.posLeft tar.style.posWidth && 
                    
    tar1a.style.posLeft >= tar.style.posLeft) && 
                    
    tar1a.style.posTop <= tar.style.posTop tar.style.posHeight && 
                    
    tar1a.style.posTop >= tar.style.posTop) { 
                    
    tar.style.visibility "hidden"
                    
    clearInterval(a); 
                } 
            } 
        } 
    // this is the second function...need help combineing this with the one above..
    function KeyDown() { 
        if (
    event.keyCode==39)
        { 

    fin.style.posLeft=fin.style.posLeft+20;

        } 
    if (
    event.keyCode==37)
        { 

    fin.style.posLeft=fin.style.posLeft-20;

    }

    if (
    event.keyCode==40)
        { 

    fin.style.posTop=fin.style.posTop+20;

        } 
    if (
    event.keyCode==38)
        { 

    fin.style.posTop=fin.style.posTop-20;

    }
    }
    </script> 

    <img src="kap.gif" name=imX style="position:absolute;top:100;left:10;"><br><br> 
    <img src="kizss.gif" name=im1 style="position:absolute;top:100;left:50;"><br><br> 
    <img src="kizss.gif" name=im2 style="position:absolute;top:100;left:100;"><br><br> 
    <img src="kizss.gif" name=im3 style="position:absolute;top:100;left:150;"><br><br> 
    <img src="kizss.gif" name=im4 style="position:absolute;top:100;left:200;"><br><br> 
    <img src="kizss.gif" name=im5 style="position:absolute;top:100;left:250;"><br><br> 
    <img src="kizss.gif" name=im6 style="position:absolute;top:100;left:300;"><br><br> 
    Last edited by gencoglu4; 01-02-2008 at 03:57 PM.

  • #7
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by gencoglu4 View Post
    I corrected it but still need help...
    PHP Code:
    var tar=new array(); 
    I don't think so - the console must have something to say about that, which should be new Array().

  • #8
    Regular Coder mjlorbet's Avatar
    Join Date
    Jan 2008
    Location
    Milwaukee, WI
    Posts
    724
    Thanks
    8
    Thanked 96 Times in 95 Posts
    additionally, all the name=imX attributes in the html should be changed to id="imX" so that document.getElementById() actually has an ID to get
    -Mike
    "Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •