Question

So I have and ArrayList of objects (say Items) and i have another object(say user). so I want to be able to search for equality (or other Booleans) between user.element and the arrays Item.element and would also like to be to recall and display information from the Item.element that rings true to the boolean.

I'd post code but its all a bunch of craziness that hasn't worked.

would i be better served to have the objects in a different kind of array?

if it matters the 2 objects are descended from the same class okay so this is what i have tried

public boolean isSomethingThere(GameObject user) {
    for(int i=0; i; i++) {
        if{theseWalls[i].position=user.position) {
            return true;
        }
    }
}

also tried for the body if (theseWall.position.contains(user.position));

i would also like to eventually in this be able to so the wall.name of the wall that was the same as the user

Was it helpful?

Solution

For a few of my games what i do is this:

Hero hero; //User
ArrayList<Aliens> aliens //ArrayList of enemies

Lets say I want to check if they are colliding!

for(i = 0; i < aliens.size(); i++){
    Aliens a = (Aliens) aliens.get(i);  // <-- This might be something you want to do
    if(hero.getBounds().intersects(a.getBounds())
        kill();
    else
        a.remove(i);
}

Now this is just an example but I am sure you should be able to use this in your program! I could help a bit more if you could provide more of your code!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top