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

2016/11/15

bouncing balls in random directions

aakanksha-patil aakanksha-patil

2016/11/15

#
can anyone help me out with that ? How to make the balls bounce off a object in random directions.
Super_Hippo Super_Hippo

2016/11/15

#
This will not work perfectly, but you might get an idea with which you can start.
public void act()
{
    move(5);
    if (isTouching(NameOfTheClass.class))
    {
        setRotation(Greenfoot.getRandomNumer(360));
    }
}
iiuulliiaannaa iiuulliiaannaa

2017/1/4

#
hi If i have this as my basic and i want to transform the counting in a random direction...what should i change to become random ? tsk :D public void act() { move(3); Actor net = getOneIntersectingObject(barrier.class); if (net!=null) { turn(0); move(1); } Actor baby_1 = getOneIntersectingObject(baby1.class); if (baby_1!=null) { turn(180); move(5); } Actor baby_2 = getOneIntersectingObject(baby2.class); if (baby_2!=null) { turn(180); move(5); } Actor baby_3 = getOneIntersectingObject(baby3.class); if (baby_3!=null) { turn(180); move(5); } }
danpost danpost

2017/1/4

#
@iiuulliiaannaa, It is unclear as to what exactly you are trying to do. Please give a couple of random sequences that would occur when randomized the way you want.
iiuulliiaannaa iiuulliiaannaa

2017/1/4

#
The ball can move anywhere within the pitch and across the wall in the middle of the screen. If the ball touches a baby it is deflected/rebounds back in the opposite direction. The ball must move one whole ‘white/wall’ block at a time every time a movement button (via a direction button (<, > v ^)) /key is pressed (when movement is possible). The solution must use the scenario provided. i.e. If the babies are left in the unmodified codes starting position the ball would move between them continuously. The ball must stop when the perimeter of the pitch is reached. The basic solution must be completed using the ‘act’ button (accessing the kickBall() method within the CBabyBallBounce.class).
danpost danpost

2017/1/4

#
What you gave looks like instructions. However, to me, they really do not mean anything as I do not have access to said scenario.
You need to login to post a reply.