Results 1 to 9 of 9
  1. #1
    Ashish_jain's Avatar
    Ashish_jain is offline Member
    Join Date
    Jun 2011
    Posts
    32
    Rep Power
    0

    Post Collision in j2me

    why collision not happen in this code-

    if (((AppleX >= OctoXpos) && (AppleX <= OctoXpos + imgBell.getWidth()))
    || ((AppleX + imgApple.getWidth() <= OctoXpos) && (AppleX + imgApple.getWidth() >= OctoXpos + imgBell.getWidth()))
    && ((AppleY >= OctoYpos) && (AppleY <= OctoYpos + imgBell.getHeight()))
    || ((OctoYpos + imgBell.getHeight() <= AppleY) && (OctoYpos + imgBell.getHeight() >= AppleY + imgApple.getHeight()))) {



    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,253
    Rep Power
    25

    Default

    Try debugging the code by printing out the values of the variables and the results of the all the sub conditions.
    Give the code values that are collusions and values that are not and compare the results to see why the code does not work when there is a collusion.

  3. #3
    Ashish_jain's Avatar
    Ashish_jain is offline Member
    Join Date
    Jun 2011
    Posts
    32
    Rep Power
    0

    Default

    I have done this but no result found.condition is correct or not?

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,253
    Rep Power
    25

    Default

    Then you must have missed some of the combinations of conditions.
    Make a table of all the conditions with all their values and make sure you send all the values to your code.
    Run all the values thru your conditions and record the results.
    When the results are wrong, look at the logic and see which tests are wrong.

    If you are having problems, write a program that executes the code and passes it various combinations of values and post it with a driver that sends the code values that should be a collusion and values the are not a condition.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,304
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Ashish_jain View Post
    why collision not happen in this code-

    if (((AppleX >= OctoXpos) && (AppleX <= OctoXpos + imgBell.getWidth()))
    || ((AppleX + imgApple.getWidth() <= OctoXpos) && (AppleX + imgApple.getWidth() >= OctoXpos + imgBell.getWidth()))
    && ((AppleY >= OctoYpos) && (AppleY <= OctoYpos + imgBell.getHeight()))
    || ((OctoYpos + imgBell.getHeight() <= AppleY) && (OctoYpos + imgBell.getHeight() >= AppleY + imgApple.getHeight()))) {
    }
    When I look at the expressions from a birdeye view, I want to see something like this:

    Java Code:
    if ((Ax || Bx) && (Ay || By)) ...
    The 'A' expressions seem ok, but those 'B' expressions are a bit mixed up.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Ashish_jain's Avatar
    Ashish_jain is offline Member
    Join Date
    Jun 2011
    Posts
    32
    Rep Power
    0

    Default

    imgbell.getWidth() point to -> OctoWidth.
    And imgApple.getWidth() point to -> AppleWidth. and i m trying to collision b/w Apple and Octopus.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,253
    Rep Power
    25

    Default

    Here is how I suggest you find the problem with your code:
    Make a simple method that executes your if test and returns true or false.
    Then pass that method values that are not collisions and values that are collisions.

    Then break the if with all its conditions up into separate sub conditions and print out the results of each sub condition.
    Then look at the output to see which sub test is wrong.

  8. #8
    Ashish_jain's Avatar
    Ashish_jain is offline Member
    Join Date
    Jun 2011
    Posts
    32
    Rep Power
    0

    Default

    i also do this with boolean but no result.but thanks for support.i will check again. :)

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,253
    Rep Power
    25

    Default

    Another suggestion, reformat the conditions so that their nesting level is visually shown.
    Your code is too compact and very poorly aligned and does not show the nesting level.

Similar Threads

  1. 2D - Collision messed up
    By überfuzz in forum New To Java
    Replies: 0
    Last Post: 06-22-2011, 09:20 PM
  2. Collision in GUI 2d Game help
    By heysayjump in forum New To Java
    Replies: 7
    Last Post: 03-14-2011, 02:01 AM
  3. Really Need help with some collision detection
    By Harwad in forum New To Java
    Replies: 1
    Last Post: 01-23-2011, 12:38 AM
  4. Collision
    By shadycharacter in forum New To Java
    Replies: 0
    Last Post: 04-13-2010, 09:58 PM
  5. Replies: 0
    Last Post: 04-22-2009, 01:30 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
  •