diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/ParticleEffectFactory.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/ParticleEffectFactory.java index bd84e85..f0a8364 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/ParticleEffectFactory.java +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/ParticleEffectFactory.java @@ -240,4 +240,46 @@ public class ParticleEffectFactory { 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 a328cc2..fc2a538 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 @@ -75,16 +75,33 @@ 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 = particleFactory.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. * * @param shot a hit - * @return always null to prevent the representation from being attached - * to the items node as well + * @return always null to prevent the representation from being attached to the items node as well */ private Spatial handleHit(Shot shot) { final Battleship ship = requireNonNull(map.findShipAt(shot), "Missing ship"); @@ -131,7 +148,7 @@ class SeaSynchronizer extends ShipMapSynchronizer { shockwave.emitAllParticles(); flame.emitAllParticles(); roundSpark.emitAllParticles(); - + return null; } @@ -246,7 +263,13 @@ class SeaSynchronizer extends ShipMapSynchronizer { return model; } - + + /** + * Creates a detailed 3D model to represent a small tug boat. + * + * @param ship the battleship to be represented + * @return the spatial representing a small tug boat + */ private Spatial createSmallship(Battleship ship) { final Spatial model = app.getAssetManager().loadModel(BOAT_SMALL_MODEL); @@ -257,6 +280,12 @@ class SeaSynchronizer extends ShipMapSynchronizer { return model; } + /** + * Creates a detailed 3D model to represent a "German WWII UBoat". + * + * @param ship the battleship to be represented + * @return the spatial representing the "German WWII UBoat" + */ private Spatial createCV(Battleship ship) { final Spatial model = app.getAssetManager().loadModel(CV_MODEL); @@ -268,6 +297,12 @@ class SeaSynchronizer extends ShipMapSynchronizer { return model; } + /** + * Creates a detailed 3D model to represent a battleship. + * + * @param ship the battleship to be represented + * @return the spatial representing a battleship + */ private Spatial createBattle(Battleship ship) { final Spatial model = app.getAssetManager().loadModel(BATTLE_MODEL); diff --git a/Projekte/battleship/client/src/main/resources/Effects/Splash/splash.png b/Projekte/battleship/client/src/main/resources/Effects/Splash/splash.png new file mode 100644 index 0000000..62856bd Binary files /dev/null and b/Projekte/battleship/client/src/main/resources/Effects/Splash/splash.png differ