A simple jQuery game - how do I know when two cars (divs) collide with each other?

I tried to make this simple jQuery game

http://www.abkeya.com/2011/02/14/simple-jquery-game/

Most of the parts work well, but as you can see, I used two divs - this is a car for the players, and the second - the car of the opponents, which would be better for me if I want to know when two cars collide with each other? or any suggestions for its further promotion?

In addition, the street lines rise when they reach the bottom of the street and disappear, I wonder how I would do the same to start the street so that the car and street lines come naturally.

+5
source share
3

, , - . , . , Car1 Car2. , , + + () .

, , ? , .

, !

+1

, - box collision.

, , , DIV. , .

--.

function intersects(a,b)
{
    if(a.x + a.w > b.x)
        sectHor = true;
    if(a.x < b.x + b.w)
        sectHor = true;
    if(a.y < b.y + b.h)
        sectVert = true;
    if(a.y + a.h > b.y)
        sectVert = true;

    if(sectHor && sectVert)
        return true;
    else return false;
}

, , , , , , . , , - A B . , , , .

+1

All Articles