Update animations and remove test setup

This commit is contained in:
Felix Koppe
2024-12-07 16:40:45 +01:00
parent 06b37584cb
commit bf84bfa0f9
7 changed files with 79 additions and 36 deletions

View File

@@ -158,7 +158,7 @@ else if(boardSelect != null) {
gameView.getBoardHandler().movePieceStartAnim(p,0); gameView.getBoardHandler().movePieceStartAnim(p,0);
//gameView.getBoardHandler().movePieceAnim(p,0, 8); //gameView.getBoardHandler().movePieceAnim(p,0, 8);
} else { } else {
gameView.getBoardHandler().throwPiece(p, Color.NAVY); gameView.getBoardHandler().throwPiece(p, Color.ARMY);
//gameView.getBoardHandler().movePieceStartAnim(p,0); //gameView.getBoardHandler().movePieceStartAnim(p,0);
} }

View File

@@ -39,6 +39,7 @@ public Explosion(MdgaApp app, Node rootNode, Vector3f location) {
this.location = location; this.location = location;
this.mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md"); this.mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
mat.setTexture("Texture", app.getAssetManager().loadTexture("Images/particle/flame.png"));
} }
/** /**
@@ -48,12 +49,14 @@ public Explosion(MdgaApp app, Node rootNode, Vector3f location) {
private void initializeEmitter() { private void initializeEmitter() {
fire = new ParticleEmitter("Effect", Type.Triangle,50); fire = new ParticleEmitter("Effect", Type.Triangle,50);
fire.setMaterial(mat); fire.setMaterial(mat);
fire.setImagesX(2);
fire.setImagesY(2);
fire.setStartColor(ColorRGBA.Yellow); fire.setStartColor(ColorRGBA.Yellow);
fire.setEndColor(ColorRGBA.Red); fire.setEndColor(ColorRGBA.Red);
fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0.2f,0.2f,4f)); fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0.2f,0.2f,4f));
fire.getParticleInfluencer().setVelocityVariation(0.4f); fire.getParticleInfluencer().setVelocityVariation(0.4f);
fire.setStartSize(0.1f); fire.setStartSize(0.7f);
fire.setEndSize(0.8f); fire.setEndSize(1.8f);
fire.setGravity(0, 0, -0.1f); fire.setGravity(0, 0, -0.1f);
fire.setLowLife(0.5f); fire.setLowLife(0.5f);
fire.setHighLife(2.2f); fire.setHighLife(2.2f);
@@ -63,14 +66,14 @@ private void initializeEmitter() {
smoke = new ParticleEmitter("Effect2", Type.Triangle,40); smoke = new ParticleEmitter("Effect2", Type.Triangle,40);
smoke.setMaterial(mat); smoke.setMaterial(mat);
smoke.setImagesX(2); smoke.setImagesX(3);
smoke.setImagesY(2); smoke.setImagesY(3);
smoke.setStartColor(ColorRGBA.DarkGray); smoke.setStartColor(ColorRGBA.DarkGray);
smoke.setEndColor(new ColorRGBA(0.05f, 0.05f, 0.05f, 1)); smoke.setEndColor(new ColorRGBA(0.05f, 0.05f, 0.05f, 1));
smoke.getParticleInfluencer().setInitialVelocity(new Vector3f(0.0f,0.0f,0.7f)); smoke.getParticleInfluencer().setInitialVelocity(new Vector3f(0.0f,0.0f,0.7f));
smoke.getParticleInfluencer().setVelocityVariation(0.5f); smoke.getParticleInfluencer().setVelocityVariation(0.5f);
smoke.setStartSize(0.2f); smoke.setStartSize(0.8f);
smoke.setEndSize(0.5f); smoke.setEndSize(1.5f);
smoke.setGravity(0, 0, -0.3f); smoke.setGravity(0, 0, -0.3f);
smoke.setLowLife(1.2f); smoke.setLowLife(1.2f);
smoke.setHighLife(5.5f); smoke.setHighLife(5.5f);

View File

@@ -33,7 +33,6 @@ public class JetAnimation {
private final float curveHeight; private final float curveHeight;
private final float animationDuration; private final float animationDuration;
private Explosion explosion; private Explosion explosion;
private final UUID id;
private Runnable actionAfter; private Runnable actionAfter;
/** /**
@@ -41,12 +40,11 @@ public class JetAnimation {
* *
* @param app The main application managing the jet animation. * @param app The main application managing the jet animation.
* @param rootNode The root node to which the jet model will be attached. * @param rootNode The root node to which the jet model will be attached.
* @param uuid A unique identifier for the animation.
* @param targetPoint The target point where the explosion will occur. * @param targetPoint The target point where the explosion will occur.
* @param curveHeight The height of the curve for the jet's flight path. * @param curveHeight The height of the curve for the jet's flight path.
* @param animationDuration The total duration of the jet animation. * @param animationDuration The total duration of the jet animation.
*/ */
public JetAnimation(MdgaApp app, Node rootNode, UUID uuid, Vector3f targetPoint, float curveHeight, float animationDuration, Runnable actionAfter) { public JetAnimation(MdgaApp app, Node rootNode, Vector3f targetPoint, float curveHeight, float animationDuration, Runnable actionAfter) {
Vector3f spawnPoint = targetPoint.add(170, 50, 50); Vector3f spawnPoint = targetPoint.add(170, 50, 50);
Vector3f controlPoint = targetPoint.add(new Vector3f(0, 0, -45)); Vector3f controlPoint = targetPoint.add(new Vector3f(0, 0, -45));
@@ -61,9 +59,7 @@ public JetAnimation(MdgaApp app, Node rootNode, UUID uuid, Vector3f targetPoint,
this.curveHeight = curveHeight; this.curveHeight = curveHeight;
this.animationDuration = animationDuration; this.animationDuration = animationDuration;
id = uuid; explosion = new Explosion(app, rootNode, targetPoint);
explosion = new Explosion(app, rootNode, nodePoint);
this.actionAfter = actionAfter; this.actionAfter = actionAfter;
} }
@@ -92,7 +88,7 @@ private void spawnJet() {
rootNode.attachChild(jetModel); rootNode.attachChild(jetModel);
} }
/** /**actionAfter
* Animates the jet along a Bezier curve path, triggers the explosion effect at the appropriate time, * Animates the jet along a Bezier curve path, triggers the explosion effect at the appropriate time,
* and performs cleanup operations after the animation completes. * and performs cleanup operations after the animation completes.
*/ */

View File

@@ -1,6 +1,9 @@
package pp.mdga.client.animation; package pp.mdga.client.animation;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager; import com.jme3.renderer.RenderManager;
@@ -29,31 +32,54 @@ public class MissileAnimation {
private final float flightTime; private final float flightTime;
private Explosion explosion; private Explosion explosion;
private Spatial missileModel; private Spatial missileModel;
private Runnable actionAfter;
private ParticleEmitter smoke;
private UUID id; private Node missileNode = new Node();
private final Material mat;
/** /**
* Constructor for the {@code MissileAnimation} class. * Constructor for the {@code MissileAnimation} class.
* *
* @param app The main application managing the missile animation. * @param app The main application managing the missile animation.
* @param rootNode The root node to which the missile model will be attached. * @param rootNode The root node to which the missile model will be attached.
* @param uuid A unique identifier for the missile animation.
* @param target The target point where the missile will explode. * @param target The target point where the missile will explode.
* @param flightTime The total flight time of the missile. * @param flightTime The total flight time of the missile.
*/ */
public MissileAnimation(MdgaApp app, Node rootNode, UUID uuid, Vector3f target, float flightTime) { public MissileAnimation(MdgaApp app, Node rootNode, Vector3f target, float flightTime, Runnable actionAfter) {
this.app = app; this.app = app;
this.rootNode = rootNode; this.rootNode = rootNode;
this.flightTime = flightTime; this.flightTime = flightTime;
this.actionAfter = actionAfter;
explosion = new Explosion(app, rootNode, target); explosion = new Explosion(app, rootNode, target);
id = uuid;
this.target = target.add(new Vector3f(1.5f, -1, 0)); this.target = target.add(new Vector3f(1.5f, -1, 0));
start = BoardHandler.gridToWorld(12, 0); start = BoardHandler.gridToWorld(12, 0);
start.add(new Vector3f(0, 0, 0)); start.add(new Vector3f(0, 0, 0));
this.mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
mat.setTexture("Texture", app.getAssetManager().loadTexture("Images/particle/vapor_cloud.png"));
smoke = new ParticleEmitter("Effect2", ParticleMesh.Type.Triangle,400);
smoke.setMaterial(mat);
smoke.setImagesX(3);
smoke.setImagesY(3);
smoke.setStartColor(ColorRGBA.DarkGray);
smoke.setEndColor(new ColorRGBA(0.05f, 0.05f, 0.05f, 1));
smoke.getParticleInfluencer().setInitialVelocity(new Vector3f(0.0f,0.0f,0.0f));
smoke.getParticleInfluencer().setVelocityVariation(0.1f);
smoke.setStartSize(0.8f);
smoke.setEndSize(1.5f);
smoke.setGravity(0, 0, -0.3f);
smoke.setLowLife(1.2f);
smoke.setHighLife(3.5f);
smoke.setParticlesPerSec(100);
missileNode.attachChild(smoke);
smoke.move(1, 0.85f, 1.0f);
} }
/** /**
@@ -77,8 +103,11 @@ private void loadMissile() {
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md"); Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture(Asset.missile.getDiffPath())); mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture(Asset.missile.getDiffPath()));
missileModel.setMaterial(mat); missileModel.setMaterial(mat);
missileModel.setLocalTranslation(start);
rootNode.attachChild(missileModel); missileNode.setLocalTranslation(start);
missileNode.attachChild(missileModel);
rootNode.attachChild(missileNode);
} }
/** /**
@@ -86,28 +115,39 @@ private void loadMissile() {
* and removes the missile model after the animation completes. * and removes the missile model after the animation completes.
*/ */
private void animateMissile() { private void animateMissile() {
missileModel.addControl(new AbstractControl() { missileNode.addControl(new AbstractControl() {
private float elapsedTime = 0; private float elapsedTime = 0;
@Override @Override
protected void controlUpdate(float tpf) { protected void controlUpdate(float tpf) {
if(elapsedTime > 6) {
endAnim();
rootNode.detachChild(missileNode);
this.spatial.removeControl(this);
}
elapsedTime += tpf; elapsedTime += tpf;
float progress = elapsedTime / flightTime; float progress = elapsedTime / flightTime;
if (progress >= 0.55) {
smoke.setParticlesPerSec(30);
}
if (progress >= 0.7) {
smoke.setParticlesPerSec(0);
}
if (progress >= 0.95f) { if (progress >= 0.95f) {
explosion.trigger(); explosion.trigger();
} }
if (progress >= 1) { if (progress >= 1) {
explosion.trigger(); explosion.trigger();
missileNode.detachChild(missileModel);
rootNode.detachChild(missileModel);
this.spatial.removeControl(this);
return;
} }
Vector3f currentPosition = computeParabolicPath(start, target, progress); Vector3f currentPosition = computeParabolicPath(start, target, progress);
missileModel.setLocalTranslation(currentPosition); missileNode.setLocalTranslation(currentPosition);
Vector3f direction = computeParabolicPath(start, target, progress + 0.01f) Vector3f direction = computeParabolicPath(start, target, progress + 0.01f)
.subtract(currentPosition) .subtract(currentPosition)
@@ -122,6 +162,10 @@ protected void controlRender(RenderManager rm, ViewPort vp) {
}); });
} }
private void endAnim(){
actionAfter.run();
}
/** /**
* Computes a position along a parabolic path at a given progress value {@code t}. * Computes a position along a parabolic path at a given progress value {@code t}.
* *

View File

@@ -35,6 +35,7 @@ public Smoke(MdgaApp app, Node rootNode, Vector3f location) {
this.location = location; this.location = location;
this.mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md"); this.mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
mat.setTexture("Texture", app.getAssetManager().loadTexture("Images/particle/vapor_cloud.png"));
} }
/** /**
@@ -46,10 +47,10 @@ private void initializeEmitter() {
fire.setMaterial(mat); fire.setMaterial(mat);
fire.setStartColor(ColorRGBA.DarkGray); fire.setStartColor(ColorRGBA.DarkGray);
fire.setEndColor(ColorRGBA.DarkGray); fire.setEndColor(ColorRGBA.DarkGray);
fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0.2f,0.2f,8f)); fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0.2f,0.2f,4f));
fire.getParticleInfluencer().setVelocityVariation(0.4f); fire.getParticleInfluencer().setVelocityVariation(0.4f);
fire.setStartSize(0.1f); fire.setStartSize(0.7f);
fire.setEndSize(0.8f); fire.setEndSize(3.8f);
fire.setGravity(0, 0, -0.1f); fire.setGravity(0, 0, -0.1f);
fire.setLowLife(0.5f); fire.setLowLife(0.5f);
fire.setHighLife(1.2f); fire.setHighLife(1.2f);
@@ -65,8 +66,8 @@ private void initializeEmitter() {
smoke.setEndColor(new ColorRGBA(0.05f, 0.05f, 0.05f, 1)); smoke.setEndColor(new ColorRGBA(0.05f, 0.05f, 0.05f, 1));
smoke.getParticleInfluencer().setInitialVelocity(new Vector3f(0.0f,0.0f,2f)); smoke.getParticleInfluencer().setInitialVelocity(new Vector3f(0.0f,0.0f,2f));
smoke.getParticleInfluencer().setVelocityVariation(0.5f); smoke.getParticleInfluencer().setVelocityVariation(0.5f);
smoke.setStartSize(0.2f); smoke.setStartSize(0.5f);
smoke.setEndSize(0.5f); smoke.setEndSize(1.5f);
smoke.setGravity(0, 0, -0.3f); smoke.setGravity(0, 0, -0.3f);
smoke.setLowLife(1.2f); smoke.setLowLife(1.2f);
smoke.setHighLife(2.5f); smoke.setHighLife(2.5f);

View File

@@ -800,7 +800,7 @@ public void throwPieceAnim(UUID uuid){
public void throwPiece(UUID uuid, Color throwColor){ public void throwPiece(UUID uuid, Color throwColor){
switch(throwColor){ switch(throwColor){
case ARMY -> throwShell(uuid); case ARMY -> throwShell(uuid);
case NAVY -> throwMissle(uuid); case NAVY -> throwMissile(uuid);
case CYBER -> throwMatrix(uuid); case CYBER -> throwMatrix(uuid);
case AIRFORCE -> throwBomb(uuid); case AIRFORCE -> throwBomb(uuid);
default -> throw new RuntimeException("invalid color"); default -> throw new RuntimeException("invalid color");
@@ -815,7 +815,7 @@ public void throwPiece(UUID uuid, Color throwColor){
private void throwBomb(UUID uuid) { private void throwBomb(UUID uuid) {
Vector3f targetPoint = pieces.get(uuid).getLocation(); Vector3f targetPoint = pieces.get(uuid).getLocation();
JetAnimation anim = new JetAnimation(app, rootNode, uuid, targetPoint, 40, 6, ()->throwPieceAnim(uuid)); JetAnimation anim = new JetAnimation(app, rootNode, targetPoint, 40, 6, ()->throwPieceAnim(uuid));
anim.start(); anim.start();
} }
@@ -832,10 +832,10 @@ private void throwMatrix(UUID uuid) {
})); }));
} }
private void throwMissle(UUID uuid) { private void throwMissile(UUID uuid) {
Vector3f targetPoint = pieces.get(uuid).getLocation(); Vector3f targetPoint = pieces.get(uuid).getLocation();
MissileAnimation anim = new MissileAnimation(app, rootNode, uuid, targetPoint, 2); MissileAnimation anim = new MissileAnimation(app, rootNode, targetPoint, 2f, ()->throwPieceAnim(uuid));
anim.start(); anim.start();
} }

View File

@@ -52,7 +52,6 @@ public GameView(MdgaApp app) {
@Override @Override
public void onEnter() { public void onEnter() {
setOwnColor(Color.AIRFORCE);
camera.init(ownColor); camera.init(ownColor);
boardHandler.init(); boardHandler.init();
guiHandler.init(ownColor); guiHandler.init(ownColor);