added a fire effect for hit ships
this will now display a burning fire at the position where the ships was hit and displays it until thge ship is removed.
This commit is contained in:
@@ -23,10 +23,10 @@ map.own=maps/map1.json
|
||||
# 2, 3
|
||||
# defines four shots, namely at the coordinates
|
||||
# (x=2, y=0), (x=2, y=1), (x=2, y=2), and (x=2, y=3)
|
||||
robot.targets=2, 0,\
|
||||
2, 1,\
|
||||
2, 2,\
|
||||
2, 3
|
||||
robot.targets=2, 3,\
|
||||
2, 4,\
|
||||
2, 5,\
|
||||
2, 8
|
||||
#
|
||||
# Delay in milliseconds between each shot fired by the RobotClient.
|
||||
robot.delay=500
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* This class is used to handle the effects for impacts
|
||||
@@ -36,32 +38,68 @@ public EffectHandler(Application app) {
|
||||
}
|
||||
|
||||
/**
|
||||
* this method is used to create a hit effect at a position
|
||||
* creates a new HitEffect
|
||||
*
|
||||
* @param battleshipNode the node of the battleship where the effect should be attached to
|
||||
* @param battleshipNode the node of the ship
|
||||
* @param shot the shot which triggered the effect
|
||||
*/
|
||||
public void createHitEffect(Node battleshipNode, Shot shot) {
|
||||
ParticleEmitter hitEffect = new ParticleEmitter("HitEffect", Type.Triangle,30);
|
||||
hitEffect.setMaterial(particleMat);
|
||||
hitEffect.setImagesX(2);
|
||||
hitEffect.setImagesY(2);
|
||||
hitEffect.setStartColor(ColorRGBA.Orange);
|
||||
hitEffect.setEndColor(ColorRGBA.Red);
|
||||
hitEffect.getParticleInfluencer().setInitialVelocity(new Vector3f(0,1,0));
|
||||
hitEffect.setStartSize(0.45f);
|
||||
hitEffect.setEndSize(0.1f);
|
||||
hitEffect.setGravity(0, -0.5f, 0);
|
||||
hitEffect.setLowLife(1f);
|
||||
hitEffect.setHighLife(2f);
|
||||
hitEffect.setParticlesPerSec(0);
|
||||
hitEffect.setLocalTranslation(shot.getY() + 0.5f, 0 , shot.getX() + 0.5f);
|
||||
LOGGER.log(Level.DEBUG, "Created HitEffect at {0}", hitEffect.getLocalTranslation().toString());
|
||||
createFieryEffect(battleshipNode,shot, "HitEffect", 30, 0.45f, 0.1f, -0.5f, 1f , 2f, false);
|
||||
}
|
||||
|
||||
hitEffect.emitAllParticles();
|
||||
/**
|
||||
* creates a new FireEffect
|
||||
*
|
||||
* @param battleshipNode the node of the ship
|
||||
* @param shot the shot which triggered the effect
|
||||
*/
|
||||
public void createFireEffect(Node battleshipNode, Shot shot) {
|
||||
createFieryEffect(battleshipNode, shot, "FireEffect", 30, 0.1f, 0.05f, -0.9f, 1f , 2f, true);
|
||||
}
|
||||
|
||||
battleshipNode.attachChild(hitEffect);
|
||||
/**
|
||||
* creates a fiery type hit effect
|
||||
*
|
||||
* @param battleshipNode the ship to which the effect should be attached
|
||||
* @param shot the shot that triggered the effect
|
||||
* @param name the name of the particle emitter
|
||||
* @param numOfParticle the overall numberOfParticles
|
||||
* @param startSize the start size of the particles
|
||||
* @param endSize the end size of the particles
|
||||
* @param gravity the gravity of the particles
|
||||
* @param lowLife the lowest lifetime of a particle
|
||||
* @param highLife the maximum lifetime of a particle
|
||||
* @param loop if the effect should be looped
|
||||
*/
|
||||
public void createFieryEffect(Node battleshipNode, Shot shot, String name, int numOfParticle, float startSize, float endSize, float gravity,
|
||||
float lowLife, float highLife, boolean loop) {
|
||||
ParticleEmitter fieryEffect = new ParticleEmitter(name, Type.Triangle, numOfParticle);
|
||||
fieryEffect.setMaterial(particleMat);
|
||||
fieryEffect.setImagesX(2);
|
||||
fieryEffect.setImagesY(2);
|
||||
fieryEffect.setStartColor(ColorRGBA.Orange);
|
||||
fieryEffect.setEndColor(ColorRGBA.Red);
|
||||
fieryEffect.getParticleInfluencer().setInitialVelocity(new Vector3f(0,1,0));
|
||||
fieryEffect.setStartSize(startSize);
|
||||
fieryEffect.setEndSize(endSize);
|
||||
fieryEffect.setGravity(0, gravity, 0);
|
||||
fieryEffect.setLowLife(lowLife);
|
||||
fieryEffect.setHighLife(highLife);
|
||||
|
||||
hitEffect.addControl(new EffectControl(hitEffect, battleshipNode));
|
||||
if(!loop) {
|
||||
fieryEffect.setLocalTranslation(shot.getY() + 0.5f, 0 , shot.getX() + 0.5f);
|
||||
fieryEffect.setParticlesPerSec(0);
|
||||
fieryEffect.emitAllParticles();
|
||||
} else {
|
||||
fieryEffect.setLocalTranslation(shot.getY() + 0.5f, 0 , shot.getX() + 0.5f);
|
||||
fieryEffect.getLocalTranslation().subtractLocal(battleshipNode.getLocalTranslation());
|
||||
fieryEffect.setParticlesPerSec(10);
|
||||
}
|
||||
|
||||
battleshipNode.attachChild(fieryEffect);
|
||||
LOGGER.log(Level.DEBUG, "Created {0} at {1}", name ,fieryEffect.getLocalTranslation().toString());
|
||||
|
||||
fieryEffect.addControl(new EffectControl(fieryEffect, battleshipNode));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -82,6 +82,7 @@ private Spatial handleHit(Shot shot) {
|
||||
final Node shipNode = requireNonNull((Node) getSpatial(ship), "Missing ship node");
|
||||
|
||||
effectHandler.createHitEffect(shipNode, shot);
|
||||
effectHandler.createFireEffect(shipNode, shot);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user