From 5f79e8e00c3e12483365e852ede6f7efadd9405f Mon Sep 17 00:00:00 2001 From: Simon Wilkening Date: Mon, 14 Oct 2024 04:25:55 +0200 Subject: [PATCH] Added effect for not hitting ships --- .../client/gui/ParticleCreator.java | 43 +++++++++++++++++++ .../client/gui/SeaSynchronizer.java | 21 ++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/ParticleCreator.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/ParticleCreator.java index c3fb04f..6593ed2 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/ParticleCreator.java +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/ParticleCreator.java @@ -238,4 +238,47 @@ public class ParticleCreator { 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; + } + } diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/SeaSynchronizer.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/SeaSynchronizer.java index 96c6ca9..4adb17b 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/SeaSynchronizer.java +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/SeaSynchronizer.java @@ -76,9 +76,28 @@ class SeaSynchronizer extends ShipMapSynchronizer { */ @Override 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 * contains the ship model as a child so that it moves with the ship.