mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-25 03:29:44 +01:00
added a miss effect
This commit is contained in:
parent
dcc7cf9c20
commit
1740988629
@ -240,4 +240,46 @@ public class ParticleEffectFactory {
|
|||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,16 +75,33 @@ 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 = 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
|
* 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.
|
||||||
*
|
*
|
||||||
* @param shot a hit
|
* @param shot a hit
|
||||||
* @return always null to prevent the representation from being attached
|
* @return always null to prevent the representation from being attached to the items node as well
|
||||||
* to the items node as well
|
|
||||||
*/
|
*/
|
||||||
private Spatial handleHit(Shot shot) {
|
private Spatial handleHit(Shot shot) {
|
||||||
final Battleship ship = requireNonNull(map.findShipAt(shot), "Missing ship");
|
final Battleship ship = requireNonNull(map.findShipAt(shot), "Missing ship");
|
||||||
@ -131,7 +148,7 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
|||||||
shockwave.emitAllParticles();
|
shockwave.emitAllParticles();
|
||||||
flame.emitAllParticles();
|
flame.emitAllParticles();
|
||||||
roundSpark.emitAllParticles();
|
roundSpark.emitAllParticles();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,7 +263,13 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
|||||||
|
|
||||||
return model;
|
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) {
|
private Spatial createSmallship(Battleship ship) {
|
||||||
final Spatial model = app.getAssetManager().loadModel(BOAT_SMALL_MODEL);
|
final Spatial model = app.getAssetManager().loadModel(BOAT_SMALL_MODEL);
|
||||||
|
|
||||||
@ -257,6 +280,12 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
|||||||
return model;
|
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) {
|
private Spatial createCV(Battleship ship) {
|
||||||
final Spatial model = app.getAssetManager().loadModel(CV_MODEL);
|
final Spatial model = app.getAssetManager().loadModel(CV_MODEL);
|
||||||
|
|
||||||
@ -268,6 +297,12 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
|||||||
return model;
|
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) {
|
private Spatial createBattle(Battleship ship) {
|
||||||
final Spatial model = app.getAssetManager().loadModel(BATTLE_MODEL);
|
final Spatial model = app.getAssetManager().loadModel(BATTLE_MODEL);
|
||||||
|
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Loading…
Reference in New Issue
Block a user