Results 1 to 2 of 2
  1. #1
    Stormy is offline Member
    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Default Paddle Brick Game- finding direction a ball hits a brick

    Hello,
    I am working on a paddle brick game (this is my first 'real' attempt at making a game), I am having a bit of difficuilty getting Java to find which side of the block is hit by the ball. The idea is that the brick disappears and the ball gets reflected in the opposite direction that it came. I have used two booleans to define which direction the ball is going - these isTop and isLeft.
    I have attempted to use if statements such as

    public void isBrickHit(int blockLeft,int blockTop, int blockHeight, int blockWidth){
    //Ball hits block from right
    if(left<=blockLeft+blockWidth && left>=blockLeft && top>blockTop && top+height<=blockHeight+blockTop){
    isLeft=true;
    }

    ... and repeated for the other four sides...
    }

    However this doesn't very well at all as it often thinks the ball has hit the rectangle at a different square...

    I think it may be possible to use an intersection method, however I am not sure how I could use this to differentiate which side is being hit!
    Could someone explain how this may be possible?
    Thanks for you help in advance!
    Simon

  2. #2
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default Re: Paddle Brick Game- finding direction a ball hits a brick

    I'm just learning games as well, but I was taught to do a similar game using a speed variable and a direction variable (in degrees).

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. Paddle Class: Trying to code details to ball & paddle..
    By CuppaCoffee in forum New To Java
    Replies: 1
    Last Post: 01-09-2012, 12:14 AM
  3. Brick Breaker
    By ivlatt in forum Java Gaming
    Replies: 5
    Last Post: 04-22-2011, 07:47 AM
  4. 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
  •