@Override public void update() { final Iterator<CircleParticle> it = particles.iterator(); while (it.hasNext()) { final CircleParticle p = it.next(); p.update(); p.setOpacity(Math.min(255, p.getLife()) / 255); if (p.isDead()) { it.remove(); } } if (lastParticleTime <= 0) { final int leftScreen = (int) level.getMapViewport().getX(); final int rightScreen = (int) (level.getMapViewport().getX() + level.getMapViewport().getRect2D().getWidth()); final int size = MathUtils.getRandomInt(10, 20); final Color color = new Color(190, MathUtils.getRandomInt(190, 220), MathUtils.getRandomInt(190, 240)); final CircleParticle p = new CircleParticle( level, MathUtils.getRandomInt(leftScreen - 100, rightScreen + 100), -10, size, size, 255, color); p.setCollision(false); p.applyForce(new Vec2D(MathUtils.getRandomFloat(-1, 1), MathUtils.getRandomFloat(1, 3))); particles.add(p); lastParticleTime = frequency; } else { lastParticleTime--; } }
public boolean isOffScreen() { return !parentLevel.getMapViewport().intersects(getRect2D()); }