Android Open Source - libgdx-demo-pax-britannica Explosion Particle Emitter






From Project

Back to project page libgdx-demo-pax-britannica.

License

The source code is released under:

Copyright (c) 2010 Ben Abraham, Renaud B?dard, Henk Boom, Daniel Burton, Matthew Gallant Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated ...

If you think the Android project libgdx-demo-pax-britannica listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.swagner.paxbritannica.particlesystem;
/*from ww w . jav a  2s.co  m*/
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;

import de.swagner.paxbritannica.GameInstance;
import de.swagner.paxbritannica.Resources;

public class ExplosionParticleEmitter extends ParticleEmitter {

  public ExplosionParticleEmitter() {
    super();

    life = 0.5f;
    damping =1f;
    delta_scale = 1.0f;

    set(Resources.getInstance().explosion);
  }

  public void addParticle(Vector2 position, float scale) {
    super.addParticle(position, new Vector2(0,0), life, scale);
  }

  public void addBigExplosion(Vector2 position) {
    delta_scale = 5;
    addParticle(position, 0.5f);
    Vector2 random = new Vector2(MathUtils.cos((float) ((MathUtils.random() * MathUtils.PI * 2f) * Math.sqrt(MathUtils.random()))),
        (float) (MathUtils.sin(MathUtils.random() * MathUtils.PI * 2f) * Math.sqrt(MathUtils.random())));
    for (int i = 1; i <= 20; ++i) {
      Vector2 vel = new Vector2().set(random).add(random);
      Vector2 velp = new Vector2().set(vel).scl(i / 20.f * 2.f);
      Vector2 offset = new Vector2().set(random).scl(10);
      GameInstance.getInstance().sparkParticles.addLaserExplosion(new Vector2(position.x + offset.x, position.y + offset.y), velp);
    }
    for (int i = 1; i <= 5; ++i) {
      Vector2 vel = new Vector2(MathUtils.random() * 2 - 1, MathUtils.random() * 2 - 1).scl(4);
      Vector2 offset = new Vector2().set(random).scl(3);
      GameInstance.getInstance().sparkParticles.addLaserExplosion(new Vector2(position.x + offset.x, position.y + offset.y), vel);
    }
    for (int i = 1; i <= 50; ++i) {
      Vector2 offset = new Vector2().set(random).scl(17);
      GameInstance.getInstance().bigBubbleParticles.addParticle(new Vector2(position.x + offset.x, position.y + offset.y));
    }
  }

  public void addMediumExplosion(Vector2 position) {
    delta_scale = 3;
    addParticle(position, 0.4f);
    Vector2 random = new Vector2(MathUtils.cos((float) ((MathUtils.random() * MathUtils.PI * 2f) * Math.sqrt(MathUtils.random()))),
        (float) (MathUtils.sin(MathUtils.random() * MathUtils.PI * 2f) * Math.sqrt(MathUtils.random())));
    for (int i = 1; i <= 10; ++i) {
      Vector2 vel = new Vector2().set(random).add(random);
      Vector2 velp = new Vector2().set(vel).scl(i / 20.f * 2.f);
      Vector2 offset = new Vector2().set(random).scl(10);
      GameInstance.getInstance().sparkParticles.addLaserExplosion(new Vector2(position.x + offset.x, position.y + offset.y), velp);
    }
    for (int i = 1; i <= 3; ++i) {
      Vector2 vel = new Vector2(MathUtils.random() * 2 - 1, MathUtils.random() * 2 - 1).scl(3);
      Vector2 offset = new Vector2().set(random).scl(3);
      GameInstance.getInstance().sparkParticles.addLaserExplosion(new Vector2(position.x + offset.x, position.y + offset.y), vel);
    }
    for (int i = 1; i <= 20; ++i) {
      Vector2 offset = new Vector2().set(random).scl(2);
      GameInstance.getInstance().bigBubbleParticles.addParticle(new Vector2(position.x + offset.x, position.y + offset.y));
    }
  }

  public void addSmallExplosion(Vector2 position) {
    delta_scale = 2;
    addParticle(position, 0.3f);
    Vector2 random = new Vector2(MathUtils.cos((float) ((MathUtils.random() * MathUtils.PI * 2f) * Math.sqrt(MathUtils.random()))),
        (float) (MathUtils.sin(MathUtils.random() * MathUtils.PI * 2f) * Math.sqrt(MathUtils.random())));
    for (int i = 1; i <= 2; ++i) {
      Vector2 vel = new Vector2().set(random).add(random);
      Vector2 velp = new Vector2().set(vel).scl(i / 20.f * 2.f);
      Vector2 offset = new Vector2().set(random).scl(10);
      GameInstance.getInstance().sparkParticles.addLaserExplosion(new Vector2(position.x + offset.x, position.y + offset.y), velp);
    }
    for (int i = 1; i <= 2; ++i) {
      Vector2 vel = new Vector2(MathUtils.random() * 2 - 1, MathUtils.random() * 2 - 1).scl(2);
      Vector2 offset = new Vector2().set(random).scl(3);
      GameInstance.getInstance().sparkParticles.addLaserExplosion(new Vector2(position.x + offset.x, position.y + offset.y), vel);
    }
    for (int i = 1; i <= 10; ++i) {
      Vector2 offset = new Vector2().set(random).scl(2);
      GameInstance.getInstance().bigBubbleParticles.addParticle(new Vector2(position.x + offset.x, position.y + offset.y));
    }
  }

  public void addTinyExplosion(Vector2 position) {
    delta_scale = 1;
    addParticle(position, 0.1f);
    Vector2 random = new Vector2(MathUtils.cos((float) ((MathUtils.random() * MathUtils.PI * 2f) * Math.sqrt(MathUtils.random()))),
        (float) (MathUtils.sin(MathUtils.random() * MathUtils.PI * 2f) * Math.sqrt(MathUtils.random())));
    for (int i = 1; i <= 1; ++i) {
      Vector2 vel = new Vector2().set(random).add(random);
      Vector2 velp = new Vector2().set(vel).scl(i / 20.f * 2.f);
      Vector2 offset = new Vector2().set(random).scl(10);
      GameInstance.getInstance().sparkParticles.addLaserExplosion(new Vector2(position.x + offset.x, position.y + offset.y), velp);
    }
    for (int i = 1; i <= 1; ++i) {
      Vector2 vel = new Vector2(MathUtils.random() * 2 - 1, MathUtils.random() * 2 - 1);
      Vector2 offset = new Vector2().set(random).scl(3);
      GameInstance.getInstance().sparkParticles.addLaserExplosion(new Vector2(position.x + offset.x, position.y + offset.y), vel);
    }
    for (int i = 1; i <= 5; ++i) {
      Vector2 offset = new Vector2().set(random).scl(17);
      GameInstance.getInstance().bigBubbleParticles.addParticle(new Vector2(position.x + offset.x, position.y + offset.y));
    }
  }
}




Java Source Code List

de.swagner.paxbritannica.Bullet.java
de.swagner.paxbritannica.Collision.java
de.swagner.paxbritannica.Constants.java
de.swagner.paxbritannica.DefaultScreen.java
de.swagner.paxbritannica.GameInstance.java
de.swagner.paxbritannica.GameScreen.java
de.swagner.paxbritannica.IOSLauncher.java
de.swagner.paxbritannica.PaxBritannica.java
de.swagner.paxbritannica.Resources.java
de.swagner.paxbritannica.Ship.java
de.swagner.paxbritannica.Targeting.java
de.swagner.paxbritannica.android.AndroidLauncher.java
de.swagner.paxbritannica.background.BackgroundFXRenderer.java
de.swagner.paxbritannica.background.Debris.java
de.swagner.paxbritannica.background.Fish.java
de.swagner.paxbritannica.bomber.Bomb.java
de.swagner.paxbritannica.bomber.BomberAI.java
de.swagner.paxbritannica.bomber.Bomber.java
de.swagner.paxbritannica.client.HtmlLauncher.java
de.swagner.paxbritannica.desktop.DesktopLauncher.java
de.swagner.paxbritannica.factory.EasyEnemyProduction.java
de.swagner.paxbritannica.factory.FactoryProduction.java
de.swagner.paxbritannica.factory.HardEnemyProduction.java
de.swagner.paxbritannica.factory.MediumEnemyProduction.java
de.swagner.paxbritannica.factory.PlayerProduction.java
de.swagner.paxbritannica.factory.Production.java
de.swagner.paxbritannica.fighter.FighterAI.java
de.swagner.paxbritannica.fighter.Fighter.java
de.swagner.paxbritannica.fighter.Laser.java
de.swagner.paxbritannica.frigate.FrigateAI.java
de.swagner.paxbritannica.frigate.Frigate.java
de.swagner.paxbritannica.frigate.MissileAI.java
de.swagner.paxbritannica.frigate.Missile.java
de.swagner.paxbritannica.help.Help.java
de.swagner.paxbritannica.mainmenu.Countdown.java
de.swagner.paxbritannica.mainmenu.FactorySelector.java
de.swagner.paxbritannica.mainmenu.MainMenu.java
de.swagner.paxbritannica.particlesystem.BigBubbleParticleEmitter.java
de.swagner.paxbritannica.particlesystem.BubbleParticleEmitter.java
de.swagner.paxbritannica.particlesystem.ExplosionParticleEmitter.java
de.swagner.paxbritannica.particlesystem.ParticleEmitter.java
de.swagner.paxbritannica.particlesystem.Particle.java
de.swagner.paxbritannica.particlesystem.SparkParticleEmitter.java
de.swagner.paxbritannica.settings.Settings.java