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

2019/10/18

help, I need the sphere to move in the form of a random parable in the world

cavencad cavencad

2019/10/18

#
I am creating a "Super Pang" style game and I need the sphere to bounce randomly on the parabola-shaped map. this is what i wear. public int speed=10; public void move(){ if(this.getX()<=0){ this.setLocation(this.getX()+3,this.getY()+speed); } this.setLocation(this.getX()+3,this.getY()-speed); }
danpost danpost

2019/10/18

#
In Super Pang, they seem to appear at a random x along the top, drop a short amount (straight down) and then randomly turn left or right as they begin to fall and bounce as with gravity and no drag, bouncing at slower speeds (not bouncing as high) as the size of the sphere gets smaller. Actually, the behavior of the largest spheres are very similar, if not the same, as the bombs and the coin (if that is what it is). It might be a good idea to have a class between Actor and the classes of these falling object, maybe called Bouncer so you do not have to write code multiple times. It can contain all the movement/bouncing codes for these actors. The subclasses can then deal with individual behavior (like bomb explodes, coin ends level and sphere breaks into smaller ones). For parabolic motion, you just need a speed along the x-axis that negates when hitting side edges, a vertical speed that constantly increases (as by gravity) and a bounce speed to set vertical speed to when hitting the ground.
You need to login to post a reply.