Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-01-2008, 06:03 PM   PM User | #1
gencoglu4
New Coder

 
Join Date: Oct 2004
Posts: 37
Thanks: 0
Thanked 1 Time in 1 Post
gencoglu4 is an unknown quantity at this point
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..
gencoglu4 is offline   Reply With Quote
Old 01-01-2008, 07:55 PM   PM User | #2
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
The minutes invested in beautifying code posting here have emazing impact, learn from expiriences.
BubikolRamios is offline   Reply With Quote
Old 01-01-2008, 08:28 PM   PM User | #3
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,554
Thanks: 9
Thanked 480 Times in 463 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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 5/13)
STATS (2013/5) HTML5:90.2% MOB:15.2% IE7:0.5% IE8:8.4% IE9:8.5% IE10:8.5%
rnd me is offline   Reply With Quote
Old 01-01-2008, 10:11 PM   PM User | #4
gencoglu4
New Coder

 
Join Date: Oct 2004
Posts: 37
Thanks: 0
Thanked 1 Time in 1 Post
gencoglu4 is an unknown quantity at this point
still there is a problem...it only hits the first one..
any more help ..please .?

thanks
gencoglu4 is offline   Reply With Quote
Old 01-01-2008, 11:37 PM   PM User | #5
Arty Effem
Banned

 
Join Date: May 2006
Location: England
Posts: 664
Thanks: 0
Thanked 84 Times in 84 Posts
Arty Effem can only hope to improve
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.
Arty Effem is offline   Reply With Quote
Old 01-02-2008, 03:55 PM   PM User | #6
gencoglu4
New Coder

 
Join Date: Oct 2004
Posts: 37
Thanks: 0
Thanked 1 Time in 1 Post
gencoglu4 is an unknown quantity at this point
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..
gencoglu4 is offline   Reply With Quote
Old 01-02-2008, 05:36 PM   PM User | #7
Arty Effem
Banned

 
Join Date: May 2006
Location: England
Posts: 664
Thanks: 0
Thanked 84 Times in 84 Posts
Arty Effem can only hope to improve
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().
Arty Effem is offline   Reply With Quote
Old 01-18-2008, 10:59 AM   PM User | #8
mjlorbet
Regular Coder

 
mjlorbet's Avatar
 
Join Date: Jan 2008
Location: Milwaukee, WI
Posts: 724
Thanks: 8
Thanked 96 Times in 95 Posts
mjlorbet will become famous soon enough
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
mjlorbet is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:18 AM.


Advertisement
Log in to turn off these ads.