added groundwork for shell animation
@ -24,6 +24,7 @@ import com.jme3.scene.shape.Cylinder;
|
||||
import pp.battleship.client.BattleshipApp;
|
||||
import pp.battleship.model.Battleship;
|
||||
import pp.battleship.model.Rotation;
|
||||
import pp.battleship.model.Shell;
|
||||
import pp.battleship.model.ShipMap;
|
||||
import pp.battleship.model.Shot;
|
||||
|
||||
@ -43,6 +44,7 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
private static final String SMALL_BOAT_MODEL = "Models/BoatSmall/12219_boat_v2_L2.j3o";
|
||||
private static final String BATTLE_MODEL = "Models/Battle/Battle.j3o"; //NON-NLS
|
||||
private static final String CV_MODEL = "Models/CV/CV.j3o"; //NON-NLS
|
||||
private static final String SHELL_MODEL = "Models/Shell/45.j3o";
|
||||
private static final String COLOR = "Color"; //NON-NLS
|
||||
private static final String SHIP = "ship"; //NON-NLS
|
||||
private static final String SHOT = "shot"; //NON-NLS
|
||||
@ -52,6 +54,8 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
|
||||
private final ShipMap map;
|
||||
private final BattleshipApp app;
|
||||
private Shell shell;
|
||||
private Spatial shellModel;
|
||||
|
||||
private ParticleEmitter flame, flash, spark, roundspark, smoketrail, debris,
|
||||
shockwave;
|
||||
@ -318,6 +322,21 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
return waterSplash;
|
||||
}
|
||||
|
||||
private void initiateShellFlight(Shot shot) {
|
||||
Vector3f startPosition = new Vector3f(0, 1, 0); // The position where the shell starts, can be adjusted
|
||||
Vector3f targetPosition = new Vector3f(shot.getX() + 0.5f, 0, shot.getY() + 0.5f);
|
||||
|
||||
shell = new Shell(startPosition, targetPosition, 2f); // 2 seconds flight duration
|
||||
shellModel = app.getAssetManager().loadModel(SHELL_MODEL);
|
||||
Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
material.setColor("Color", ColorRGBA.Yellow);
|
||||
shellModel.setMaterial(material);
|
||||
|
||||
// Set the initial position for the shell model
|
||||
shellModel.setLocalTranslation(startPosition);
|
||||
//.attachChild(shellModel); TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@code SeaSynchronizer} object with the specified application, root node, and ship map.
|
||||
*
|
||||
|
387991
Projekte/battleship/client/src/main/resources/Models/Shell/45.obj
Normal file
After Width: | Height: | Size: 127 KiB |
After Width: | Height: | Size: 94 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 147 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 101 KiB |
After Width: | Height: | Size: 102 KiB |
After Width: | Height: | Size: 35 KiB |
After Width: | Height: | Size: 3.0 MiB |
After Width: | Height: | Size: 246 KiB |
After Width: | Height: | Size: 330 KiB |
@ -45,6 +45,7 @@ public class ModelExporter extends SimpleApplication {
|
||||
export("Models/BoatSmall/12219_boat_v2_L2.obj", "12219_boat_v2_L2.j3o");
|
||||
export("Models/Battle/14084_WWII_Ship_German_Type_II_U-boat_v2_L1.obj", "Battle.j3o"); //NON-NLS
|
||||
export("Models/CV/essex_scb-125_generic.obj", "CV.j3o"); //NON-NLS
|
||||
export("Models/Shell/Shell/45.obj", "Shell.j3o");
|
||||
|
||||
|
||||
|
||||
|
387991
Projekte/battleship/converter/src/main/resources/Models/Shell/Shell/45.obj
Normal file
After Width: | Height: | Size: 127 KiB |
After Width: | Height: | Size: 94 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 147 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 101 KiB |
After Width: | Height: | Size: 102 KiB |
After Width: | Height: | Size: 35 KiB |
After Width: | Height: | Size: 3.0 MiB |
After Width: | Height: | Size: 246 KiB |
After Width: | Height: | Size: 330 KiB |
@ -11,6 +11,7 @@ import pp.battleship.BattleshipConfig;
|
||||
import pp.battleship.message.client.ClientInterpreter;
|
||||
import pp.battleship.message.client.MapMessage;
|
||||
import pp.battleship.message.client.ShootMessage;
|
||||
import pp.battleship.message.client.ShellAnimationFinishedMessage;
|
||||
import pp.battleship.message.server.EffectMessage;
|
||||
import pp.battleship.message.server.GameDetails;
|
||||
import pp.battleship.message.server.ServerMessage;
|
||||
@ -35,6 +36,7 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
private final BattleshipConfig config;
|
||||
private final List<Player> players = new ArrayList<>(2);
|
||||
private final Set<Player> readyPlayers = new HashSet<>();
|
||||
private Set<Integer> playersFinishedShellAnimation = new HashSet<>();
|
||||
private final ServerSender serverSender;
|
||||
private Player activePlayer;
|
||||
private ServerState state = ServerState.WAIT;
|
||||
@ -197,6 +199,9 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
*/
|
||||
void shoot(Player p, IntPoint pos) {
|
||||
if (p != activePlayer) return;
|
||||
setState(ServerState.SHELL_IN_FLIGHT);
|
||||
// setState(ServerState.BATTLE);
|
||||
|
||||
final Player otherPlayer = getOpponent(activePlayer);
|
||||
final Battleship selectedShip = otherPlayer.getMap().findShipAt(pos);
|
||||
if (selectedShip == null) {
|
||||
@ -260,5 +265,31 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Handles the reception of ShellAnimationFinishedMessage.
|
||||
* This method is called when a client signals that its shell animation is complete.
|
||||
*
|
||||
* @param msg the received ShellAnimationFinishedMessage
|
||||
* @param from the ID of the sender client
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void received(ShellAnimationFinishedMessage msg, int from) {
|
||||
// Add the player to the set of players who have finished the animation
|
||||
playersFinishedShellAnimation.add(from);
|
||||
|
||||
// Check if both players have finished the shell animation
|
||||
if (playersFinishedShellAnimation.size() == 2) {
|
||||
// Clear the set of players who have finished the animation for the next shot
|
||||
playersFinishedShellAnimation.clear();
|
||||
|
||||
// Transition back to the BATTLE state
|
||||
setState(ServerState.BATTLE);
|
||||
|
||||
// Log the completion of the shell animation
|
||||
LOGGER.log(Level.INFO, "Both players finished shell animation. Returning to BATTLE state.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -29,5 +29,10 @@ enum ServerState {
|
||||
/**
|
||||
* The game has ended because all the ships of one player have been destroyed.
|
||||
*/
|
||||
GAME_OVER
|
||||
GAME_OVER,
|
||||
/**
|
||||
* The games is frozen as long as the shell animation is running
|
||||
*/
|
||||
SHELL_IN_FLIGHT
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import pp.battleship.message.client.ClientMessage;
|
||||
import pp.battleship.message.client.MapMessage;
|
||||
import pp.battleship.message.client.ShootMessage;
|
||||
import pp.battleship.model.Battleship;
|
||||
import pp.battleship.message.client.ShellAnimationFinishedMessage;
|
||||
|
||||
/**
|
||||
* The {@code Copycat} class is a utility that creates a copy of a {@link ClientMessage}.
|
||||
@ -72,4 +73,11 @@ class Copycat implements ClientInterpreter {
|
||||
private static Battleship copy(Battleship ship) {
|
||||
return new Battleship(ship.getLength(), ship.getX(), ship.getY(), ship.getRot());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(ShellAnimationFinishedMessage shellAnimationFinishedMessage, int from) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'received'");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,10 @@ public interface ClientInterpreter {
|
||||
*/
|
||||
void received(ShootMessage msg, int from);
|
||||
|
||||
// TODO
|
||||
void received(ShellAnimationFinishedMessage shellAnimationFinishedMessage, int from);
|
||||
|
||||
|
||||
/**
|
||||
* Processes a received MapMessage.
|
||||
*
|
||||
|
@ -0,0 +1,10 @@
|
||||
package pp.battleship.message.client;
|
||||
|
||||
public class ShellAnimationFinishedMessage extends ClientMessage{
|
||||
|
||||
@Override
|
||||
public void accept(ClientInterpreter interpreter, int from) {
|
||||
interpreter.received(this, from);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package pp.battleship.model;
|
||||
|
||||
|
||||
import com.jme3.math.Vector3f;
|
||||
|
||||
public class Shell {
|
||||
private Vector3f startPosition;
|
||||
private Vector3f targetPosition;
|
||||
private Vector3f currentPosition;
|
||||
private float speed;
|
||||
private boolean isAtTarget;
|
||||
|
||||
public Shell(Vector3f startPosition, Vector3f targetPosition, float speed) {
|
||||
this.startPosition = startPosition;
|
||||
this.targetPosition = targetPosition;
|
||||
this.currentPosition = new Vector3f(startPosition);
|
||||
this.speed = speed;
|
||||
this.isAtTarget = true;
|
||||
}
|
||||
|
||||
// Aktualisiert die Position des Geschosses basierend auf der verstrichenen Zeit
|
||||
public void updatePosition(float deltaTime) {
|
||||
if (!isAtTarget) {
|
||||
// Berechne die Richtung des Geschosses
|
||||
Vector3f direction = targetPosition.subtract(currentPosition).normalize();
|
||||
// Berechne die Bewegung basierend auf der Geschwindigkeit und der verstrichenen Zeit
|
||||
Vector3f movement = direction.mult(speed * deltaTime);
|
||||
currentPosition.addLocal(movement);
|
||||
|
||||
// Prüfe, ob das Geschoss das Ziel erreicht hat
|
||||
if (currentPosition.distance(targetPosition) < speed * deltaTime) {
|
||||
currentPosition.set(targetPosition);
|
||||
isAtTarget = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gibt die aktuelle Position des Geschosses zurück
|
||||
public Vector3f getCurrentPosition() {
|
||||
return currentPosition;
|
||||
}
|
||||
|
||||
// Überprüft, ob das Geschoss das Ziel erreicht hat
|
||||
public boolean isAtTarget() {
|
||||
return isAtTarget;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,47 @@
|
||||
package pp.battleship.model;
|
||||
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
|
||||
public class ShellControl extends AbstractControl {
|
||||
|
||||
private Shell shell; // Das Shell-Objekt, das die Bewegung des Geschosses enthält
|
||||
|
||||
public ShellControl(Shell shell) {
|
||||
this.shell = shell;
|
||||
}
|
||||
|
||||
// Die Methode wird in jedem Frame aufgerufen, um die Logik zu aktualisieren
|
||||
@Override
|
||||
protected void controlUpdate(float deltaTime) {
|
||||
if (shell != null) {
|
||||
// Aktualisiere die Position des Geschosses basierend auf der verstrichenen Zeit
|
||||
shell.updatePosition(deltaTime);
|
||||
|
||||
// Setze die neue Position des Geschosses im 3D-Raum
|
||||
spatial.setLocalTranslation(shell.getCurrentPosition());
|
||||
|
||||
// Optionale Animation oder Effekte hinzufügen (z.B. Rauch oder Funkenflug)
|
||||
// addParticleEffects();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Setze das Shell-Objekt neu, um es während des Spiels zu ändern
|
||||
public void setShell(Shell shell) {
|
||||
this.shell = shell;
|
||||
}
|
||||
|
||||
// Gibt das aktuell verwendete Shell-Objekt zurück
|
||||
public Shell getShell() {
|
||||
return this.shell;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
}
|