package de.sopa.drawing;

import org.andengine.entity.IEntityFactory;
import org.andengine.entity.modifier.AlphaModifier;
import org.andengine.entity.modifier.RotationModifier;
import org.andengine.entity.particle.ParticleSystem;
import org.andengine.entity.particle.initializer.GravityParticleInitializer;
import org.andengine.entity.particle.initializer.VelocityParticleInitializer;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.color.Color;

/**
 * @author Raphael Schilling - raphaelschiling@gmail.com
 */
public class ConfettiParticleSystem extends ParticleSystem<Rectangle> {
    public ConfettiParticleSystem(final VertexBufferObjectManager vbom, float cameraWidth) {
        super(createEntityFactory(vbom), new HorizontalLineParticleEmitter(0, 0, cameraWidth), 50f, 100f, 200);
        addParticleInitializer(new VelocityParticleInitializer<Rectangle>(-20, 20, 250, 300));
        addParticleInitializer(new GravityParticleInitializer<Rectangle>());
    }

    private static IEntityFactory<Rectangle> createEntityFactory(final VertexBufferObjectManager vbom) {
        return new IEntityFactory<Rectangle>() {
            @Override
            public Rectangle create(final float pX, final float pY) {
                Color colorMap[] = {new Color(1f, 0f, 0f), //rot
                                    new Color(0.07f, 0.84f, 0.12f),
                                    new Color(0.24f, 0f, 0.87f),
                                    new Color(1f, 1f, 0f)};

                Rectangle rectangle = new Rectangle(pX, pY, 30, 15, vbom);
                rectangle.setColor(colorMap[((int) (Math.random() * 4))]);
                rectangle.registerEntityModifier(new RotationModifier(7f, (float) Math.random() * 360,
                        (7 - (float) Math.random() * 15) * 360));
                rectangle.registerEntityModifier(new AlphaModifier(4f, 0.7f, 0f));
                return rectangle;
            }};
    }
}

@@ -587,16 +587,64 @@
 ail.com%0A
+ * @author David Schilling - davejs92@gmail.com%0A
  */%0Apubl
@@ -711,16 +711,323 @@
 ngle%3E %7B%0A
+%0A    private static final Color%5B%5D COLOR_MAP = %7B  new Color(1f, 0f, 0f),%0A                                                new Color(0.07f, 0.84f, 0.12f),%0A                                                new Color(0.24f, 0f, 0.87f),%0A                                                new Color(1f, 1f, 0f)%0A    %7D;%0A%0A
     publ
@@ -1107,24 +1107,25 @@
 eraWidth) %7B%0A
+%0A
         supe
@@ -1504,24 +1504,25 @@
 ger vbom) %7B%0A
+%0A
         retu
@@ -1653,266 +1653,8 @@
 Y) %7B
-%0A                Color colorMap%5B%5D = %7Bnew Color(1f, 0f, 0f), //rot%0A                                    new Color(0.07f, 0.84f, 0.12f),%0A                                    new Color(0.24f, 0f, 0.87f),%0A                                    new Color(1f, 1f, 0f)%7D;
 %0A%0A  
@@ -1765,43 +1765,47 @@
 lor(
-colorMap%5B((int) (Math.random() * 4)
+COLOR_MAP%5BgetRandomBetweenZeroAndThree(
 )%5D);
@@ -2112,11 +2112,116 @@
 %7D;%0A    %7D
+%0A%0A    private static int getRandomBetweenZeroAndThree() %7B%0A        return (int) (Math.random() * 4);%0A    %7D
 %0A%7D%0A

refactor confetti particle system