added effect for shell flying
This commit is contained in:
@@ -8,26 +8,22 @@
|
||||
|
||||
import static pp.mdga.client.Util.linInt;
|
||||
|
||||
public class FadeControl extends InitControl {
|
||||
public class FadeControl extends ActionControl {
|
||||
private float duration; // Duration of the fade effect
|
||||
private float timeElapsed = 0;
|
||||
private boolean init = false;
|
||||
private float startAlpha;
|
||||
private float endAlpha;
|
||||
private Runnable actionAfter;
|
||||
|
||||
public FadeControl(float duration, float startAlpha, float endAlpha, Runnable actionAfter) {
|
||||
super(actionAfter);
|
||||
this.duration = duration;
|
||||
this.startAlpha = startAlpha;
|
||||
this.endAlpha = endAlpha;
|
||||
this.actionAfter = actionAfter;
|
||||
}
|
||||
|
||||
public FadeControl(float duration, float startAlpha, float endAlpha) {
|
||||
this.duration = duration;
|
||||
this.startAlpha = startAlpha;
|
||||
this.endAlpha = endAlpha;
|
||||
this.actionAfter = null;
|
||||
this(duration, startAlpha, endAlpha, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,7 +43,7 @@ protected void controlUpdate(float tpf) {
|
||||
t = 1;
|
||||
init = false;
|
||||
spatial.removeControl(this);
|
||||
if(actionAfter != null) actionAfter.run();
|
||||
action();
|
||||
}
|
||||
|
||||
float alpha = linInt(startAlpha, endAlpha, t); // Interpolate alpha
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class MatrixAnimation extends InitControl {
|
||||
public class MatrixAnimation extends ActionControl {
|
||||
private MdgaApp app;
|
||||
private static final Random RANDOM = new Random();
|
||||
private Vector3f radarPos;
|
||||
@@ -30,10 +30,10 @@ private enum MatrixState{
|
||||
}
|
||||
|
||||
private MatrixState state;
|
||||
public MatrixAnimation(MdgaApp app, float duration, Vector3f radarPos, Runnable runnable){
|
||||
public MatrixAnimation(MdgaApp app, Vector3f radarPos, Runnable runnable){
|
||||
super(runnable);
|
||||
this.app = app;
|
||||
this.radarPos = radarPos;
|
||||
this.runnable = runnable;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,8 +90,8 @@ public void run() {
|
||||
case MATRIX_OFF -> {
|
||||
if(timeElapsed >= 0.5f){
|
||||
init = false;
|
||||
runnable.run();
|
||||
spatial.removeControl(this);
|
||||
action();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,8 +76,8 @@ private void shoot(){
|
||||
);
|
||||
|
||||
Spatial shell = createShell();
|
||||
shell.addControl(new ShellControl(this::hitExplosion, shootPos, spatial.getLocalTranslation(), FLYING_HEIGHT, FLYING_DURATION));
|
||||
app.getRootNode().attachChild(shell);
|
||||
shell.addControl(new ShellControl(this::hitExplosion, shootPos, spatial.getLocalTranslation(), FLYING_HEIGHT, FLYING_DURATION, app.getAssetManager()));
|
||||
}
|
||||
|
||||
private Spatial createShell(){
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package pp.mdga.client.animation;
|
||||
|
||||
import com.jme3.asset.AssetManager;
|
||||
import com.jme3.effect.ParticleEmitter;
|
||||
import com.jme3.effect.ParticleMesh;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Vector3f;
|
||||
import pp.mdga.client.InitControl;
|
||||
@@ -10,13 +15,16 @@ public class ShellControl extends ActionControl {
|
||||
private final float height;
|
||||
private final float duration;
|
||||
private Vector3f oldPos;
|
||||
private ParticleEmitter emitter;
|
||||
private AssetManager assetManager;
|
||||
|
||||
public ShellControl(Runnable runnable, Vector3f shootPos, Vector3f endPos, float height, float duration){
|
||||
public ShellControl(Runnable runnable, Vector3f shootPos, Vector3f endPos, float height, float duration, AssetManager assetManager){
|
||||
super(runnable);
|
||||
this.shootPos = shootPos;
|
||||
this.endPos = endPos;
|
||||
this.height = height;
|
||||
this.duration = duration;
|
||||
this.assetManager = assetManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -25,6 +33,9 @@ protected void initSpatial() {
|
||||
shootPos,
|
||||
endPos,
|
||||
()->{
|
||||
emitter.killAllParticles();
|
||||
emitter.setParticlesPerSec(0);
|
||||
emitter.removeFromParent();
|
||||
spatial.removeControl(this);
|
||||
spatial.removeFromParent();
|
||||
action();
|
||||
@@ -34,6 +45,34 @@ protected void initSpatial() {
|
||||
false
|
||||
));
|
||||
oldPos = spatial.getLocalTranslation().clone();
|
||||
createEmitter();
|
||||
}
|
||||
|
||||
private void createEmitter() {
|
||||
emitter = new ParticleEmitter("ShellTrail", ParticleMesh.Type.Triangle, 200);
|
||||
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", assetManager.loadTexture("Images/particle/line.png")); // Nutze eine schmale, linienartige Textur
|
||||
emitter.setMaterial(mat);
|
||||
|
||||
// Comic-Style Farben
|
||||
emitter.setStartColor(new ColorRGBA(1f, 1f, 1f, 1f)); // Reinweiß
|
||||
emitter.setEndColor(new ColorRGBA(1f, 1f, 1f, 0f)); // Transparent
|
||||
|
||||
// Partikelgröße und Lebensdauer
|
||||
emitter.setStartSize(0.15f); // Startgröße
|
||||
emitter.setEndSize(0.1f); // Endgröße
|
||||
emitter.setLowLife(0.14f); // Sehr kurze Lebensdauer
|
||||
emitter.setHighLife(0.14f);
|
||||
|
||||
emitter.setGravity(0, 0, 0); // Keine Gravitation
|
||||
emitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0));
|
||||
emitter.getParticleInfluencer().setVelocityVariation(0f); // Kein Variationsspielraum
|
||||
|
||||
// Hohe Dichte für eine glatte Spur
|
||||
emitter.setParticlesPerSec(500);
|
||||
|
||||
// Zur Shell hinzufügen
|
||||
spatial.getParent().attachChild(emitter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,5 +83,7 @@ protected void controlUpdate(float tpf) {
|
||||
spatial.rotate(FastMath.HALF_PI,0,0);
|
||||
}
|
||||
oldPos = spatial.getLocalTranslation().clone();
|
||||
|
||||
emitter.setLocalTranslation(spatial.getLocalTranslation().clone());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -775,7 +775,7 @@ private void throwBomb(UUID uuid) {
|
||||
private void throwMatrix(UUID uuid) {
|
||||
//app.getAcousticHandler().playSound(MdgaSound.MATRIX);
|
||||
Spatial piece = pieces.get(uuid).getSpatial();
|
||||
piece.addControl(new MatrixAnimation(app, 1, radarPos,()-> {
|
||||
piece.addControl(new MatrixAnimation(app, radarPos,()-> {
|
||||
piece.addControl(new FadeControl(1,1,0,
|
||||
() -> {
|
||||
throwPiece(uuid);
|
||||
|
||||
BIN
Projekte/mdga/client/src/main/resources/Images/particle/line.png
Normal file
BIN
Projekte/mdga/client/src/main/resources/Images/particle/line.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 140 B |
Reference in New Issue
Block a user