Aufgabe 13

edited class BattleState in order to implement the 2D map feature
edited class GameSound to add the Missile launch sound
edited class MapViewSynchronizer in order to implement the 2D map feature
edited class ImpactEffectManager removed unused import
edited class SeaSynchronizer removed unused code
edited class Shell in order to implement the 2D map feature
edited class ShellControl in order to implement the 2D map feature
edited Sound added Missile launch enum
edited FloatMath to improve the animation for the 2D projectile
added missileLaunch.wav
This commit is contained in:
Lukas Bauer
2024-10-11 14:23:49 +02:00
parent 6100e95e76
commit bf16a18b71
11 changed files with 176 additions and 65 deletions

View File

@@ -55,11 +55,11 @@ else if (logic.getOpponentMap().isValid(pos))
@Override
public void receivedEffect(EffectMessage msg) {
ClientGameLogic.LOGGER.log(Level.INFO, "report effect: {0}", msg); //NON-NLS
playSound(msg);
myTurn = msg.isMyTurn();
logic.playSound(Sound.MISSILE_LAUNCH);
logic.setInfoText(msg.getInfoTextKey());
affectedMap(msg).add(msg.getShot());
affectedMap(msg).add(new Shell(new Vector3f(0, 10, 0), new Vector3f(msg.getShot().getY() + 0.5f, -0.4f, msg.getShot().getX() + 0.5f), 1f));
affectedMap(msg).add(new Shell(new Vector3f(0, 50, 0), new Vector3f(msg.getShot().getY() + 0.5f, -0.4f, msg.getShot().getX() + 0.5f), 1f,msg,logic));
if (destroyedOpponentShip(msg))
logic.getOpponentMap().add(msg.getDestroyedShip());
if (msg.isGameOver()) {

View File

@@ -1,6 +1,8 @@
package pp.battleship.model;
import com.jme3.math.Vector3f;
import pp.battleship.game.client.ClientGameLogic;
import pp.battleship.message.server.EffectMessage;
import pp.util.FloatMath;
public class Shell implements Item {
@@ -8,26 +10,38 @@ public class Shell implements Item {
private Vector3f targetPosition; // Zielposition des Geschosses0
private Vector3f currentPosition; // Aktuelle Position des Geschosses
private float speed; // Geschwindigkeit des Geschosses
private EffectMessage msg;
private ClientGameLogic logic;
private float progress;
private float progress;
public Shell(Vector3f startPosition, Vector3f targetPosition, float speed) {
/**
* @param startPosition
* @param targetPosition
* @param speed
* @param msg
* @param logic
*/
public Shell(Vector3f startPosition, Vector3f targetPosition, float speed, EffectMessage msg, ClientGameLogic logic) {
this.startPosition = startPosition;
this.targetPosition = targetPosition;
this.currentPosition = new Vector3f(startPosition); // Initiale Position ist die Startposition
this.speed = speed;
this.msg = msg;
this.logic = logic;
}
// Methode, um die Position des Geschosses basierend auf der Zeit zu aktualisieren
public void updatePosition(float deltaTime) {
progress+=deltaTime*speed;
progress += deltaTime * speed;
progress = FloatMath.clamp(progress, 0.0f, 1.0f);
float t = FloatMath.easeInOutElastic(progress);
// Interpoliere die Position zwischen Start- und Zielposition basierend auf dem Fortschritt
currentPosition.x = FloatMath.interpolateLinear(progress,startPosition.x,targetPosition.x);
currentPosition.y = FloatMath.interpolateLinear(progress,startPosition.y,targetPosition.y);
currentPosition.z = FloatMath.interpolateLinear(progress,startPosition.z,targetPosition.z);
//currentPosition.interpolateLocal(startPosition, targetPosition, progress);
currentPosition.y = FloatMath.extrapolateLinear(t, startPosition.y, targetPosition.y);
currentPosition.x = FloatMath.extrapolateLinear(t, startPosition.x, targetPosition.x);
currentPosition.z = FloatMath.extrapolateLinear(t, startPosition.z, targetPosition.z);
}
// Aktuelle Position des Geschosses
@@ -40,22 +54,44 @@ public boolean isAtTarget() {
return currentPosition.distance(targetPosition) < 0.0001f; // Toleranz für die Zielgenauigkeit
}
/**
* @param visitor the visitor performing operations on the item
* @param <T>
* @return
*/
@Override
public <T> T accept(Visitor<T> visitor) {
return visitor.visit(this);
}
/**
* Accepts a visitor that does not return a value. This method is part of the
* Visitor design pattern.
*
* @param visitor the visitor to accept
*/
@Override
public void accept(VoidVisitor visitor) {
visitor.visit(this);
}
/**
* @return
*/
public boolean isFinished() {
return progress >= 1;
}
/**
* @return
*/
public EffectMessage getMsg() {
return msg;
}
/**
* @return
*/
public ClientGameLogic getLogic() {
return logic;
}
}

View File

@@ -22,5 +22,9 @@ public enum Sound {
/**
* Sound of a ship being destroyed.
*/
DESTROYED_SHIP
DESTROYED_SHIP,
/**
* Sound of a fired Missile
*/
MISSILE_LAUNCH
}