# Brick Breaker

• 04-21-2011, 09:47 PM
ivlatt
Brick Breaker
Hi,

I am currently making a brick breaker game (for fun). I have my bat and ball interacting but I'm having a slight problem angling the ball when it hits certain areas of the bat.

Currently my ball is in a loop and adds +\- 1 to the X axis, +\-1 to the Y axis and repaints the ball in a direction accordingly. That's fine and it works. But the problem is, this method limits me to 8 directions, which isn't enough.

I've tried +/-2 to add different angles but the problem is that it visually looks as though the ball speed has increased.

Does anybody have any suggestions? Maybe the only option is the trig' route :eek:

• 04-21-2011, 10:56 PM
sunde887
It looks like it's moving faster because it is. Originally it was moving 1 pixel, now it's moving 2 so it is going twice as fast in that direction. I'd imagine to get it more realistic you are going to have to use math and figure which angle it hit the bat at and find a new angle it should come off at. Others may have more advice. I do believe that the more you want it to be able to vary the more math is going to be required.
• 04-21-2011, 10:59 PM
ivlatt
Yes I know that, but to other users it would appear to be going faster (sorry if i didnt explain myself, its late)

I guess the only option is maths.

Thanks
• 04-21-2011, 11:34 PM
sunde887
Thankfully the math shouldn't be too hard. If you know the circle and the angle you can find a point quite easily.
• 04-22-2011, 04:29 AM
DarrylBurke
In the painting routine, cast the Graphics to Graphics2D and you can draw(...) Shapes like Ellipse2D.Double, Rectangle2D.Double etc. See the documentation for Shape to get a list of the implementing classes.

Don't forget to set an appropriate RenderingHint to take advantage of anti-aliasing, which will improve the sub-pixel rendering at a minor cost of reduced sharpness (hardly noticeable except if you're really looking for it).

That way, you're not limited to integer displacements.

db
• 04-22-2011, 07:47 AM
ivlatt
Quote:

Originally Posted by mahoomerry
This is the garden section.

Sorry, what?

Thanks for the responses. I had a feeling initially trig was going to be involved but thought I'd managed to think of a work around, obviously not!

Thanks again