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

Report as inappropriate.

2Karl
2Karl presents ...

2012/6/24

Bouncing Balls

A friend of mine presented a conundrum regarding getting balls to bounce properly in a Pang-clone he is bruilding. Hopefully this should give some insights

5134 views / 28 in the last 7 days

Tags: with-source

open in greenfoot
Your browser does not support the canvas tag.
2Karl2Karl

2012/6/24

I should mention that the code is fully commented for those of you who are curious.
sp33dysp33dy

2012/6/25

Some very dubious collision detection there. Seems to register collisions too early with balls below and with side way hits.
danpostdanpost

2012/6/25

@sp33dy, I believe that is due to the difference between the actual size of the image and the size of the ball itself within the image. @2Karl, since the balls are round, maybe you should use 'getObjectsInRange' for collision checking, instead of using one of the 'intersecting' methods.
2Karl2Karl

2012/6/28

Yes, getObjectsInRange would be more efficient. the reason I used getOneIntersecting Object is because the person I was helping out is not only new to greenfoot, he's new to Java as well. rather than confuse him with optimisation from the off, I thought I'd show him the logic behind collision detection so that he can investigate more efficient methods as he develops. Thanks for the input though guys ;)

Want to leave a comment? You must first log in.

Who likes this?

No votes yet.