Results 1 to 6 of 6

Thread: Brick Breaker

  1. #1
    ivlatt is offline Member
    Join Date
    Apr 2011
    Posts
    12
    Rep Power
    0

    Default 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 advance
    Last edited by ivlatt; 04-21-2011 at 10:10 PM.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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.

  3. #3
    ivlatt is offline Member
    Join Date
    Apr 2011
    Posts
    12
    Rep Power
    0

    Default

    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

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Thankfully the math shouldn't be too hard. If you know the circle and the angle you can find a point quite easily.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default

    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

  6. #6
    ivlatt is offline Member
    Join Date
    Apr 2011
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by mahoomerry View Post
    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

Similar Threads

  1. Brick breaker game Code
    By Mahesh Ratan in forum AWT / Swing
    Replies: 6
    Last Post: 03-26-2014, 05:30 PM
  2. need help with brick breaker (breakout)
    By blackmatrix00 in forum Java Applets
    Replies: 3
    Last Post: 05-24-2010, 07:25 AM
  3. Brick breaker game Code
    By Mahesh Ratan in forum Java Gaming
    Replies: 3
    Last Post: 03-22-2010, 02:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •