mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-25 05:49:44 +01:00
Added effect for not hitting ships
This commit is contained in:
parent
03adf45167
commit
5f79e8e00c
@ -238,4 +238,47 @@ public class ParticleCreator {
|
|||||||
|
|
||||||
return smokeEmitter;
|
return smokeEmitter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a one-time water splash particle emitter.
|
||||||
|
*
|
||||||
|
* @return a configured one-time water splash particle emitter
|
||||||
|
*/
|
||||||
|
public ParticleEmitter createWaterSplash() {
|
||||||
|
// Create a new particle emitter for the splash effect
|
||||||
|
ParticleEmitter waterSplash = new ParticleEmitter("WaterSplash", Type.Triangle, 30);
|
||||||
|
|
||||||
|
// Set the shape of the emitter, making particles emit from a point or small area
|
||||||
|
waterSplash.setShape(new EmitterSphereShape(Vector3f.ZERO, 0.2f));
|
||||||
|
|
||||||
|
// Start and end colors for water (blue, fading out)
|
||||||
|
waterSplash.setStartColor(new ColorRGBA(0.4f, 0.4f, 1f, 1f)); // Light blue at start
|
||||||
|
waterSplash.setEndColor(new ColorRGBA(0.4f, 0.4f, 1f, 0f)); // Transparent at the end
|
||||||
|
|
||||||
|
// Particle size: small at start, larger before fading out
|
||||||
|
waterSplash.setStartSize(0.1f);
|
||||||
|
waterSplash.setEndSize(0.3f);
|
||||||
|
|
||||||
|
// Particle lifespan (how long particles live)
|
||||||
|
waterSplash.setLowLife(0.5f);
|
||||||
|
waterSplash.setHighLife(1f);
|
||||||
|
|
||||||
|
// Gravity: Pull the water particles downwards
|
||||||
|
waterSplash.setGravity(0, -9.81f, 0); // Earth's gravity simulation
|
||||||
|
|
||||||
|
// Velocity: Give particles an initial burst upward (simulates splash)
|
||||||
|
waterSplash.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 3, 0));
|
||||||
|
waterSplash.getParticleInfluencer().setVelocityVariation(0.6f); // Add randomness to splash
|
||||||
|
|
||||||
|
// Set how many particles are emitted per second (0 to emit all particles at once)
|
||||||
|
waterSplash.setParticlesPerSec(0);
|
||||||
|
|
||||||
|
// Load a texture for the water splash (assuming a texture exists at this path)
|
||||||
|
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||||
|
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Splash/splash.png"));
|
||||||
|
waterSplash.setMaterial(mat);
|
||||||
|
|
||||||
|
return waterSplash;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -76,9 +76,28 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Spatial visit(Shot shot) {
|
public Spatial visit(Shot shot) {
|
||||||
return shot.isHit() ? handleHit(shot) : createCylinder(shot);
|
return shot.isHit() ? handleHit(shot) : handleMiss(shot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles a miss by representing it with a blue cylinder
|
||||||
|
* and attaching a water splash effect to it.
|
||||||
|
* @param shot the shot to be processed
|
||||||
|
* @return a Spatial simulating a miss with water splash effect
|
||||||
|
*/
|
||||||
|
private Spatial handleMiss(Shot shot) {
|
||||||
|
Node shotNode = new Node("ShotNode");
|
||||||
|
Geometry shotCylinder = createCylinder(shot);
|
||||||
|
shotNode.attachChild(shotCylinder);
|
||||||
|
ParticleEmitter waterSplash = particlecreator.createWaterSplash();
|
||||||
|
waterSplash.setLocalTranslation(shot.getY() + 0.5f, 0f, shot.getX() + 0.5f);
|
||||||
|
shotNode.attachChild(waterSplash);
|
||||||
|
waterSplash.emitAllParticles();
|
||||||
|
|
||||||
|
return shotNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a hit by attaching its representation to the node that
|
* Handles a hit by attaching its representation to the node that
|
||||||
* contains the ship model as a child so that it moves with the ship.
|
* contains the ship model as a child so that it moves with the ship.
|
||||||
|
Loading…
Reference in New Issue
Block a user