So I'm creating a simple game where you play as a white star attacking ghosts by colliding with them, if its an immortal ghost your particle trail gets either shorter or resets (as seen in the code) My problem is that the collision with the particle trails doesn't seem to work properly, it only collides if the ghost hits the very tail end of it, when it should do for any where on the tail but the head, and when it does hit the tail end, even though I remove the ghost from the list, it seems to run through the calculations more than once, for example, where you see `score += 5' instead anywhere between 100 and 500 gets added.
for (int i = 0; i < EntityHandler.getEnemies().size(); i++) {
Enemy e = EntityHandler.getEnemies().get(i);
if (collidesWith(e)) {
if (e.getType() == GHOST_IMMORTAL) {
trailLife = 100;
score -= 100;
} else {
score += 15;
trailLife -= 5;
}
EntityHandler.removeEnemy(e);
}
for (int k = 0; k < trails.size(); k++) {
ParticleTrail pt = trails.get(i);
if (pt.intersects(e.getBounds())) {
if (e.getType() == GHOST_IMMORTAL) {
trailLife += 20;
score -= 20; //instead takes away 500 if at tail end, else it doesnt do anything
} else score += 5; //instead adds 200-500 if at tail end, else nothing happens
EntityHandler.removeEnemy(e);
}
}
}
As for how the particle trail is being created, in case that has something to do with it:
@Override
public void tick() {
if (alpha > speed) alpha -= speed;
else dead = true;
}
@Override
public void render(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setComposite(Util.makeTransparent(alpha));
g.setColor(color);
drawShape(g); //Renderer.fillStar(g, (int) x, (int) y, PLAYER_PRONG_RADIUS, radius, PLAYER_PRONGS);
//Renderer.fillRegularPolygon(g, (int) x, (int) y, radius, PLAYER_SIDES);
g2d.setComposite(Util.makeTransparent(ALPHA_VISIBLE));
}
And here is the transparent making method in the 'Util' class I created:
public static AlphaComposite makeTransparent(float alpha) {
int type = AlphaComposite.SRC_OVER;
return AlphaComposite.getInstance(type, alpha);
}
Here's a picture of the application: