Hey guys. I’m working on the collision detection for my pacman game. I’ve got the pills to load and show on the map, however, in my main class, i’m trying to make it so when the pacman touches one of the pills it removes it from the array. I don’t know the index of the pill it hit, so I can’t just do pillList.removeIndex(index)…I’ve tried a bunch of things and been searching to no avail. Any ideas?
public void update() {
//float deltaTime = Gdx.graphics.getDeltaTime();
for (Pills tempPill : map.getPillList()) {
tempPill.checkCollision(player.getRect());
if (tempPill.GetVisible() == false) {
}
}
keyInput();
player.move(map);
}
The pillList holds all of the pill objects. When the player rectangle overlaps the pill rectangle, it sets the isVisible boolean of the pill object to false…Now i’m trying to iterate through the pill list, and if the isVisible is equal to false, I want to remove the pill from the list.
I can do it like this, but it seems like this is an outdated way to do it…
for (int p = 0; p < map.getPillList().size;p++) {
map.getPillList().get(p).checkCollision(player.getRect());
if (map.getPillList().get(p).GetVisible() == false) {
map.getPillList().removeIndex(p);
}
}