Results 1 to 8 of 8
  1. #1
    Luff is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default Check The Collisions

    Hello, I'm pretty new to Java, I used to use C++ and SDL before.
    But anyway.

    My problem is like this, I'm doing a Shmup and it all went well until, I were going to the collisions. I' using 2 CopyOnWriteArrayLists just like this:

    Java Code:
    CopyOnWriteArrayList<Bullet> Bullets = new CopyOnWriteArrayList<Bullet>();
    CopyOnWriteArrayList<Square> Enemies = new CopyOnWriteArrayList<Square>();
    It all went smooth creating them:

    Java Code:
    Bullet Bullet = new Bullet(Player.getX() + 4, Player.getY() - 8, 8);
    Bullets.add(Bullet);
    And drawing them:

    Java Code:
    for (Bullet bullets : Bullets) {
      B.setColor(Color.white);
      B.fillRect(bullets.getX(), bullets.getY(), bullets.getWidth(), bullets.getHeight());
    }
    But now for checking collisions between those two, Bullets and Enemies I have no AJD. I can't do one of those for loops, so I got no clue.

    Plz help, and comment if you need more info.

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

    Default

    I have no AJD
    What is AJD?
    checking collisions
    Is a collision when the boundary of one object touches/crosses the boundary of another?

  3. #3
    Luff is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    Oh, AJD = Idea - e;

    I got these Rectangle things thats return a Rectangle which is called getBounds.
    I've done collisions before like this:

    Java Code:
    if (me.getBounds().intersects(you.getBounds()) {
    But that isn't working here.

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

    Default

    English is the preferred language here. Lots of English as a second language posters.

    that isn't working here
    Can you explain?
    How are the boundaries of the objects in question stored? The code you posted uses the fillRect() method which makes one think the objects are rectangles.

  5. #5
    Luff is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    In my Two classes 'Square' n' 'Bullet' I've got these functions? Is it functions when they return something? Oh well, I uses something like this:

    Java Code:
    public Rectangle getBounds() {
      return new Rectangle(getX(), getY(), getWidth(), getHeight());
    }
    That isn't the problem I guess, the problem is that I don't know how to check the collision with only one of those two instances in the Bullets and Enemies.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    problem is that I don't know how to check the collision with only one of those two instances
    If you only have one instance of an object. Does mean there are no other objects and hence there can not be any collisions? Can you explain what you mean?

    The gross way to check for collisions would be to go thru all the enemy's one by one and see it it collides with each bullet one by one.
    Another way would be to only check the object(s) that moved to see if they have collided with something. No sense checking something that hasn't moved.

  7. #7
    Luff is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    Yes, but via that for loop I only can check for instances thats out of the ArrayList. Äh, I got no idea how to explain it....

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    I got no idea how to explain it..
    That makes it hard to make recommendations on how to do it.

Similar Threads

  1. how to check jsp or servlet?
    By waqar100 in forum New To Java
    Replies: 2
    Last Post: 06-04-2010, 04:39 AM
  2. check registry key
    By anilkumar_vist in forum Advanced Java
    Replies: 5
    Last Post: 11-22-2009, 04:52 PM
  3. Don't know what to check for
    By Chasingxsuns in forum New To Java
    Replies: 8
    Last Post: 08-26-2009, 05:59 AM
  4. pls check it
    By aRTx in forum New To Java
    Replies: 0
    Last Post: 03-24-2009, 02:35 PM
  5. Check box tag
    By elizaabru in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-26-2008, 02:37 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
  •