This site requires JavaScript, please enable it in your browser!
Greenfoot back
Rabe123
Rabe123 wrote ...

2016/6/5

Roundabout traffic Problem

Rabe123 Rabe123

2016/6/5

#
Hi guys, i have a make a circle with the radius 290 around the point x=400 and y=480. In this radius driven cars (fast) and busses (slow). Now i have two question: How can i make it so that when before a car a car or bus stop the car too stop and then when the car or bus before move it too move ? Then i would make it so that the car look if on the radius 230 is a car or a bus. When there is no car or bus on the point next too them it should switch to this radius 230. When then on the radius 290 is no car and bus next too them it should go to the old radius 290. So i would make a roundabout traffic. thanks
Rabe123 Rabe123

2016/6/5

#
here is my try to make it:
   circle();
        g=k;
   
        if (!getNeighbours(170, false,Bus.class).isEmpty()&& radius == 290)
        {
            g= 0; //speed
            
               
                    if(!getObjectsInRange(151,Bus.class).isEmpty()){
                
                    
                    {

                        g= 0;
                        radius = radius -60;

                    }
                }

            
            else {
            return;}
        
    }
        
        if(radius == 230){

            if(isTouching(Auto.class)&&!getNeighbours(o, true,Bus.class).isEmpty()){
                radius = radius +60;
            }
        }
danpost danpost

2016/6/5

#
Line 28 has an unknown quantity for the range of 'getNeighbours'. It appears the range of 'getNeighbours' in line 4 could have an auto stop even if a bus was in the other lane (no passing would be allowed). You may have to find a way to be more specific as to what areas to use collision checking at (it may require the auto to change positions before checking and moving back after checking).
Rabe123 Rabe123

2016/6/5

#
ok but i dont know how i should do it. How can i make a method for the auto that looks if there (on the other radius) is a bus or car without the touching, inRage or Neighbours method ?
danpost danpost

2016/6/5

#
Rabe123 wrote...
ok but i dont know how i should do it. How can i make a method for the auto that looks if there (on the other radius) is a bus or car without the touching, inRage or Neighbours method ?
I was not suggesting that you not use any of those methods -- I was suggesting that you use one of those methods (most probably the 'getObjectsInRange' method); but only after re-locating the auto to potential future locations. After performing the check, you would move the auto back to where it was moved from, if a collision was found to occur. So, for example, a method to change lanes might be:
private void tryLaneChange()
{
    move((radius+60)%radius+radius); // unconditional lane change
    boolean atVehicle = ! (getObjectsInRange(100, Auto.class).isEmpty() && getObjectsInRange(100, Bus.class).isEmpty());
    if (atVehicle) move((radius+60)%radius+radius); // cannot change lanes -- switch back to original lane
}
Maybe you could write a method that reverses what the 'circle' method does. That way you can move back it you find the auto in range of another after the initial movement.
You need to login to post a reply.