Results 1 to 6 of 6
Thread: Brick Breaker
- 04-21-2011, 09:47 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 12
- Rep Power
- 0
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:
Thanks in advanceLast edited by ivlatt; 04-21-2011 at 10:10 PM.
- 04-21-2011, 10:56 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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 #3
Member
- Join Date
- Apr 2011
- Posts
- 12
- Rep Power
- 0
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 #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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 #5
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 #6
Member
- Join Date
- Apr 2011
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
need help with brick breaker (breakout)
By blackmatrix00 in forum Java AppletsReplies: 3Last Post: 05-24-2010, 07:25 AM -
Brick breaker game Code
By Mahesh Ratan in forum Java GamingReplies: 3Last Post: 03-22-2010, 02:21 PM -
Brick breaker game Code
By Mahesh Ratan in forum AWT / SwingReplies: 3Last Post: 03-22-2010, 01:13 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks