Search in sources :

Example 1 with RectangleFillParticle

use of de.gurkenlabs.litiengine.graphics.particles.RectangleFillParticle in project litiengine by gurkenlabs.

the class CustomEmitter method createNewParticle.

@Override
protected Particle createNewParticle() {
    float x;
    float y;
    float deltaX;
    float deltaY;
    float gravityX;
    float gravityY;
    float width;
    float height;
    float deltaWidth;
    float deltaHeight;
    x = this.getEmitterData().getParticleX().get();
    y = this.getEmitterData().getParticleY().get();
    deltaX = this.getEmitterData().getDeltaX().get();
    deltaY = this.getEmitterData().getDeltaY().get();
    gravityX = this.getEmitterData().getGravityX().get();
    gravityY = this.getEmitterData().getGravityY().get();
    width = this.getEmitterData().getParticleWidth().get();
    height = this.getEmitterData().getParticleHeight().get();
    deltaWidth = this.getEmitterData().getDeltaWidth().get();
    deltaHeight = this.getEmitterData().getDeltaHeight().get();
    Particle particle;
    switch(this.getEmitterData().getParticleType()) {
        case LEFTLINE:
            particle = new LeftLineParticle(width, height, this.getRandomParticleColor(), this.getRandomParticleTTL()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
            break;
        case DISC:
            particle = new OvalParticle(width, height, this.getRandomParticleColor(), this.getRandomParticleTTL()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
            break;
        case RECTANGLE:
            particle = new RectangleFillParticle(width, height, this.getRandomParticleColor(), this.getRandomParticleTTL()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
            break;
        case RECTANGLE_OUTLINE:
            particle = new RectangleOutlineParticle(width, height, this.getRandomParticleColor(), this.getRandomParticleTTL()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
            break;
        case RIGHTLINE:
            particle = new RightLineParticle(width, height, this.getRandomParticleColor(), this.getRandomParticleTTL()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
            break;
        case SHIMMER:
            particle = new ShimmerParticle(new Rectangle2D.Float(x, y, this.getWidth(), this.getHeight()), width, height, this.getRandomParticleColor()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
            break;
        case TEXT:
            particle = new TextParticle(this.getEmitterData().getParticleText(), this.getRandomParticleColor(), this.getRandomParticleTTL()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
            break;
        case SPRITE:
            Spritesheet sprite = Spritesheet.find(this.getEmitterData().getSpritesheet());
            if (sprite == null) {
                return null;
            }
            particle = new SpriteParticle(sprite.getSprite(MathUtilities.randomInRange(0, sprite.getTotalNumberOfSprites() - 1)), this.getRandomParticleTTL()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
            break;
        default:
            particle = new RectangleFillParticle(width, height, this.getRandomParticleColor(), this.getRandomParticleTTL()).setX(x).setY(y).setDeltaIncX(gravityX).setDeltaIncY(gravityY).setDeltaX(deltaX).setDeltaY(deltaY).setDeltaWidth(deltaWidth).setDeltaHeight(deltaHeight);
            break;
    }
    particle.setDeltaWidth(deltaWidth);
    particle.setDeltaHeight(deltaHeight);
    particle.setCollisionType(this.getEmitterData().getCollisionType());
    return particle;
}
Also used : Particle(de.gurkenlabs.litiengine.graphics.particles.Particle) TextParticle(de.gurkenlabs.litiengine.graphics.particles.TextParticle) RectangleFillParticle(de.gurkenlabs.litiengine.graphics.particles.RectangleFillParticle) OvalParticle(de.gurkenlabs.litiengine.graphics.particles.OvalParticle) RightLineParticle(de.gurkenlabs.litiengine.graphics.particles.RightLineParticle) ShimmerParticle(de.gurkenlabs.litiengine.graphics.particles.ShimmerParticle) RectangleOutlineParticle(de.gurkenlabs.litiengine.graphics.particles.RectangleOutlineParticle) LeftLineParticle(de.gurkenlabs.litiengine.graphics.particles.LeftLineParticle) SpriteParticle(de.gurkenlabs.litiengine.graphics.particles.SpriteParticle) RectangleFillParticle(de.gurkenlabs.litiengine.graphics.particles.RectangleFillParticle) RectangleOutlineParticle(de.gurkenlabs.litiengine.graphics.particles.RectangleOutlineParticle) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) TextParticle(de.gurkenlabs.litiengine.graphics.particles.TextParticle) SpriteParticle(de.gurkenlabs.litiengine.graphics.particles.SpriteParticle) LeftLineParticle(de.gurkenlabs.litiengine.graphics.particles.LeftLineParticle) RightLineParticle(de.gurkenlabs.litiengine.graphics.particles.RightLineParticle) OvalParticle(de.gurkenlabs.litiengine.graphics.particles.OvalParticle) ShimmerParticle(de.gurkenlabs.litiengine.graphics.particles.ShimmerParticle)

Example 2 with RectangleFillParticle

use of de.gurkenlabs.litiengine.graphics.particles.RectangleFillParticle in project litiengine by gurkenlabs.

the class FireEmitter method newParticle.

/**
 * Creates a new Particle object.
 *
 * @param color
 *          the color
 * @param life
 *          The number of movements before the new Particle decays.
 * @param maxAxisMovement
 *          the max axis movement
 */
public void newParticle(final Color color, final int life, final double maxAxisMovement) {
    final boolean randBool = Math.random() >= 0.5;
    final float x = (float) (this.getWidth() * 0.5 + Math.random() * maxAxisMovement * (randBool ? -1f : 1f));
    final float dx = (float) (Math.random() * 0.2);
    final float dy = (float) (Math.random() * 2 * -1f);
    final float gravityY = 0.0015f * (randBool ? 1f : -1f);
    final float size = (float) (4 + Math.random() * 5);
    this.addParticle(new RectangleFillParticle(size, size, color, life).setX(x).setDeltaX(dx).setDeltaY(dy).setDeltaIncY(gravityY));
}
Also used : RectangleFillParticle(de.gurkenlabs.litiengine.graphics.particles.RectangleFillParticle)

Aggregations

RectangleFillParticle (de.gurkenlabs.litiengine.graphics.particles.RectangleFillParticle)2 Spritesheet (de.gurkenlabs.litiengine.graphics.Spritesheet)1 LeftLineParticle (de.gurkenlabs.litiengine.graphics.particles.LeftLineParticle)1 OvalParticle (de.gurkenlabs.litiengine.graphics.particles.OvalParticle)1 Particle (de.gurkenlabs.litiengine.graphics.particles.Particle)1 RectangleOutlineParticle (de.gurkenlabs.litiengine.graphics.particles.RectangleOutlineParticle)1 RightLineParticle (de.gurkenlabs.litiengine.graphics.particles.RightLineParticle)1 ShimmerParticle (de.gurkenlabs.litiengine.graphics.particles.ShimmerParticle)1 SpriteParticle (de.gurkenlabs.litiengine.graphics.particles.SpriteParticle)1 TextParticle (de.gurkenlabs.litiengine.graphics.particles.TextParticle)1