Package de.nameless.graphicEngine.lib

Source Code of de.nameless.graphicEngine.lib.NEParticleSpray

package de.nameless.graphicEngine.lib;

import javax.media.opengl.GL;

import de.nameless.graphicEngine.NE2DHelper;
import de.nameless.graphicEngine.NEabstractGraphicObject;
import de.nameless.graphicEngine.animation.lib.NEALiefeTimeAnimation;
import de.nameless.graphicEngine.animation.lib.NEArelativeMove;
import de.nameless.graphicEngine.animation.lib.NEArelative2DRotation;

public class NEParticleSpray extends NE2DHelper{

  private float spare;
 
  private float particleSpeed;
  private float particleSpeedRandom = 0;
 
  private NESprayable particle;
 
  private float particleSize;
  private float particleSizeRandom = 0;
 
  private float particleLifeTime = 0;
  private float particleLifeTimeRandom = 0;
 
  private float particleRotationRamdom=0;
  private float particleRotationSpeed=0;
 
  private float particleDensity = 1f;

  private float timer = 0;


  public NEParticleSpray(float spare, float particleSpeed, NESprayable particle, float particleSize) {
    super();
    this.spare = spare;
    this.particleSpeed = particleSpeed;
    this.particle = particle;
    this.particleSize = particleSize;
  }

  @Override
  public void getInPositionAndRotation(GL gl) {
    particle.setPos(x,y)
  }

  @Override
  public void performAction(float TBM) {   
    timer += TBM;     
    while(timer >= particleDensity/1000){     
        generateOneParticle();       
      timer -=particleDensity/1000;
   
  }
 
  private float generateDirection(){
    float result = (float) (this.xAngel + ( ((Math.random()-0.5)*2)*this.spare )) ;
    if (result >= Math.PI*2) {
      result -= Math.PI*2;
    } else if (result < 0 ){
      result +=  Math.PI*2;
    }   
    return result;
  }
 
  private void generateOneParticle(){
    NEabstractGraphicObject newParticle = particle.getNewParticle((float) (particleSize*(1+ ((Math.random()-0.5)*2)*particleSizeRandom)))
     
    newParticle.addAnimation(new NEArelativeMove(this.generateDirection(),(float) (this.particleSpeed * (1+ ((Math.random()-0.5)*2) * this.particleSpeedRandom)),100))
   
    if(particleRotationRamdom + particleRotationSpeed != 0){
      newParticle.addAnimation(new NEArelative2DRotation(5000,(float) (particleRotationSpeed * (1+ ((Math.random()-0.5)*2) * particleRotationRamdom))));
    }
   
    if(this.particleLifeTime!= 0){
      newParticle.addAnimation(new NEALiefeTimeAnimation((float) (this.particleLifeTime * (1+ ((Math.random()-0.5)*2) *particleLifeTimeRandom  ))) );
    }
   
    this.holdingServer.addGraphicObject(newParticle);
  }

  public void setRandom(float particleSpeedRandom, float particleSizeRandom,
      float particleLifeTimeRandom) {
    this.particleSpeedRandom = particleSpeedRandom;
    this.particleSizeRandom = particleSizeRandom;
    this.particleLifeTimeRandom = particleLifeTimeRandom;
  }



  /**
   * @param particleDensity the particleDensity to set
   */
  public void setParticleDensity(float particleDensity) {
    this.particleDensity = particleDensity;
  }



  /**
   * @param particleLifeTime the particleLifeTime to set
   */
  public void setParticleLifeTime(float particleLifeTime) {
    this.particleLifeTime = particleLifeTime;
  }
 
  public void setParticleRotation(float speed, float speedRandom){
    this.particleRotationSpeed = speed;
    this.particleRotationRamdom = speedRandom;
  }
 
}
TOP

Related Classes of de.nameless.graphicEngine.lib.NEParticleSpray

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.