#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    belgium
    Posts
    116
    Rep Power
    8

    My problem with multiple collision detection (Java)


    Hello,

    i don't know how to explain my problem so i've called it:
    "my problem with multiple collision detection".

    The idea:
    you are a guy/girl and need kill all evil aliens.

    But the problem is how i know when that guy / girl shoots an alien.
    so with other words how do i know when there is a collision between a bullet and an alien.Let's say that there are 50 aliens
    and you have unlimited bullets.
    When you make a game like pong it's easy because you only have 3 objects.
    Do i need to write this like 70000000000 times?
    Code:
    bullet[0].intersects(evilAlienNR1);
    I hope not

    Help me java-game-programmers you guys are my only hope

    William
  2. #2
  3. No Profile Picture
    rebel with a cause
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2004
    Location
    The Batsh!t Crazy State.
    Posts
    5,817
    Rep Power
    3461
    This is why we use lists of all objects in games.
    Dear God. What is it like in your funny little brains? It must be so boring.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    belgium
    Posts
    116
    Rep Power
    8
    Can I ask you how i'm supposed to do that
    ArrayList?
    Code:
    ArrayList alList1 = new ArrayList();
    or some kind of ingenious class.
    Code:
    class bullet{}
    Code:
    class alien{}
    someone help me *puppy face*

    William
  6. #4
  7. Psycho Canadian
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Jan 2001
    Location
    Canada
    Posts
    4,846
    Rep Power
    635
    should I move this to Java forum?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    belgium
    Posts
    116
    Rep Power
    8
    sure no problem
  10. #6
  11. No Profile Picture
    rebel with a cause
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2004
    Location
    The Batsh!t Crazy State.
    Posts
    5,817
    Rep Power
    3461
    Ok. Your aliens. Do you have 50 different instances of alien or do you have them in an array or a list? If they're in a list (or array) then you can loop through them for each bullet using a nested loop.

    Collections
    Dear God. What is it like in your funny little brains? It must be so boring.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    belgium
    Posts
    116
    Rep Power
    8
    k thanks going to tryout the collections idea

    William
  14. #8
  15. Kage Bunshin
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2005
    Location
    The Seven Seas Of Rhye
    Posts
    930
    Rep Power
    422
    Is this for a project? If not, I would try something like GTGE.
    It has built in collision detection =D

    EDIT: w00t, 300th post =D

    Comments on this post

    • william_nagels agrees : thanks man
    "Java makes impossible things possible, but makes easy things difficult." - Somebody
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Location
    belgium
    Posts
    116
    Rep Power
    8
    thanks man

    William

IMN logo majestic logo threadwatch logo seochat tools logo