Compare commits
24 Commits
b_schmidt_
...
revert-f24
Author | SHA1 | Date | |
---|---|---|---|
|
0f44d37d4a | ||
|
f248a77c81 | ||
|
aa9c073931 | ||
|
1740988629 | ||
|
dcc7cf9c20 | ||
|
5501c0716d | ||
|
8261e1b3b2 | ||
|
5cca8f5c05 | ||
|
133921cfbb | ||
|
4cf14d02ee | ||
|
50bee91775 | ||
|
a656ab5062 | ||
|
b2a6f86fc2 | ||
|
9f90d92198 | ||
|
3e913f636c | ||
|
806c00c94a | ||
|
4fff32c13e | ||
|
1c99117ca0 | ||
|
62421e87cc | ||
|
e343074240 | ||
|
35f154aa0f | ||
|
4488911e82 | ||
|
c7269f032f | ||
|
4581e611ca |
@@ -7,18 +7,14 @@ description = 'Battleship Client'
|
||||
dependencies {
|
||||
implementation project(":jme-common")
|
||||
implementation project(":battleship:model")
|
||||
implementation 'org.jmonkeyengine:jme3-core:3.6.0-stable'
|
||||
implementation 'org.jmonkeyengine:jme3-effects:3.6.0-stable'
|
||||
|
||||
|
||||
implementation libs.jme3.desktop
|
||||
implementation libs.jme3.effects
|
||||
|
||||
runtimeOnly libs.jme3.awt.dialogs
|
||||
runtimeOnly libs.jme3.plugins
|
||||
runtimeOnly libs.jme3.jogg
|
||||
runtimeOnly libs.jme3.testdata
|
||||
|
||||
|
||||
}
|
||||
|
||||
application {
|
||||
|
@@ -22,8 +22,8 @@ import com.simsilica.lemur.GuiGlobals;
|
||||
import com.simsilica.lemur.style.BaseStyles;
|
||||
import pp.battleship.client.gui.BattleAppState;
|
||||
import pp.battleship.client.gui.EditorAppState;
|
||||
import pp.battleship.client.gui.GameMusic;
|
||||
import pp.battleship.client.gui.SeaAppState;
|
||||
import pp.battleship.client.GameMusic;
|
||||
import pp.battleship.game.client.BattleshipClient;
|
||||
import pp.battleship.game.client.ClientGameLogic;
|
||||
import pp.battleship.game.client.ServerConnection;
|
||||
@@ -269,7 +269,6 @@ public class BattleshipApp extends SimpleApplication implements BattleshipClient
|
||||
|
||||
attachGameSound();
|
||||
attachGameMusic();
|
||||
|
||||
stateManager.attachAll(new EditorAppState(), new BattleAppState(), new SeaAppState());
|
||||
}
|
||||
|
||||
@@ -284,12 +283,12 @@ public class BattleshipApp extends SimpleApplication implements BattleshipClient
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches the music state and sets its initial enabled state.
|
||||
* Attaches the background music state and sets its initial enabled state.
|
||||
*/
|
||||
private void attachGameMusic() {
|
||||
final GameMusic gameMusic = new GameMusic();
|
||||
gameMusic.setEnabled(GameMusic.enabledInPreferences());
|
||||
stateManager.attach(gameMusic);
|
||||
final GameMusic gameSound = new GameMusic();
|
||||
gameSound.setEnabled(GameMusic.enabledInPreferences());
|
||||
stateManager.attach(gameSound);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,7 +11,9 @@ import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Checkbox;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
import pp.battleship.client.gui.VolumeControl;
|
||||
|
||||
import pp.battleship.client.gui.GameMusic;
|
||||
import pp.battleship.client.gui.VolumeSlider;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.StateCheckboxModel;
|
||||
import pp.dialog.TextInputDialog;
|
||||
@@ -34,7 +36,7 @@ class Menu extends Dialog {
|
||||
private final BattleshipApp app;
|
||||
private final Button loadButton = new Button(lookup("menu.map.load"));
|
||||
private final Button saveButton = new Button(lookup("menu.map.save"));
|
||||
private final VolumeControl volumeSlider;
|
||||
private final VolumeSlider slider;
|
||||
|
||||
/**
|
||||
* Constructs the Menu dialog for the Battleship application.
|
||||
@@ -44,25 +46,19 @@ class Menu extends Dialog {
|
||||
public Menu(BattleshipApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
addChild(new Label(lookup("battleship.name"), new ElementId("header")));//NON-NLS
|
||||
|
||||
slider = new VolumeSlider(app.getStateManager().getState(GameMusic.class));
|
||||
addChild(new Label(lookup("battleship.name"), new ElementId("header"))); //NON-NLS
|
||||
addChild(new Checkbox(lookup("menu.sound-enabled"), new StateCheckboxModel(app, GameSound.class)));
|
||||
|
||||
addChild(new Checkbox(lookup("menu.background-sound-enabled"), new StateCheckboxModel(app, GameMusic.class)));
|
||||
|
||||
addChild(slider);
|
||||
|
||||
volumeSlider = new VolumeControl(app.getStateManager().getState(GameMusic.class));
|
||||
|
||||
addChild(volumeSlider);
|
||||
|
||||
addChild(loadButton)
|
||||
.addClickCommands(s -> ifTopDialog(this::loadDialog));
|
||||
addChild(saveButton)
|
||||
.addClickCommands(s -> ifTopDialog(this::saveDialog));
|
||||
addChild(new Button(lookup("menu.return-to-game")))
|
||||
.addClickCommands(s -> ifTopDialog(this::close));
|
||||
addChild(new Button(lookup("menu.quit")))
|
||||
.addClickCommands(s -> ifTopDialog(app::closeApp));
|
||||
addChild(loadButton).addClickCommands(s -> ifTopDialog(this::loadDialog));
|
||||
addChild(saveButton).addClickCommands(s -> ifTopDialog(this::saveDialog));
|
||||
addChild(new Button(lookup("menu.return-to-game"))).addClickCommands(s -> ifTopDialog(this::close));
|
||||
addChild(new Button(lookup("menu.quit"))).addClickCommands(s -> ifTopDialog(app::closeApp));
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -75,15 +71,11 @@ class Menu extends Dialog {
|
||||
saveButton.setEnabled(app.getGameLogic().maySaveMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the position of the volume control slider.
|
||||
*/
|
||||
@Override
|
||||
public void update(float delta) {
|
||||
volumeSlider.update();
|
||||
slider.update();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* As an escape action, this method closes the menu if it is the top dialog.
|
||||
*/
|
||||
|
@@ -7,12 +7,13 @@
|
||||
|
||||
package pp.battleship.client;
|
||||
|
||||
import com.simsilica.lemur.Checkbox;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.TextField;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
import pp.battleship.client.server.BattleshipSelfhostServer;
|
||||
|
||||
import pp.battleship.server.BattleshipServer;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.DialogBuilder;
|
||||
import pp.dialog.SimpleDialog;
|
||||
@@ -35,7 +36,8 @@ class NetworkDialog extends SimpleDialog {
|
||||
private final NetworkSupport network;
|
||||
private final TextField host = new TextField(LOCALHOST);
|
||||
private final TextField port = new TextField(DEFAULT_PORT);
|
||||
private static final Checkbox HOST = new Checkbox(lookup("server.host"));
|
||||
// private final Button serverButton = new Button(lookup("client.server-star"));
|
||||
private final Button serverButton = new Button(lookup("client.server-start"));
|
||||
private String hostname;
|
||||
private int portNumber;
|
||||
private Future<Object> connectionFuture;
|
||||
@@ -59,7 +61,6 @@ class NetworkDialog extends SimpleDialog {
|
||||
input.addChild(host, 1);
|
||||
input.addChild(new Label(lookup("port.number") + ": "));
|
||||
input.addChild(port, 1);
|
||||
input.addChild(HOST).addClickCommands(s -> ifTopDialog(this::startClientServer));
|
||||
|
||||
DialogBuilder.simple(app.getDialogManager())
|
||||
.setTitle(lookup("server.dialog"))
|
||||
@@ -69,6 +70,9 @@ class NetworkDialog extends SimpleDialog {
|
||||
.setOkClose(false)
|
||||
.setNoClose(false)
|
||||
.build(this);
|
||||
|
||||
//Add the button to start the sever
|
||||
addChild(serverButton).addClickCommands(s -> ifTopDialog(this::startServerInThread));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,15 +160,15 @@ class NetworkDialog extends SimpleDialog {
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the server of the client in a new thread and catches connectivity issues.
|
||||
* Starts the server in a separate thread.
|
||||
*/
|
||||
private void startClientServer() {
|
||||
HOST.setEnabled(false);
|
||||
private void startServerInThread() {
|
||||
serverButton.setEnabled(false);
|
||||
Thread serverThread = new Thread(() -> {
|
||||
try {
|
||||
BattleshipSelfhostServer.main(null);
|
||||
BattleshipServer.main(null);
|
||||
} catch (Exception e) {
|
||||
HOST.setEnabled(true);
|
||||
serverButton.setEnabled(true);
|
||||
LOGGER.log(Level.ERROR, "Server could not be started", e);
|
||||
network.getApp().errorDialog("Could not start server: " + e.getMessage());
|
||||
}
|
||||
@@ -172,4 +176,3 @@ class NetworkDialog extends SimpleDialog {
|
||||
serverThread.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,10 @@
|
||||
package pp.battleship.client;
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import static pp.util.PreferencesUtils.getPreferences;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import com.jme3.app.Application;
|
||||
import com.jme3.app.state.AbstractAppState;
|
||||
@@ -9,25 +14,13 @@ import com.jme3.asset.AssetNotFoundException;
|
||||
import com.jme3.audio.AudioData;
|
||||
import com.jme3.audio.AudioNode;
|
||||
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import static pp.util.PreferencesUtils.getPreferences;
|
||||
|
||||
/**
|
||||
* An application state that plays music.
|
||||
*/
|
||||
public class GameMusic extends AbstractAppState {
|
||||
public class GameMusic extends AbstractAppState{
|
||||
private static final Logger LOGGER = System.getLogger(GameMusic.class.getName());
|
||||
private static final Preferences PREFERENCES = getPreferences(GameMusic.class);
|
||||
private static final String ENABLED_PREF = "enabled"; //NON-NLS
|
||||
private static final String VOLUME_PREF = "volume"; //NON-NLS
|
||||
|
||||
private AudioNode battleMusic;
|
||||
private AudioNode menuMusicModern;
|
||||
private AudioNode menuMusicTraditional;
|
||||
private AudioNode music;
|
||||
|
||||
/**
|
||||
* Checks if sound is enabled in the preferences.
|
||||
@@ -37,47 +30,18 @@ public class GameMusic extends AbstractAppState {
|
||||
public static boolean enabledInPreferences() {
|
||||
return PREFERENCES.getBoolean(ENABLED_PREF, true);
|
||||
}
|
||||
/**
|
||||
* Checks enabled volume in preferences.
|
||||
*
|
||||
* @return {@code float} if a volumePreference is set, the volume is set to the Value in PREFERENCES,
|
||||
* {@code 0.25f} if no volumePreference is set in PREFERENCES, the Volume is set to a default of 0.25f
|
||||
*
|
||||
*/
|
||||
|
||||
public static float volumePreference() {
|
||||
return PREFERENCES.getFloat(VOLUME_PREF, 0.25f);
|
||||
/**
|
||||
* Checks if sound is enabled in the preferences.
|
||||
*
|
||||
* @return float to which the volume is set
|
||||
*/
|
||||
public static float volumeInPreferences() {
|
||||
return PREFERENCES.getFloat(VOLUME_PREF, 0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the game sound on or off.
|
||||
*/
|
||||
public void toggleSound() {
|
||||
setEnabled(!isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the enabled state of this AppState.
|
||||
* Overrides {@link com.jme3.app.state.AbstractAppState#setEnabled(boolean)}
|
||||
*
|
||||
* @param enabled {@code true} to enable the AppState, {@code false} to disable it.
|
||||
*/
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
if (isEnabled() == enabled) return;
|
||||
else if (!isEnabled() && enabled) {
|
||||
if (menuMusicModern != null) menuMusicModern.play();
|
||||
} else if (isEnabled() && !enabled) {
|
||||
if (menuMusicModern != null) menuMusicModern.stop();
|
||||
}
|
||||
|
||||
super.setEnabled(enabled);
|
||||
LOGGER.log(Level.INFO, "Music enabled: {0}", enabled); //NON-NLS
|
||||
PREFERENCES.putBoolean(ENABLED_PREF, enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the music.
|
||||
* Initializes the sound effects for the game.
|
||||
* Overrides {@link AbstractAppState#initialize(AppStateManager, Application)}
|
||||
*
|
||||
* @param stateManager The state manager
|
||||
@@ -86,17 +50,16 @@ public class GameMusic extends AbstractAppState {
|
||||
@Override
|
||||
public void initialize(AppStateManager stateManager, Application app) {
|
||||
super.initialize(stateManager, app);
|
||||
menuMusicModern =loadSound(app, "Sound/BackgroundMusic/menu-music-modern.ogg");
|
||||
setVolume(volumePreference());
|
||||
menuMusicModern.setLooping(true);
|
||||
if (isEnabled() && menuMusicModern != null) {
|
||||
menuMusicModern.play();
|
||||
music = loadSound(app, "Sound/background.ogg");
|
||||
setVolume(volumeInPreferences());
|
||||
music.setLooping(true);
|
||||
if (isEnabled() && music != null) {
|
||||
music.play();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the music from the specified file.
|
||||
* Loads a sound from the specified file.
|
||||
*
|
||||
* @param app The application
|
||||
* @param name The name of the sound file.
|
||||
@@ -116,14 +79,41 @@ public class GameMusic extends AbstractAppState {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the vol param to the level set in PREFERENCES
|
||||
*
|
||||
* @param vol Volume level of the music as indicated by the Volume control Slider
|
||||
* Sets the enabled state of this AppState.
|
||||
* Overrides {@link com.jme3.app.state.AbstractAppState#setEnabled(boolean)}
|
||||
*
|
||||
* @param enabled {@code true} to enable the AppState, {@code false} to disable it.
|
||||
*/
|
||||
public void setVolume(float vol){
|
||||
menuMusicModern.setVolume(vol);
|
||||
PREFERENCES.putFloat(VOLUME_PREF, vol);
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
if (isEnabled() == enabled) return;
|
||||
|
||||
if (music != null) {
|
||||
if (enabled) {
|
||||
music.play();
|
||||
} else {
|
||||
music.stop();
|
||||
}
|
||||
}
|
||||
|
||||
super.setEnabled(enabled);
|
||||
LOGGER.log(Level.INFO, "Sound enabled: {0}", enabled); //NON-NLS
|
||||
PREFERENCES.putBoolean(ENABLED_PREF, enabled);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Toggles the game sound on or off.
|
||||
*/
|
||||
public void toggleSound() {
|
||||
setEnabled(!isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the volume of music
|
||||
* @param vol the volume to which the music should be set
|
||||
*/
|
||||
public void setVolume(float vol){
|
||||
music.setVolume(vol);
|
||||
PREFERENCES.putFloat(VOLUME_PREF, vol);
|
||||
}
|
||||
}
|
@@ -28,7 +28,7 @@ import pp.util.Position;
|
||||
* and interaction between the model and the view.
|
||||
*/
|
||||
class MapView {
|
||||
public static final float FIELD_SIZE = 40f;
|
||||
private static final float FIELD_SIZE = 40f;
|
||||
private static final float GRID_LINE_WIDTH = 2f;
|
||||
private static final float BACKGROUND_DEPTH = -4f;
|
||||
private static final float GRID_DEPTH = -1f;
|
||||
|
@@ -7,21 +7,14 @@
|
||||
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.material.RenderState;
|
||||
import com.jme3.material.RenderState.BlendMode;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.shape.Sphere;
|
||||
import pp.battleship.model.Battleship;
|
||||
import pp.battleship.model.Shell;
|
||||
import pp.battleship.model.Shot;
|
||||
import pp.util.Position;
|
||||
|
||||
import static com.jme3.material.Materials.UNSHADED;
|
||||
|
||||
/**
|
||||
* Synchronizes the visual representation of the ship map with the game model.
|
||||
* It handles the rendering of ships and shots on the map view, updating the view
|
||||
@@ -129,25 +122,4 @@ class MapViewSynchronizer extends ShipMapSynchronizer {
|
||||
private Geometry shipLine(float x1, float y1, float x2, float y2, ColorRGBA color) {
|
||||
return view.getApp().getDraw().makeFatLine(x1, y1, x2, y2, SHIP_DEPTH, color, SHIP_LINE_WIDTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a Spatial representation of the given {@code Shell} object
|
||||
* for 2D visualization in the game. The shell is represented as a circle.
|
||||
*
|
||||
* @param shell The {@code Shell} object to be visualized.
|
||||
* @return A {@code Spatial} object representing the shell on the map.
|
||||
*/
|
||||
@Override
|
||||
public Spatial visit(Shell shell) {
|
||||
final ColorRGBA color = ColorRGBA.Black;
|
||||
Geometry ellipse = new Geometry("ellipse", new Sphere(50, 50, MapView.FIELD_SIZE / 2 * 0.8f));
|
||||
Material mat = new Material(view.getApp().getAssetManager(), UNSHADED); //NON-NLS
|
||||
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
|
||||
mat.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
|
||||
mat.setColor("Color", color);
|
||||
ellipse.setMaterial(mat);
|
||||
ellipse.addControl(new Shell2DControl(view, shell));
|
||||
return ellipse;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,285 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.effect.ParticleEmitter;
|
||||
import com.jme3.effect.ParticleMesh.Type;
|
||||
import com.jme3.effect.shapes.EmitterSphereShape;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Vector3f;
|
||||
import pp.battleship.client.BattleshipApp;
|
||||
|
||||
/**
|
||||
* Factory class responsible for creating particle effects used in the game.
|
||||
* This centralizes the creation of various types of particle emitters.
|
||||
*/
|
||||
public class ParticleEffectFactory {
|
||||
private static final int COUNT_FACTOR = 1;
|
||||
private static final float COUNT_FACTOR_F = 1f;
|
||||
private static final boolean POINT_SPRITE = true;
|
||||
private static final Type EMITTER_TYPE = POINT_SPRITE ? Type.Point : Type.Triangle;
|
||||
|
||||
private final BattleshipApp app;
|
||||
|
||||
ParticleEffectFactory(BattleshipApp app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a flame particle emitter.
|
||||
*
|
||||
* @return a configured flame particle emitter
|
||||
*/
|
||||
ParticleEmitter createFlame() {
|
||||
ParticleEmitter flame = new ParticleEmitter("Flame", EMITTER_TYPE, 32 * COUNT_FACTOR);
|
||||
flame.setSelectRandomImage(true);
|
||||
flame.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (1f / COUNT_FACTOR_F)));
|
||||
flame.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
|
||||
flame.setStartSize(0.1f);
|
||||
flame.setEndSize(0.5f);
|
||||
flame.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
|
||||
flame.setParticlesPerSec(0);
|
||||
flame.setGravity(0, -5, 0);
|
||||
flame.setLowLife(.4f);
|
||||
flame.setHighLife(.5f);
|
||||
flame.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 7, 0));
|
||||
flame.getParticleInfluencer().setVelocityVariation(1f);
|
||||
flame.setImagesX(2);
|
||||
flame.setImagesY(2);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/flame.png"));
|
||||
mat.setBoolean("PointSprite", POINT_SPRITE);
|
||||
flame.setMaterial(mat);
|
||||
|
||||
return flame;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a flash particle emitter.
|
||||
*
|
||||
* @return a configured flash particle emitter
|
||||
*/
|
||||
ParticleEmitter createFlash() {
|
||||
ParticleEmitter flash = new ParticleEmitter("Flash", EMITTER_TYPE, 24 * COUNT_FACTOR);
|
||||
flash.setSelectRandomImage(true);
|
||||
flash.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1f / COUNT_FACTOR_F));
|
||||
flash.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
|
||||
flash.setStartSize(.1f);
|
||||
flash.setEndSize(0.5f);
|
||||
flash.setShape(new EmitterSphereShape(Vector3f.ZERO, .05f));
|
||||
flash.setParticlesPerSec(0);
|
||||
flash.setGravity(0, 0, 0);
|
||||
flash.setLowLife(.2f);
|
||||
flash.setHighLife(.2f);
|
||||
flash.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 5f, 0));
|
||||
flash.getParticleInfluencer().setVelocityVariation(1);
|
||||
flash.setImagesX(2);
|
||||
flash.setImagesY(2);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/flash.png"));
|
||||
mat.setBoolean("PointSprite", POINT_SPRITE);
|
||||
flash.setMaterial(mat);
|
||||
|
||||
return flash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a round spark particle emitter.
|
||||
*
|
||||
* @return a configured round spark particle emitter
|
||||
*/
|
||||
ParticleEmitter createRoundSpark() {
|
||||
ParticleEmitter roundSpark = new ParticleEmitter("RoundSpark", EMITTER_TYPE, 20 * COUNT_FACTOR);
|
||||
roundSpark.setStartColor(new ColorRGBA(1f, 0.29f, 0.34f, (float) (1.0 / COUNT_FACTOR_F)));
|
||||
roundSpark.setEndColor(new ColorRGBA(0, 0, 0, 0.5f / COUNT_FACTOR_F));
|
||||
roundSpark.setStartSize(0.2f);
|
||||
roundSpark.setEndSize(0.8f);
|
||||
roundSpark.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
|
||||
roundSpark.setParticlesPerSec(0);
|
||||
roundSpark.setGravity(0, -.5f, 0);
|
||||
roundSpark.setLowLife(1.8f);
|
||||
roundSpark.setHighLife(2f);
|
||||
roundSpark.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 3, 0));
|
||||
roundSpark.getParticleInfluencer().setVelocityVariation(.5f);
|
||||
roundSpark.setImagesX(1);
|
||||
roundSpark.setImagesY(1);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/roundspark.png"));
|
||||
mat.setBoolean("PointSprite", POINT_SPRITE);
|
||||
roundSpark.setMaterial(mat);
|
||||
|
||||
return roundSpark;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a spark particle emitter.
|
||||
*
|
||||
* @return a configured spark particle emitter
|
||||
*/
|
||||
ParticleEmitter createSpark() {
|
||||
ParticleEmitter spark = new ParticleEmitter("Spark", Type.Triangle, 30 * COUNT_FACTOR);
|
||||
spark.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1.0f / COUNT_FACTOR_F));
|
||||
spark.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
|
||||
spark.setStartSize(.5f);
|
||||
spark.setEndSize(.5f);
|
||||
spark.setFacingVelocity(true);
|
||||
spark.setParticlesPerSec(0);
|
||||
spark.setGravity(0, 5, 0);
|
||||
spark.setLowLife(1.1f);
|
||||
spark.setHighLife(1.5f);
|
||||
spark.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 20, 0));
|
||||
spark.getParticleInfluencer().setVelocityVariation(1);
|
||||
spark.setImagesX(1);
|
||||
spark.setImagesY(1);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/spark.png"));
|
||||
spark.setMaterial(mat);
|
||||
|
||||
return spark;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a smoke trail particle emitter.
|
||||
*
|
||||
* @return a configured smoke trail particle emitter
|
||||
*/
|
||||
ParticleEmitter createSmokeTrail() {
|
||||
ParticleEmitter smokeTrail = new ParticleEmitter("SmokeTrail", Type.Triangle, 22 * COUNT_FACTOR);
|
||||
smokeTrail.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1.0f / COUNT_FACTOR_F));
|
||||
smokeTrail.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
|
||||
smokeTrail.setStartSize(.2f);
|
||||
smokeTrail.setEndSize(1f);
|
||||
smokeTrail.setFacingVelocity(true);
|
||||
smokeTrail.setParticlesPerSec(0);
|
||||
smokeTrail.setGravity(0, 1, 0);
|
||||
smokeTrail.setLowLife(.4f);
|
||||
smokeTrail.setHighLife(.5f);
|
||||
smokeTrail.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 12, 0));
|
||||
smokeTrail.getParticleInfluencer().setVelocityVariation(1);
|
||||
smokeTrail.setImagesX(1);
|
||||
smokeTrail.setImagesY(3);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/smoketrail.png"));
|
||||
smokeTrail.setMaterial(mat);
|
||||
|
||||
return smokeTrail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a debris particle emitter.
|
||||
*
|
||||
* @return a configured debris particle emitter
|
||||
*/
|
||||
ParticleEmitter createDebris() {
|
||||
ParticleEmitter debris = new ParticleEmitter("Debris", Type.Triangle, 15 * COUNT_FACTOR);
|
||||
debris.setSelectRandomImage(true);
|
||||
debris.setRandomAngle(true);
|
||||
debris.setRotateSpeed(FastMath.TWO_PI * 4);
|
||||
debris.setStartColor(new ColorRGBA(1f, 0.59f, 0.28f, 1.0f / COUNT_FACTOR_F));
|
||||
debris.setEndColor(new ColorRGBA(.5f, 0.5f, 0.5f, 0f));
|
||||
debris.setStartSize(.10f);
|
||||
debris.setEndSize(.15f);
|
||||
debris.setParticlesPerSec(0);
|
||||
debris.setGravity(0, 12f, 0);
|
||||
debris.setLowLife(1.4f);
|
||||
debris.setHighLife(1.5f);
|
||||
debris.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 15, 0));
|
||||
debris.getParticleInfluencer().setVelocityVariation(.60f);
|
||||
debris.setImagesX(3);
|
||||
debris.setImagesY(3);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/Debris.png"));
|
||||
debris.setMaterial(mat);
|
||||
|
||||
return debris;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a shockwave particle emitter.
|
||||
*
|
||||
* @return a configured shockwave particle emitter
|
||||
*/
|
||||
ParticleEmitter createShockwave() {
|
||||
ParticleEmitter shockwave = new ParticleEmitter("Shockwave", Type.Triangle, 1 * COUNT_FACTOR);
|
||||
shockwave.setFaceNormal(Vector3f.UNIT_Y);
|
||||
shockwave.setStartColor(new ColorRGBA(.48f, 0.17f, 0.01f, .8f / COUNT_FACTOR_F));
|
||||
shockwave.setEndColor(new ColorRGBA(.48f, 0.17f, 0.01f, 0f));
|
||||
shockwave.setStartSize(0f);
|
||||
shockwave.setEndSize(3f);
|
||||
shockwave.setParticlesPerSec(0);
|
||||
shockwave.setGravity(0, 0, 0);
|
||||
shockwave.setLowLife(0.5f);
|
||||
shockwave.setHighLife(0.5f);
|
||||
shockwave.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 0, 0));
|
||||
shockwave.getParticleInfluencer().setVelocityVariation(0f);
|
||||
shockwave.setImagesX(1);
|
||||
shockwave.setImagesY(1);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/shockwave.png"));
|
||||
shockwave.setMaterial(mat);
|
||||
|
||||
return shockwave;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a moving smoke emitter.
|
||||
*
|
||||
* @return a configured smoke emitter
|
||||
*/
|
||||
ParticleEmitter createMovingSmokeEmitter() {
|
||||
ParticleEmitter smokeEmitter = new ParticleEmitter("SmokeEmitter", Type.Triangle, 300);
|
||||
smokeEmitter.setGravity(0, 0, 0);
|
||||
smokeEmitter.getParticleInfluencer().setVelocityVariation(1);
|
||||
smokeEmitter.setLowLife(1);
|
||||
smokeEmitter.setHighLife(1);
|
||||
smokeEmitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, .5f, 0));
|
||||
smokeEmitter.setImagesX(15); // Assuming the smoke texture is a sprite sheet with 15 frames
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Smoke/Smoke.png"));
|
||||
smokeEmitter.setMaterial(mat);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@@ -8,13 +8,9 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.effect.ParticleEmitter;
|
||||
import com.jme3.effect.ParticleMesh.Type;
|
||||
import com.jme3.effect.shapes.EmitterSphereShape;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.material.RenderState.BlendMode;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.Node;
|
||||
@@ -24,7 +20,6 @@ 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;
|
||||
|
||||
@@ -34,17 +29,16 @@ import static pp.util.FloatMath.PI;
|
||||
|
||||
/**
|
||||
* The {@code SeaSynchronizer} class is responsible for synchronizing the graphical
|
||||
* representation of the ships and shots on the sea map with the underlying model.
|
||||
* representation of the ships and shots on the sea map with the underlying data model.
|
||||
* It extends the {@link ShipMapSynchronizer} to provide specific synchronization
|
||||
* logic for the sea map.
|
||||
*/
|
||||
class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
private static final String UNSHADED = "Common/MatDefs/Misc/Unshaded.j3md"; //NON-NLS
|
||||
private static final String KING_GEORGE_V_MODEL = "Models/KingGeorgeV/KingGeorgeV.j3o";//NON-NLS
|
||||
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 KING_GEORGE_V_MODEL = "Models/KingGeorgeV/KingGeorgeV.j3o"; //NON-NLS
|
||||
private static final String BOAT_SMALL_MODEL = "Models/BoatSmall/12219_boat_v2_L2.j3o"; //NON-NLS
|
||||
private static final String CV_MODEL = "Models/CV/CV.j3o"; //NON-NLS
|
||||
private static final String LIGHTING = "Common/MatDefs/Light/Lighting.j3md";
|
||||
private static final String BATTLE_MODEL = "Models/Battle/Battle.j3o"; //NON-NLS
|
||||
private static final String COLOR = "Color"; //NON-NLS
|
||||
private static final String SHIP = "ship"; //NON-NLS
|
||||
private static final String SHOT = "shot"; //NON-NLS
|
||||
@@ -54,273 +48,7 @@ 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;
|
||||
|
||||
|
||||
private static final int COUNT_FACTOR = 1;
|
||||
private static final float COUNT_FACTOR_F = 1f;
|
||||
|
||||
private static final boolean POINT_SPRITE = true;
|
||||
private static final Type EMITTER_TYPE = POINT_SPRITE ? Type.Point : Type.Triangle;
|
||||
|
||||
/**
|
||||
* Creates a Flame texture with indefinite Lifetime
|
||||
* @return flame texture
|
||||
*/
|
||||
private ParticleEmitter createFlame(){
|
||||
flame = new ParticleEmitter("Flame", EMITTER_TYPE, 32 * COUNT_FACTOR);
|
||||
flame.setSelectRandomImage(true);
|
||||
flame.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (1f / COUNT_FACTOR_F)));
|
||||
flame.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
|
||||
flame.setStartSize(0.1f);
|
||||
flame.setEndSize(0.5f);
|
||||
flame.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
|
||||
flame.setParticlesPerSec(0);
|
||||
flame.setGravity(0, -5, 0);
|
||||
flame.setLowLife(.4f);
|
||||
flame.setHighLife(.5f);
|
||||
flame.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 7, 0));
|
||||
flame.getParticleInfluencer().setVelocityVariation(1f);
|
||||
flame.setImagesX(2);
|
||||
flame.setImagesY(2);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/flame.png"));
|
||||
mat.setBoolean("PointSprite", POINT_SPRITE);
|
||||
flame.setMaterial(mat);
|
||||
|
||||
return flame;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Flash texture
|
||||
* @return flash texture
|
||||
*/
|
||||
private ParticleEmitter createFlash(){
|
||||
flash = new ParticleEmitter("Flash", EMITTER_TYPE, 24 * COUNT_FACTOR);
|
||||
flash.setSelectRandomImage(true);
|
||||
flash.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1f / COUNT_FACTOR_F));
|
||||
flash.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
|
||||
flash.setStartSize(.1f);
|
||||
flash.setEndSize(0.5f);
|
||||
flash.setShape(new EmitterSphereShape(Vector3f.ZERO, .05f));
|
||||
flash.setParticlesPerSec(0);
|
||||
flash.setGravity(0, 0, 0);
|
||||
flash.setLowLife(.2f);
|
||||
flash.setHighLife(.2f);
|
||||
flash.getParticleInfluencer()
|
||||
.setInitialVelocity(new Vector3f(0, 5f, 0));
|
||||
flash.getParticleInfluencer().setVelocityVariation(1);
|
||||
flash.setImagesX(2);
|
||||
flash.setImagesY(2);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/flash.png"));
|
||||
mat.setBoolean("PointSprite", POINT_SPRITE);
|
||||
flash.setMaterial(mat);
|
||||
|
||||
return flash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates small spark particles, that dissipate into the air
|
||||
* @return spark texture
|
||||
*/
|
||||
private ParticleEmitter createRoundSpark(){
|
||||
roundspark = new ParticleEmitter("RoundSpark", EMITTER_TYPE, 20 * COUNT_FACTOR);
|
||||
roundspark.setStartColor(new ColorRGBA(1f, 0.29f, 0.34f, (float) (1.0 / COUNT_FACTOR_F)));
|
||||
roundspark.setEndColor(new ColorRGBA(0, 0, 0, 0.5f / COUNT_FACTOR_F));
|
||||
roundspark.setStartSize(0.2f);
|
||||
roundspark.setEndSize(0.8f);
|
||||
roundspark.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
|
||||
roundspark.setParticlesPerSec(0);
|
||||
roundspark.setGravity(0, -.5f, 0);
|
||||
roundspark.setLowLife(1.8f);
|
||||
roundspark.setHighLife(2f);
|
||||
roundspark.getParticleInfluencer()
|
||||
.setInitialVelocity(new Vector3f(0, 3, 0));
|
||||
roundspark.getParticleInfluencer().setVelocityVariation(.5f);
|
||||
roundspark.setImagesX(1);
|
||||
roundspark.setImagesY(1);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/roundspark.png"));
|
||||
mat.setBoolean("PointSprite", POINT_SPRITE);
|
||||
roundspark.setMaterial(mat);
|
||||
|
||||
return roundspark;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates small, thin smoke trails that enhance the flying debris
|
||||
* @return crates a thin smoke trail texture
|
||||
*/
|
||||
private ParticleEmitter createSpark(){
|
||||
spark = new ParticleEmitter("Spark", Type.Triangle, 30 * COUNT_FACTOR);
|
||||
spark.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1.0f / COUNT_FACTOR_F));
|
||||
spark.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
|
||||
spark.setStartSize(.5f);
|
||||
spark.setEndSize(.5f);
|
||||
spark.setFacingVelocity(true);
|
||||
spark.setParticlesPerSec(0);
|
||||
spark.setGravity(0, 5, 0);
|
||||
spark.setLowLife(1.1f);
|
||||
spark.setHighLife(1.5f);
|
||||
spark.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 20, 0));
|
||||
spark.getParticleInfluencer().setVelocityVariation(1);
|
||||
spark.setImagesX(1);
|
||||
spark.setImagesY(1);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/spark.png"));
|
||||
spark.setMaterial(mat);
|
||||
|
||||
return spark;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a dynamic smoke trail
|
||||
* @return smoke texture
|
||||
*/
|
||||
private ParticleEmitter createSmokeTrail(){
|
||||
smoketrail = new ParticleEmitter("SmokeTrail", Type.Triangle, 22 * COUNT_FACTOR);
|
||||
smoketrail.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, 1.0f / COUNT_FACTOR_F));
|
||||
smoketrail.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f));
|
||||
smoketrail.setStartSize(.2f);
|
||||
smoketrail.setEndSize(1f);
|
||||
|
||||
// smoketrail.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
|
||||
smoketrail.setFacingVelocity(true);
|
||||
smoketrail.setParticlesPerSec(0);
|
||||
smoketrail.setGravity(0, 1, 0);
|
||||
smoketrail.setLowLife(.4f);
|
||||
smoketrail.setHighLife(.5f);
|
||||
smoketrail.getParticleInfluencer()
|
||||
.setInitialVelocity(new Vector3f(0, 12, 0));
|
||||
smoketrail.getParticleInfluencer().setVelocityVariation(1);
|
||||
smoketrail.setImagesX(1);
|
||||
smoketrail.setImagesY(3);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/smoketrail.png"));
|
||||
smoketrail.setMaterial(mat);
|
||||
|
||||
return smoketrail;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates flying debris particles
|
||||
* @return debris texture
|
||||
*/
|
||||
private ParticleEmitter createDebris(){
|
||||
debris = new ParticleEmitter("Debris", Type.Triangle, 15 * COUNT_FACTOR);
|
||||
debris.setSelectRandomImage(true);
|
||||
debris.setRandomAngle(true);
|
||||
debris.setRotateSpeed(FastMath.TWO_PI * 4);
|
||||
debris.setStartColor(new ColorRGBA(1f, 0.59f, 0.28f, 1.0f / COUNT_FACTOR_F));
|
||||
debris.setEndColor(new ColorRGBA(.5f, 0.5f, 0.5f, 0f));
|
||||
debris.setStartSize(.10f);
|
||||
debris.setEndSize(.15f);
|
||||
|
||||
// debris.setShape(new EmitterSphereShape(Vector3f.ZERO, .05f));
|
||||
debris.setParticlesPerSec(0);
|
||||
debris.setGravity(0, 12f, 0);
|
||||
debris.setLowLife(1.4f);
|
||||
debris.setHighLife(1.5f);
|
||||
debris.getParticleInfluencer()
|
||||
.setInitialVelocity(new Vector3f(0, 15, 0));
|
||||
debris.getParticleInfluencer().setVelocityVariation(.60f);
|
||||
debris.setImagesX(3);
|
||||
debris.setImagesY(3);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/Debris.png"));
|
||||
debris.setMaterial(mat);
|
||||
|
||||
return debris;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an expanding circular shockwave
|
||||
* @return shockwave texture
|
||||
*/
|
||||
private ParticleEmitter createShockwave(){
|
||||
shockwave = new ParticleEmitter("Shockwave", Type.Triangle, 1 * COUNT_FACTOR);
|
||||
// shockwave.setRandomAngle(true);
|
||||
shockwave.setFaceNormal(Vector3f.UNIT_Y);
|
||||
shockwave.setStartColor(new ColorRGBA(.48f, 0.17f, 0.01f, .8f / COUNT_FACTOR_F));
|
||||
shockwave.setEndColor(new ColorRGBA(.48f, 0.17f, 0.01f, 0f));
|
||||
|
||||
shockwave.setStartSize(0f);
|
||||
shockwave.setEndSize(3f);
|
||||
|
||||
shockwave.setParticlesPerSec(0);
|
||||
shockwave.setGravity(0, 0, 0);
|
||||
shockwave.setLowLife(0.5f);
|
||||
shockwave.setHighLife(0.5f);
|
||||
shockwave.getParticleInfluencer()
|
||||
.setInitialVelocity(new Vector3f(0, 0, 0));
|
||||
shockwave.getParticleInfluencer().setVelocityVariation(0f);
|
||||
shockwave.setImagesX(1);
|
||||
shockwave.setImagesY(1);
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Explosion/shockwave.png"));
|
||||
shockwave.setMaterial(mat);
|
||||
|
||||
return shockwave;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an animated smoke column.
|
||||
* @return moving smoke texture
|
||||
*/
|
||||
private ParticleEmitter createMovingSmokeEmitter() {
|
||||
ParticleEmitter smokeEmitter = new ParticleEmitter("SmokeEmitter", Type.Triangle, 300);
|
||||
smokeEmitter.setGravity(0, 0, 0);
|
||||
smokeEmitter.getParticleInfluencer().setVelocityVariation(1);
|
||||
smokeEmitter.setLowLife(1);
|
||||
smokeEmitter.setHighLife(1);
|
||||
smokeEmitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, .5f, 0));
|
||||
smokeEmitter.setImagesX(15); // Assuming the smoke texture is a sprite sheet with 15 frames
|
||||
|
||||
// Set the material for the emitter
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
||||
mat.setTexture("Texture", app.getAssetManager().loadTexture("Effects/Smoke/Smoke.png"));
|
||||
smokeEmitter.setMaterial(mat);
|
||||
|
||||
return smokeEmitter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a small burst of bubbles.
|
||||
*
|
||||
* @return bubbling water texture.
|
||||
*/
|
||||
public ParticleEmitter createWaterSplash() {
|
||||
ParticleEmitter waterSplash = new ParticleEmitter("WaterSplash", Type.Triangle, 30);
|
||||
|
||||
waterSplash.setShape(new EmitterSphereShape(Vector3f.ZERO, 0.2f));
|
||||
|
||||
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
|
||||
|
||||
waterSplash.setStartSize(0.05f);
|
||||
waterSplash.setEndSize(0.1f);
|
||||
|
||||
waterSplash.setLowLife(0.5f);
|
||||
waterSplash.setHighLife(1f);
|
||||
|
||||
|
||||
waterSplash.setGravity(0, 0, 0); // No gravity to simulate a horizontal water splash
|
||||
|
||||
waterSplash.getParticleInfluencer().setInitialVelocity(new Vector3f(1f, 0f, 1f)); // Horizontal spread
|
||||
waterSplash.getParticleInfluencer().setVelocityVariation(1f); // Add randomness to splash
|
||||
waterSplash.setParticlesPerSec(0);
|
||||
|
||||
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;
|
||||
}
|
||||
private final ParticleEffectFactory particleFactory;
|
||||
|
||||
/**
|
||||
* Constructs a {@code SeaSynchronizer} object with the specified application, root node, and ship map.
|
||||
@@ -333,6 +61,7 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
super(app.getGameLogic().getOwnMap(), root);
|
||||
this.app = app;
|
||||
this.map = map;
|
||||
this.particleFactory = new ParticleEffectFactory(app);
|
||||
addExisting();
|
||||
}
|
||||
|
||||
@@ -349,13 +78,49 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
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 the sinking animation and removal of ship if destroyed
|
||||
* @param ship the ship to be sunk
|
||||
*/
|
||||
private void sinkAndRemoveShip(Battleship ship) {
|
||||
Battleship wilkeningklaunichtmeinencode = ship;
|
||||
final Node shipNode = (Node) getSpatial(wilkeningklaunichtmeinencode);
|
||||
if (shipNode == null) return;
|
||||
|
||||
// Add sinking control to animate the sinking
|
||||
shipNode.addControl(new SinkingControl(shipNode));
|
||||
|
||||
// Add particle effects
|
||||
ParticleEmitter bubbles = particleFactory.createWaterSplash();
|
||||
bubbles.setLocalTranslation(shipNode.getLocalTranslation());
|
||||
shipNode.attachChild(bubbles);
|
||||
bubbles.emitAllParticles();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param shot a hit
|
||||
* @return always null to prevent the representation from being attached
|
||||
* to the items node as well
|
||||
* @return always null to prevent the representation from being attached to the items node as well
|
||||
*/
|
||||
private Spatial handleHit(Shot shot) {
|
||||
final Battleship ship = requireNonNull(map.findShipAt(shot), "Missing ship");
|
||||
@@ -367,14 +132,14 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
Node hitEffectNode = new Node("HitEffectNode");
|
||||
|
||||
// Create particle effects
|
||||
ParticleEmitter flame = createFlame();
|
||||
ParticleEmitter flash = createFlash();
|
||||
ParticleEmitter spark = createSpark();
|
||||
ParticleEmitter roundSpark = createRoundSpark();
|
||||
ParticleEmitter smokeTrail = createSmokeTrail();
|
||||
ParticleEmitter debris = createDebris();
|
||||
ParticleEmitter shockwave = createShockwave();
|
||||
ParticleEmitter movingSmoke = createMovingSmokeEmitter(); // New moving smoke emitter
|
||||
ParticleEmitter flame = particleFactory.createFlame();
|
||||
ParticleEmitter flash = particleFactory.createFlash();
|
||||
ParticleEmitter spark = particleFactory.createSpark();
|
||||
ParticleEmitter roundSpark = particleFactory.createRoundSpark();
|
||||
ParticleEmitter smokeTrail = particleFactory.createSmokeTrail();
|
||||
ParticleEmitter debris = particleFactory.createDebris();
|
||||
ParticleEmitter shockwave = particleFactory.createShockwave();
|
||||
ParticleEmitter movingSmoke = particleFactory.createMovingSmokeEmitter();
|
||||
|
||||
// Attach all effects to the hitEffectNode
|
||||
hitEffectNode.attachChild(flame);
|
||||
@@ -403,36 +168,14 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
flame.emitAllParticles();
|
||||
roundSpark.emitAllParticles();
|
||||
|
||||
//Checks if ship is destroyed and triggers animation accordingly
|
||||
if (ship.isDestroyed()) {
|
||||
// Add ShipSinkingControl to the shipNode
|
||||
ShipSinkingControl sinkingControl = new ShipSinkingControl(2f, 5f, -5f, 60f);
|
||||
shipNode.addControl(sinkingControl);
|
||||
sinkingControl.startSinking(); // Start the sinking process
|
||||
|
||||
sinkAndRemoveShip(ship);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = createWaterSplash();
|
||||
waterSplash.setLocalTranslation(shot.getY() + 0.5f, 0f, shot.getX() + 0.5f);
|
||||
shotNode.attachChild(waterSplash);
|
||||
waterSplash.emitAllParticles();
|
||||
|
||||
return shotNode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a cylinder geometry representing the specified shot.
|
||||
* The appearance of the cylinder depends on whether the shot is a hit or a miss.
|
||||
@@ -484,17 +227,11 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
*/
|
||||
private Spatial createShip(Battleship ship) {
|
||||
switch (ship.getLength()) {
|
||||
case 4:
|
||||
return createBattleship(ship);
|
||||
case 3:
|
||||
return createCV(ship);
|
||||
case 2:
|
||||
return createBattle(ship);
|
||||
case 1:
|
||||
return createSmallShip(ship);
|
||||
|
||||
default:
|
||||
return createBox(ship);
|
||||
case 4: return createBattleship(ship);
|
||||
case 3: return createCV(ship);
|
||||
case 2: return createBattle(ship);
|
||||
case 1: return createSmallship(ship);
|
||||
default: return createBox(ship);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -538,26 +275,27 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
* Creates a detailed 3D model to represent a "King George V" battleship.
|
||||
*
|
||||
* @param ship the battleship to be represented
|
||||
* @return the spatial representing the "King George V" battleship.
|
||||
* @return the spatial representing the "King George V" battleship
|
||||
*/
|
||||
private Spatial createBattleship(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(KING_GEORGE_V_MODEL);
|
||||
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
||||
model.scale(1.48f);
|
||||
// model.scale(0.0007f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a detailed 3D model to represent a small tugboat.
|
||||
* Creates a detailed 3D model to represent a small tug boat.
|
||||
*
|
||||
* @param ship the battleship to be represented
|
||||
* @return the spatial representing the small tugboat.
|
||||
* @return the spatial representing a small tug boat
|
||||
*/
|
||||
private Spatial createSmallShip(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(SMALL_BOAT_MODEL);
|
||||
private Spatial createSmallship(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(BOAT_SMALL_MODEL);
|
||||
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
||||
model.scale(0.0005f);
|
||||
@@ -567,27 +305,10 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a detailed 3D model to represent a U-Boat .
|
||||
* Creates a detailed 3D model to represent a "German WWII UBoat".
|
||||
*
|
||||
* @param ship the battleship to be represented
|
||||
* @return the spatial representing the U-Boat.
|
||||
*/
|
||||
private Spatial createBattle(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(BATTLE_MODEL);
|
||||
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
||||
// model.move(0f, -0.05f, 0f);
|
||||
model.scale(0.27f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a detailed 3D model to represent an aircraft carrier
|
||||
*
|
||||
* @param ship the battleship to be represented
|
||||
* @return the spatial representing the aircraft carrier.
|
||||
* @return the spatial representing the "German WWII UBoat"
|
||||
*/
|
||||
private Spatial createCV(Battleship ship) {
|
||||
final Spatial model = app.getAssetManager().loadModel(CV_MODEL);
|
||||
@@ -600,6 +321,23 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
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) {
|
||||
final Spatial model = app.getAssetManager().loadModel(BATTLE_MODEL);
|
||||
|
||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
||||
model.move(0f, -0.06f, 0f);
|
||||
model.scale(0.27f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the rotation angle for the specified rotation.
|
||||
*
|
||||
@@ -614,26 +352,4 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
case UP -> PI;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a 3D model representation of the given {@code Shell} object
|
||||
* for visualization in the game.
|
||||
*
|
||||
* @param shell The {@code Shell} object to be visualized.
|
||||
* @return A {@code Spatial} object representing the 3D model of the shell.
|
||||
*/
|
||||
@Override
|
||||
public Spatial visit(Shell shell) {
|
||||
final Spatial model = app.getAssetManager().loadModel("Models/Shell/shell.j3o");
|
||||
model.setLocalScale(.05f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
Material mat = new Material(app.getAssetManager(), LIGHTING);
|
||||
mat.setTexture("DiffuseMap", app.getAssetManager().loadTexture("Models/Shell/shell_color.png"));
|
||||
mat.setReceivesShadows(true);
|
||||
model.setMaterial(mat);
|
||||
|
||||
model.addControl(new ShellControl(shell));
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,50 +0,0 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
import pp.battleship.model.Shell;
|
||||
import pp.util.Position;
|
||||
|
||||
/**
|
||||
* Controls the 2D representation of a {@code Shell} in the game, updating its position
|
||||
* based on the shell's current state in the game model. The {@code Shell2DControl} class
|
||||
* is responsible for translating the shell's 3D position to a 2D view position within
|
||||
* the game's map view.
|
||||
*/
|
||||
public class Shell2DControl extends AbstractControl {
|
||||
private final Shell shell;
|
||||
private final MapView view;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code Shell2DControl} to manage the 2D visualization of the given {@code Shell}.
|
||||
*
|
||||
* @param view The {@code MapView} used to get information about the map to display.
|
||||
* @param shell The {@code Shell} being visualized.
|
||||
*/
|
||||
public Shell2DControl(MapView view, Shell shell){
|
||||
this.shell = shell;
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the position of the shell's 2D representation based on the shell's current
|
||||
* 3D position in the game model. The position is mapped from model space to view space
|
||||
* coordinates and translated to the appropriate location within the {@code MapView}.
|
||||
*
|
||||
* @param tpf Time per frame, representing the time elapsed since the last frame.
|
||||
*/
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
Vector3f shellPos = shell.getPosition();
|
||||
Position viewPos = view.modelToView(shellPos.x, shellPos.z);
|
||||
spatial.setLocalTranslation(viewPos.getX() + MapView.FIELD_SIZE / 2, viewPos.getY() + MapView.FIELD_SIZE / 2, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
// No rendering-specific behavior required for this control
|
||||
}
|
||||
}
|
||||
|
@@ -1,51 +0,0 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
import pp.battleship.model.Shell;
|
||||
|
||||
import static pp.util.FloatMath.PI;
|
||||
|
||||
/**
|
||||
* Controls the 3D representation of a {@code Shell} in the game, updating its position
|
||||
* and rotation based on the shell's current state in the game model. The {@code ShellControl}
|
||||
* class ensures that the spatial associated with the shell is positioned and oriented correctly
|
||||
* within the world.
|
||||
*/
|
||||
public class ShellControl extends AbstractControl {
|
||||
private final Shell shell;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code ShellControl} to manage the 3D visualization of the given {@code Shell}.
|
||||
*
|
||||
* @param shell The {@code Shell} being visualized and controlled.
|
||||
*/
|
||||
public ShellControl(Shell shell){
|
||||
super();
|
||||
this.shell = shell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the 3D position and rotation of the shell based on its current state.
|
||||
* Converts map coordinates to world coordinates and applies the shell's orientation.
|
||||
*
|
||||
* @param tpf Time per frame, representing the elapsed time since the last update.
|
||||
*/
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
Vector3f pos = shell.getPosition();
|
||||
Vector3f fixed = new Vector3f(pos.z + 0.5f, pos.y, pos.x + 0.5f);
|
||||
fixed.setY(pos.y);
|
||||
spatial.setLocalTranslation(fixed);
|
||||
spatial.setLocalRotation(shell.getRotation());
|
||||
spatial.rotate(PI/2,0,0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
// No rendering-specific behavior required for this control
|
||||
}
|
||||
}
|
||||
|
@@ -1,116 +0,0 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
|
||||
/**
|
||||
* Controls the burning, tilting, and sinking behavior of a battleship.
|
||||
* The ship will burn and tilt for a specified duration, then sink below the water surface.
|
||||
*/
|
||||
public class ShipSinkingControl extends AbstractControl {
|
||||
|
||||
private float elapsedTime = 0f;
|
||||
private final float burnTiltDuration;
|
||||
private final float sinkDuration;
|
||||
private final float sinkDepth;
|
||||
private final float tiltAngle;
|
||||
private final Vector3f initialPosition;
|
||||
private boolean sinkingStarted = false;
|
||||
|
||||
/**
|
||||
* Constructs a new ShipSinkingControl instance.
|
||||
*
|
||||
* @param burnTiltDuration Time in seconds for the ship to burn and tilt on the surface
|
||||
* @param sinkDuration Time in seconds for the ship to fully sink
|
||||
* @param sinkDepth Depth below the water to sink the ship
|
||||
* @param tiltAngle Final tilt angle in degrees
|
||||
*/
|
||||
public ShipSinkingControl(float burnTiltDuration, float sinkDuration, float sinkDepth, float tiltAngle) {
|
||||
this.burnTiltDuration = burnTiltDuration;
|
||||
this.sinkDuration = sinkDuration;
|
||||
this.sinkDepth = sinkDepth;
|
||||
this.tiltAngle = tiltAngle;
|
||||
this.initialPosition = new Vector3f(); // Placeholder; will be set in controlUpdate
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides controlUpdate in AbstractControl
|
||||
* regulates the burn and tilt timeframe
|
||||
* @param tpf time per frame (in seconds)
|
||||
*/
|
||||
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
if (spatial == null) return;
|
||||
|
||||
elapsedTime += tpf;
|
||||
|
||||
if (elapsedTime < burnTiltDuration) {
|
||||
float progress = elapsedTime / burnTiltDuration;
|
||||
|
||||
float angleInRadians = FastMath.DEG_TO_RAD * FastMath.interpolateLinear(progress, 0f, -tiltAngle);
|
||||
Quaternion tiltRotation = new Quaternion().fromAngles(angleInRadians, 0, 0);
|
||||
spatial.setLocalRotation(tiltRotation);
|
||||
return;
|
||||
}
|
||||
|
||||
// Start sinking if it hasn't started yet
|
||||
if (!sinkingStarted) {
|
||||
sinkingStarted = true;
|
||||
// Save the initial position when sinking starts
|
||||
initialPosition.set(spatial.getLocalTranslation());
|
||||
|
||||
// Remove the hitEffectNode
|
||||
Node parentNode = (Node) spatial;
|
||||
Spatial hitEffects = parentNode.getChild("HitEffectNode");
|
||||
if (hitEffects != null) {
|
||||
parentNode.detachChild(hitEffects);
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the progress of the sinking (0 to 1)
|
||||
float progress = Math.min((elapsedTime - burnTiltDuration) / sinkDuration, 1f);
|
||||
|
||||
// Apply the tilt angle (remains constant during sinking)
|
||||
Quaternion tiltRotation = new Quaternion().fromAngles(-FastMath.DEG_TO_RAD * tiltAngle, 0, 0);
|
||||
spatial.setLocalRotation(tiltRotation);
|
||||
|
||||
// Sink the ship by interpolating the Y position
|
||||
float currentY = FastMath.interpolateLinear(progress, initialPosition.y, sinkDepth);
|
||||
spatial.setLocalTranslation(initialPosition.x, currentY, initialPosition.z);
|
||||
|
||||
if (currentY <= sinkDepth) {
|
||||
Node parentNode = (Node) spatial.getParent();
|
||||
if (parentNode != null) {
|
||||
parentNode.detachChild(spatial);
|
||||
}
|
||||
spatial.removeControl(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called during the rendering phase, but it does not perform any
|
||||
* operations in this implementation as the control only influences the spatial's
|
||||
* transformation, not its rendering process.
|
||||
*
|
||||
* @param rm the RenderManager rendering the controlled Spatial (not null)
|
||||
* @param vp the ViewPort being rendered (not null)
|
||||
*/
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
// No rendering logic is needed for this control
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the sinking process for the ship.
|
||||
*/
|
||||
public void startSinking() {
|
||||
// Nothing to do here as the control update handles the timing and sequence
|
||||
}
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.Node;
|
||||
|
||||
/**
|
||||
* Control that handles the sinking effect for destroyed ships.
|
||||
* It will gradually move the ship downwards and then remove it from the scene.
|
||||
*/
|
||||
class SinkingControl extends AbstractControl {
|
||||
private static final float SINK_DURATION = 5f; // Duration of the sinking animation
|
||||
private static final float SINK_SPEED = 0.1f; // Speed at which the ship sinks
|
||||
private float elapsedTime = 0;
|
||||
|
||||
private final Node shipNode;
|
||||
|
||||
/**
|
||||
* Constructs a {@code SinkingControl} object with the shipNode to be to be sunk
|
||||
* @param shipNode the node to handeld
|
||||
*/
|
||||
public SinkingControl(Node shipNode) {
|
||||
this.shipNode = shipNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updated the Map to sink the ship
|
||||
*
|
||||
* @param tpf time per frame
|
||||
*/
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
// Update the sinking effect
|
||||
elapsedTime += tpf;
|
||||
|
||||
// Move the ship down over time
|
||||
Vector3f currentPos = shipNode.getLocalTranslation();
|
||||
shipNode.setLocalTranslation(currentPos.x, currentPos.y - SINK_SPEED * tpf, currentPos.z);
|
||||
|
||||
// Check if sinking duration has passed
|
||||
if (elapsedTime >= SINK_DURATION) {
|
||||
// Remove the ship from the scene
|
||||
shipNode.removeFromParent();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
// No rendering-related code needed
|
||||
}
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.simsilica.lemur.Slider;
|
||||
import pp.battleship.client.GameMusic;
|
||||
|
||||
|
||||
public class VolumeControl extends Slider {
|
||||
|
||||
private final GameMusic menuMusicModern;
|
||||
|
||||
private double vol;
|
||||
|
||||
public VolumeControl(GameMusic music) {
|
||||
super();
|
||||
this.menuMusicModern = music;
|
||||
vol = GameMusic.volumePreference();
|
||||
getModel().setPercent(vol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the volume of the music to the appropriate level set by the User through the Volume control Slider
|
||||
*
|
||||
*/
|
||||
public void update() {
|
||||
if (vol != getModel().getPercent()) {
|
||||
vol = getModel().getPercent();
|
||||
menuMusicModern.setVolume( (float) vol);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -0,0 +1,35 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.simsilica.lemur.Slider;
|
||||
/**
|
||||
* The VolumeSlider class represents the Volume Slider in the Menu.
|
||||
* It extends the Slider class and provides functionalities for setting the music volume,
|
||||
* with the help of the Slider in the GUI
|
||||
*/
|
||||
public class VolumeSlider extends Slider {
|
||||
|
||||
private final GameMusic music;
|
||||
private double vol;
|
||||
|
||||
/**
|
||||
* Constructs the Volume Slider for the Menu dialog
|
||||
* @param music the music instance
|
||||
*/
|
||||
public VolumeSlider(GameMusic music) {
|
||||
super();
|
||||
this.music = music;
|
||||
vol = GameMusic.volumeInPreferences();
|
||||
getModel().setPercent(vol);
|
||||
}
|
||||
|
||||
/**
|
||||
* when triggered it updates the volume to the value set with the slider
|
||||
*/
|
||||
public void update() {
|
||||
if (vol != getModel().getPercent()) {
|
||||
vol = getModel().getPercent();
|
||||
music.setVolume( (float) vol);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -5,7 +5,7 @@
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.battleship.client.server;
|
||||
package pp.battleship.server;
|
||||
|
||||
import com.jme3.network.ConnectionListener;
|
||||
import com.jme3.network.HostedConnection;
|
||||
@@ -18,7 +18,6 @@ import pp.battleship.BattleshipConfig;
|
||||
import pp.battleship.game.server.Player;
|
||||
import pp.battleship.game.server.ServerGameLogic;
|
||||
import pp.battleship.game.server.ServerSender;
|
||||
import pp.battleship.message.client.AnimationFinishedMessage;
|
||||
import pp.battleship.message.client.ClientMessage;
|
||||
import pp.battleship.message.client.MapMessage;
|
||||
import pp.battleship.message.client.ShootMessage;
|
||||
@@ -42,14 +41,14 @@ import java.util.logging.LogManager;
|
||||
/**
|
||||
* Server implementing the visitor pattern as MessageReceiver for ClientMessages
|
||||
*/
|
||||
public class BattleshipSelfhostServer implements MessageListener<HostedConnection>, ConnectionListener, ServerSender {
|
||||
private static final Logger LOGGER = System.getLogger(BattleshipSelfhostServer.class.getName());
|
||||
public class BattleshipServer implements MessageListener<HostedConnection>, ConnectionListener, ServerSender {
|
||||
private static final Logger LOGGER = System.getLogger(BattleshipServer.class.getName());
|
||||
private static final File CONFIG_FILE = new File("server.properties");
|
||||
|
||||
private final BattleshipConfig config = new BattleshipConfig();
|
||||
private Server myServer;
|
||||
private final ServerGameLogic logic;
|
||||
private final BlockingQueue<ReceivedMessageSelfhost> pendingMessages = new LinkedBlockingQueue<>();
|
||||
private final BlockingQueue<ReceivedMessage> pendingMessages = new LinkedBlockingQueue<>();
|
||||
|
||||
static {
|
||||
// Configure logging
|
||||
@@ -64,16 +63,16 @@ public class BattleshipSelfhostServer implements MessageListener<HostedConnectio
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the server.
|
||||
* Starts the Battleships server.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
new BattleshipSelfhostServer().run();
|
||||
new BattleshipServer().run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the server.
|
||||
*/
|
||||
BattleshipSelfhostServer() {
|
||||
BattleshipServer() {
|
||||
config.readFromIfExists(CONFIG_FILE);
|
||||
LOGGER.log(Level.INFO, "Configuration: {0}", config); //NON-NLS
|
||||
logic = new ServerGameLogic(this, config);
|
||||
@@ -116,7 +115,6 @@ public class BattleshipSelfhostServer implements MessageListener<HostedConnectio
|
||||
Serializer.registerClass(MapMessage.class);
|
||||
Serializer.registerClass(ShootMessage.class);
|
||||
Serializer.registerClass(EffectMessage.class);
|
||||
Serializer.registerClass(AnimationFinishedMessage.class);
|
||||
Serializer.registerClass(Battleship.class);
|
||||
Serializer.registerClass(IntPoint.class);
|
||||
Serializer.registerClass(Shot.class);
|
||||
@@ -125,7 +123,6 @@ public class BattleshipSelfhostServer implements MessageListener<HostedConnectio
|
||||
private void registerListeners() {
|
||||
myServer.addMessageListener(this, MapMessage.class);
|
||||
myServer.addMessageListener(this, ShootMessage.class);
|
||||
myServer.addMessageListener(this, AnimationFinishedMessage.class);
|
||||
myServer.addConnectionListener(this);
|
||||
}
|
||||
|
||||
@@ -133,7 +130,7 @@ public class BattleshipSelfhostServer implements MessageListener<HostedConnectio
|
||||
public void messageReceived(HostedConnection source, Message message) {
|
||||
LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS
|
||||
if (message instanceof ClientMessage clientMessage)
|
||||
pendingMessages.add(new ReceivedMessageSelfhost(clientMessage, source.getId()));
|
||||
pendingMessages.add(new ReceivedMessage(clientMessage, source.getId()));
|
||||
}
|
||||
|
||||
@Override
|
@@ -5,12 +5,12 @@
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.battleship.client.server;
|
||||
package pp.battleship.server;
|
||||
|
||||
import pp.battleship.message.client.ClientInterpreter;
|
||||
import pp.battleship.message.client.ClientMessage;
|
||||
|
||||
record ReceivedMessageSelfhost(ClientMessage message, int from) {
|
||||
record ReceivedMessage(ClientMessage message, int from) {
|
||||
void process(ClientInterpreter interpreter) {
|
||||
message.accept(interpreter, from);
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
|
||||
# File Created: 29.03.2012 14:25:39
|
||||
|
||||
newmtl default
|
||||
Ns 35.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 1.0000 1.0000 1.0000
|
||||
Kd 1.0000 1.0000 1.0000
|
||||
Ks 0.5400 0.5400 0.5400
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka 14084_WWII_ship_German_Type_II_U-boat_diff.jpg
|
||||
map_Kd 14084_WWII_ship_German_Type_II_U-boat_diff.jpg
|
@@ -1,104 +0,0 @@
|
||||
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
|
||||
# File Created: 16.12.2011 14:18:52
|
||||
|
||||
newmtl white
|
||||
Ns 53.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.6667 0.6667 0.6667
|
||||
Kd 0.6667 0.6667 0.6667
|
||||
Ks 0.1800 0.1800 0.1800
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl boat_elements_black
|
||||
Ns 55.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.0000 0.0000 0.0000
|
||||
Kd 0.0000 0.0000 0.0000
|
||||
Ks 0.3600 0.3600 0.3600
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl boat_glass
|
||||
Ns 60.0000
|
||||
Ni 7.0000
|
||||
d 0.4000
|
||||
Tr 0.6000
|
||||
Tf 0.4000 0.4000 0.4000
|
||||
illum 2
|
||||
Ka 0.1059 0.1569 0.1451
|
||||
Kd 0.1059 0.1569 0.1451
|
||||
Ks 0.6750 0.6750 0.6750
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl boat_screw_hooks_bronze
|
||||
Ns 80.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.2941 0.2157 0.0510
|
||||
Kd 0.2941 0.2157 0.0510
|
||||
Ks 0.7200 0.7200 0.7200
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl boat_silver
|
||||
Ns 80.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 0.3333 0.3333 0.3333
|
||||
Kd 0.3333 0.3333 0.3333
|
||||
Ks 0.7200 0.7200 0.7200
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
|
||||
newmtl boat_buffer
|
||||
Ns 10.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 1.0000 1.0000 1.0000
|
||||
Kd 1.0000 1.0000 1.0000
|
||||
Ks 0.2700 0.2700 0.2700
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka boat_buffer_diffuse.jpg
|
||||
map_Kd boat_buffer_diffuse.jpg
|
||||
|
||||
newmtl boat_roof_accessory
|
||||
Ns 15.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 1.0000 1.0000 1.0000
|
||||
Kd 1.0000 1.0000 1.0000
|
||||
Ks 0.3600 0.3600 0.3600
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka boat_roof_accessory_diffuse.jpg
|
||||
map_Kd boat_roof_accessory_diffuse.jpg
|
||||
|
||||
newmtl boat_body
|
||||
Ns 55.0000
|
||||
Ni 1.5000
|
||||
d 1.0000
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 2
|
||||
Ka 1.0000 1.0000 1.0000
|
||||
Kd 1.0000 1.0000 1.0000
|
||||
Ks 0.3600 0.3600 0.3600
|
||||
Ke 0.0000 0.0000 0.0000
|
||||
map_Ka boat_body_diffuse.jpg
|
||||
map_Kd boat_body_diffuse.jpg
|
Before Width: | Height: | Size: 78 B |
@@ -1,180 +0,0 @@
|
||||
newmtl Model001_Material001
|
||||
map_Kd Yorktown_paint6.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material002
|
||||
map_Kd diff_null_7.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material003
|
||||
map_Kd diff_null_14.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material004
|
||||
map_Kd diff_null_Color005.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material005
|
||||
map_Kd diff_null_8.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material006
|
||||
map_Kd diff_null_Color007.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material007
|
||||
map_Kd diff_null_17.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material008
|
||||
map_Kd diff_null_FrontColor.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material009
|
||||
map_Kd diff_null_BackColor.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material010
|
||||
map_Kd diff_null_4.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material011
|
||||
map_Kd Color_004.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material012
|
||||
map_Kd diff_null_Gray1.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material013
|
||||
map_Kd diff_null_3.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material014
|
||||
map_Kd Metal_Rough.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material015
|
||||
map_Kd diff_null_12.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material016
|
||||
map_Kd diff_null_19.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material017
|
||||
map_Kd diff_null_Color003.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material018
|
||||
map_Kd diff_null_mat1.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material019
|
||||
map_Kd diff_null_1.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material020
|
||||
map_Kd diff_null_2.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material021
|
||||
map_Kd diff_null_Black1.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material022
|
||||
map_Kd diff_null_Model001Materia.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material023
|
||||
map_Kd diff_null_Model001Mate1.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material024
|
||||
map_Kd diff_null_13.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material025
|
||||
map_Kd _6.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material026
|
||||
map_Kd Metal_Aluminum_Anodized.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material027
|
||||
map_Kd diff_null_Color006.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material028
|
||||
map_Kd Blinds_Vertical_Stripe_Gray.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material029
|
||||
map_Kd diff_null_15.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material030
|
||||
map_Kd diff_null_Color002.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material031
|
||||
map_Kd Cladding_Siding_Tan.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material032
|
||||
map_Kd diff_null_Color008.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material033
|
||||
map_Kd diff_null_16.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material034
|
||||
map_Kd _2.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material035
|
||||
map_Kd Blinds_Roman_Hobbled_Blue.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material036
|
||||
map_Kd Blinds_Wood_White.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material037
|
||||
map_Kd Metal_Seamed.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material038
|
||||
map_Kd image_16.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material039
|
||||
map_Kd diff_null_9.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material040
|
||||
map_Kd image_15.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material041
|
||||
map_Kd _Blinds_Roman_Hobbled_Blue_1.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material042
|
||||
map_Kd diff_null_10.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material043
|
||||
map_Kd diff_null_Material5.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material044
|
||||
map_Kd diff_null_Material1.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
||||
newmtl Model001_Material045
|
||||
map_Kd diff_null_11.png
|
||||
map_bump bumpmap_flat.png
|
||||
|
Before Width: | Height: | Size: 43 KiB |
@@ -41,13 +41,10 @@ public class ModelExporter extends SimpleApplication {
|
||||
*/
|
||||
@Override
|
||||
public void simpleInitApp() {
|
||||
export("Models/KingGeorgeV/King_George_V.obj", "KingGeorgeV.j3o");//NON-NLS
|
||||
export("Models/BoatSmall/12219_boat_v2_L2.obj", "12219_boat_v2_L2.j3o");
|
||||
export("Models/KingGeorgeV/King_George_V.obj", "KingGeorgeV.j3o"); //NON-NLS
|
||||
export("Models/BoatSmall/12219_boat_v2_L2.obj", "BoatSmall.j3o"); //NON-NLS
|
||||
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");
|
||||
|
||||
|
||||
|
||||
stop();
|
||||
}
|
||||
|
Before Width: | Height: | Size: 78 B |
Before Width: | Height: | Size: 127 KiB |
Before Width: | Height: | Size: 94 KiB |
Before Width: | Height: | Size: 90 KiB |
Before Width: | Height: | Size: 147 KiB |
Before Width: | Height: | Size: 109 KiB |
Before Width: | Height: | Size: 101 KiB |
Before Width: | Height: | Size: 102 KiB |
Before Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 3.0 MiB |
Before Width: | Height: | Size: 246 KiB |
Before Width: | Height: | Size: 330 KiB |
@@ -11,7 +11,6 @@ import pp.battleship.message.client.ShootMessage;
|
||||
import pp.battleship.message.server.EffectMessage;
|
||||
import pp.battleship.model.IntPoint;
|
||||
import pp.battleship.model.ShipMap;
|
||||
import pp.battleship.model.Shell;
|
||||
import pp.battleship.notification.Sound;
|
||||
|
||||
import java.lang.System.Logger.Level;
|
||||
@@ -54,13 +53,16 @@ class BattleState extends ClientState {
|
||||
@Override
|
||||
public void receivedEffect(EffectMessage msg) {
|
||||
ClientGameLogic.LOGGER.log(Level.INFO, "report effect: {0}", msg); //NON-NLS
|
||||
playSound(msg);
|
||||
myTurn = msg.isMyTurn();
|
||||
logic.setInfoText(msg.getInfoTextKey());
|
||||
Shell shell = new Shell(msg.getShot());
|
||||
affectedMap(msg).add(shell);
|
||||
logic.playSound(Sound.SHELL_FLYING);
|
||||
logic.setState(new ShootingState(logic, shell, myTurn, msg));
|
||||
|
||||
affectedMap(msg).add(msg.getShot());
|
||||
if (destroyedOpponentShip(msg))
|
||||
logic.getOpponentMap().add(msg.getDestroyedShip());
|
||||
if (msg.isGameOver()) {
|
||||
msg.getRemainingOpponentShips().forEach(logic.getOpponentMap()::add);
|
||||
logic.setState(new GameOverState(logic));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,4 +74,29 @@ class BattleState extends ClientState {
|
||||
private ShipMap affectedMap(EffectMessage msg) {
|
||||
return msg.isOwnShot() ? logic.getOpponentMap() : logic.getOwnMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the opponent's ship was destroyed by the player's shot.
|
||||
*
|
||||
* @param msg the effect message received from the server
|
||||
* @return true if the shot destroyed an opponent's ship, false otherwise
|
||||
*/
|
||||
private boolean destroyedOpponentShip(EffectMessage msg) {
|
||||
return msg.getDestroyedShip() != null && msg.isOwnShot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays a sound based on the outcome of the shot. Different sounds are played for a miss, hit,
|
||||
* or destruction of a ship.
|
||||
*
|
||||
* @param msg the effect message containing the result of the shot
|
||||
*/
|
||||
private void playSound(EffectMessage msg) {
|
||||
if (!msg.getShot().isHit())
|
||||
logic.playSound(Sound.SPLASH);
|
||||
else if (msg.getDestroyedShip() == null)
|
||||
logic.playSound(Sound.EXPLOSION);
|
||||
else
|
||||
logic.playSound(Sound.DESTROYED_SHIP);
|
||||
}
|
||||
}
|
||||
|
@@ -1,114 +0,0 @@
|
||||
package pp.battleship.game.client;
|
||||
|
||||
import pp.battleship.message.client.AnimationFinishedMessage;
|
||||
import pp.battleship.message.server.EffectMessage;
|
||||
import pp.battleship.model.Battleship;
|
||||
import pp.battleship.model.Shell;
|
||||
import pp.battleship.model.ShipMap;
|
||||
import pp.battleship.notification.Sound;
|
||||
|
||||
/**
|
||||
* Represents the shooting state of the game where a shell is fired at the opponent.
|
||||
*/
|
||||
public class ShootingState extends ClientState {
|
||||
private float shootValue;
|
||||
private final static float SHELL_SPEED = 0.3f;
|
||||
private final Shell shell;
|
||||
private final boolean myTurn;
|
||||
private final EffectMessage msg;
|
||||
|
||||
/**
|
||||
* Constructs a shooting state with the specified game logic.
|
||||
*
|
||||
* @param logic the game logic
|
||||
* @param shell the shell being shot
|
||||
* @param myTurn indicates if it is the player's turn
|
||||
* @param msg the effect message associated with the shooting action
|
||||
*/
|
||||
public ShootingState(ClientGameLogic logic, Shell shell, boolean myTurn, EffectMessage msg) {
|
||||
super(logic);
|
||||
this.msg = msg;
|
||||
this.myTurn = myTurn;
|
||||
this.shell = shell;
|
||||
this.shootValue = 0;
|
||||
shell.move(shootValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showBattle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the shooting state by moving the shell based on the elapsed time.
|
||||
*
|
||||
* @param delta the time in seconds since the last update
|
||||
*/
|
||||
@Override
|
||||
void update(float delta) {
|
||||
super.update(delta);
|
||||
if (shootValue > 1) {
|
||||
endState();
|
||||
}
|
||||
else {
|
||||
shootValue += delta * SHELL_SPEED;
|
||||
shell.move(shootValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the shooting state and processes the effects of the shot.
|
||||
*/
|
||||
private void endState() {
|
||||
playSound(msg);
|
||||
affectedMap(msg).add(msg.getShot());
|
||||
affectedMap(msg).remove(shell);
|
||||
|
||||
if (destroyedOpponentShip(msg))
|
||||
logic.getOpponentMap().add(msg.getDestroyedShip());
|
||||
if (msg.isGameOver()) {
|
||||
for (Battleship ship : msg.getRemainingOpponentShips()) {
|
||||
logic.getOpponentMap().add(ship);
|
||||
}
|
||||
logic.setState(new GameOverState(logic));
|
||||
return;
|
||||
}
|
||||
logic.send(new AnimationFinishedMessage());
|
||||
logic.setState(new BattleState(logic, myTurn));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an opponent's ship was destroyed by the shot.
|
||||
*
|
||||
* @param msg the effect message containing the shot details
|
||||
* @return true if an opponent's ship was destroyed, false otherwise
|
||||
*/
|
||||
private boolean destroyedOpponentShip(EffectMessage msg) {
|
||||
return msg.getDestroyedShip() != null && msg.isOwnShot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the affected map based on whether the shot was owned by the player or the opponent.
|
||||
*
|
||||
* @param msg the effect message containing shot details
|
||||
* @return the ShipMap that was affected by the shot
|
||||
*/
|
||||
private ShipMap affectedMap(EffectMessage msg) {
|
||||
return msg.isOwnShot() ? logic.getOpponentMap() : logic.getOwnMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays a sound based on the outcome of the shot. Different sounds are played for a miss, hit,
|
||||
* or destruction of a ship.
|
||||
*
|
||||
* @param msg the effect message containing the result of the shot
|
||||
*/
|
||||
private void playSound(EffectMessage msg) {
|
||||
if (!msg.getShot().isHit())
|
||||
logic.playSound(Sound.SPLASH);
|
||||
else if (msg.getDestroyedShip() == null)
|
||||
logic.playSound(Sound.EXPLOSION);
|
||||
else
|
||||
logic.playSound(Sound.DESTROYED_SHIP);
|
||||
}
|
||||
}
|
@@ -9,9 +9,9 @@ package pp.battleship.game.server;
|
||||
|
||||
import pp.battleship.BattleshipConfig;
|
||||
import pp.battleship.message.client.ClientInterpreter;
|
||||
import pp.battleship.message.client.ClientMessage;
|
||||
import pp.battleship.message.client.MapMessage;
|
||||
import pp.battleship.message.client.ShootMessage;
|
||||
import pp.battleship.message.client.AnimationFinishedMessage;
|
||||
import pp.battleship.message.server.EffectMessage;
|
||||
import pp.battleship.message.server.GameDetails;
|
||||
import pp.battleship.message.server.ServerMessage;
|
||||
@@ -36,7 +36,6 @@ 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<Player> waitPlayers = new HashSet<>();
|
||||
private final ServerSender serverSender;
|
||||
private Player activePlayer;
|
||||
private ServerState state = ServerState.WAIT;
|
||||
@@ -136,7 +135,7 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
|
||||
/**
|
||||
* Handles the reception of a MapMessage.
|
||||
* Also tests valid ship placement on the Map.
|
||||
* Also tests if Map is in correct format
|
||||
*
|
||||
* @param msg the received MapMessage
|
||||
* @param from the ID of the sender client
|
||||
@@ -145,19 +144,60 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
public void received(MapMessage msg, int from) {
|
||||
if (state != ServerState.SET_UP)
|
||||
LOGGER.log(Level.ERROR, "playerReady not allowed in {0}", state); //NON-NLS
|
||||
else {
|
||||
if (checkMap(msg.getShips())) {
|
||||
playerReady(getPlayerById(from), msg.getShips());
|
||||
}
|
||||
else {
|
||||
LOGGER.log(Level.WARNING, "Invalid Map sent from player {0}", from); //NON-NLS
|
||||
send(players.get(from), new GameDetails(config));
|
||||
}
|
||||
|
||||
Player cp = getPlayerById(from);
|
||||
List<Battleship> ships = msg.getShips();
|
||||
|
||||
if (!validateShips(ships)) {
|
||||
LOGGER.log(Level.ERROR, "Invalid ship placement by player {0}", from);
|
||||
send(cp, null );
|
||||
return;
|
||||
}
|
||||
|
||||
playerReady(cp, ships);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validates a list of ships.
|
||||
* Validates the list, that no ships are out of bounds or overlap with each other
|
||||
*
|
||||
* @param ships list of ships to validate
|
||||
* @return {@code true} if all ships positions are valid, {@code false} otherwise
|
||||
*/
|
||||
private boolean validateShips(List<Battleship> ships) {
|
||||
Set<IntPoint> occupiedPoints = new HashSet<>();
|
||||
|
||||
for (Battleship ship : ships) {
|
||||
if (!isWithinBounds(ship)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int x = ship.getMinX(); x <= ship.getMaxX(); x++) {
|
||||
for (int y = ship.getMinY(); y <= ship.getMaxY(); y++) {
|
||||
IntPoint point = new IntPoint(x, y);
|
||||
if (!occupiedPoints.add(point)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if a ship is inside the map
|
||||
* @param ship the ship to validate
|
||||
* @return {@code true} if a ship is within bounds, {@code false} otherwise
|
||||
*/
|
||||
private boolean isWithinBounds(Battleship ship) {
|
||||
return ship.getMinX() >= 0 && ship.getMaxX() < config.getMapWidth() &&
|
||||
ship.getMinY() >= 0 && ship.getMaxY() < config.getMapHeight();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles the reception of a ShootMessage.
|
||||
*
|
||||
@@ -168,11 +208,8 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
public void received(ShootMessage msg, int from) {
|
||||
if (state != ServerState.BATTLE)
|
||||
LOGGER.log(Level.ERROR, "shoot not allowed in {0}", state); //NON-NLS
|
||||
else{
|
||||
setState(ServerState.ANIMATION);
|
||||
else
|
||||
shoot(getPlayerById(from), msg.getPosition());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,7 +240,6 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
*/
|
||||
void shoot(Player p, IntPoint pos) {
|
||||
if (p != activePlayer) return;
|
||||
|
||||
final Player otherPlayer = getOpponent(activePlayer);
|
||||
final Battleship selectedShip = otherPlayer.getMap().findShipAt(pos);
|
||||
if (selectedShip == null) {
|
||||
@@ -233,61 +269,4 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Handles the reception of a AnimationFinishedMessage.
|
||||
*
|
||||
* @param msg the received MapMessage
|
||||
* @param from the ID of the sender client
|
||||
*/
|
||||
@Override
|
||||
public void received(AnimationFinishedMessage msg, int from) {
|
||||
if (state != ServerState.ANIMATION) {
|
||||
LOGGER.log(Level.ERROR, "animation finished not allowed in {0}", state);
|
||||
}
|
||||
else {
|
||||
LOGGER.log(Level.DEBUG, "anim received from {0}", getPlayerById(from));
|
||||
Player player = getPlayerById(from);
|
||||
if (!waitPlayers.add(player)) {
|
||||
LOGGER.log(Level.ERROR, "{0} already sent animation finished", player); //NON-NLS
|
||||
return;
|
||||
}
|
||||
if (waitPlayers.size() == 2) {
|
||||
waitPlayers = new HashSet<>();
|
||||
setState(ServerState.BATTLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the placement of battleships on the map.
|
||||
* Ensures that:
|
||||
* <ul>
|
||||
* <li>The number of ships matches the configuration.</li>
|
||||
* <li>Ships are within the map's boundaries.</li>
|
||||
* <li>Ships do not overlap.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param ships the list of {@link Battleship} objects to validate
|
||||
* @return {@code true} if all ships are placed correctly; {@code false} otherwise
|
||||
*/
|
||||
private boolean checkMap(List<Battleship> ships) {
|
||||
int numShips = config.getShipNums().values().stream().mapToInt(Integer::intValue).sum();
|
||||
if (numShips != ships.size()) return false;
|
||||
|
||||
List<IntPoint> occupied = new ArrayList<>();
|
||||
|
||||
for (Battleship battleship : ships) {
|
||||
int x = battleship.getX();
|
||||
int y = battleship.getY();
|
||||
for (int i = 0; i < battleship.getLength(); i++) {
|
||||
if (x >= 0 && x < config.getMapWidth() && y >= 0 && y < config.getMapHeight() && !occupied.contains(new IntPoint(x, y))) {
|
||||
occupied.add(new IntPoint(x, y));
|
||||
x += battleship.getRot().dx();
|
||||
y += battleship.getRot().dy();
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -26,14 +26,8 @@ enum ServerState {
|
||||
*/
|
||||
BATTLE,
|
||||
|
||||
/**
|
||||
* The server is waiting for all clients to finish the shoot animation.
|
||||
*/
|
||||
ANIMATION,
|
||||
|
||||
|
||||
/**
|
||||
* The game has ended because all the ships of one player have been destroyed.
|
||||
*/
|
||||
GAME_OVER,
|
||||
GAME_OVER
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@ import pp.battleship.message.client.ClientInterpreter;
|
||||
import pp.battleship.message.client.ClientMessage;
|
||||
import pp.battleship.message.client.MapMessage;
|
||||
import pp.battleship.message.client.ShootMessage;
|
||||
import pp.battleship.message.client.AnimationFinishedMessage;
|
||||
import pp.battleship.model.Battleship;
|
||||
|
||||
/**
|
||||
@@ -64,12 +63,6 @@ class Copycat implements ClientInterpreter {
|
||||
copiedMessage = new MapMessage(msg.getShips().stream().map(Copycat::copy).toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(AnimationFinishedMessage msg, int from) {
|
||||
copiedMessage = msg;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a copy of the provided {@link Battleship}.
|
||||
*
|
||||
@@ -79,5 +72,4 @@ class Copycat implements ClientInterpreter {
|
||||
private static Battleship copy(Battleship ship) {
|
||||
return new Battleship(ship.getLength(), ship.getX(), ship.getY(), ship.getRot());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@ package pp.battleship.game.singlemode;
|
||||
import pp.battleship.game.client.BattleshipClient;
|
||||
import pp.battleship.message.client.MapMessage;
|
||||
import pp.battleship.message.client.ShootMessage;
|
||||
import pp.battleship.message.client.AnimationFinishedMessage;
|
||||
import pp.battleship.message.server.EffectMessage;
|
||||
import pp.battleship.message.server.GameDetails;
|
||||
import pp.battleship.message.server.ServerInterpreter;
|
||||
@@ -122,7 +121,6 @@ class RobotClient implements ServerInterpreter {
|
||||
@Override
|
||||
public void received(EffectMessage msg) {
|
||||
LOGGER.log(Level.INFO, "Received EffectMessage: {0}", msg); //NON-NLS
|
||||
connection.sendRobotMessage(new AnimationFinishedMessage());
|
||||
if (msg.isMyTurn())
|
||||
shoot();
|
||||
}
|
||||
|
@@ -1,24 +0,0 @@
|
||||
package pp.battleship.message.client;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* Represents a message indicating that an animation has finished on the client side.
|
||||
*/
|
||||
@Serializable
|
||||
public class AnimationFinishedMessage extends ClientMessage {
|
||||
public AnimationFinishedMessage() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
* @param from the connection ID from which the message was received
|
||||
*/
|
||||
@Override
|
||||
public void accept(ClientInterpreter interpreter, int from) {
|
||||
interpreter.received(this, from);
|
||||
}
|
||||
}
|
@@ -26,12 +26,4 @@ public interface ClientInterpreter {
|
||||
* @param from the connection ID from which the message was received
|
||||
*/
|
||||
void received(MapMessage msg, int from);
|
||||
|
||||
/**
|
||||
* Processes a received AnimationFinishedMessage.
|
||||
*
|
||||
* @param animationFinishedMessage the MapMessage to be processed
|
||||
* @param from the connection ID from which the message was received
|
||||
*/
|
||||
void received(AnimationFinishedMessage animationFinishedMessage, int from);
|
||||
}
|
||||
|
@@ -1,126 +0,0 @@
|
||||
package pp.battleship.model;
|
||||
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
|
||||
/**
|
||||
* The {@code Shell} class represents a projectile fired by a ship in the Battleship game.
|
||||
* It models the position and rotation of the projectile and allows for its movement along
|
||||
* a Bezier curve.
|
||||
*/
|
||||
public class Shell implements Item {
|
||||
/**
|
||||
* Initial position of the shell
|
||||
*/
|
||||
private final static Vector3f INIT_POS = new Vector3f(-3, 7, -3);
|
||||
/**
|
||||
* The overshot difference vector used to get a shallower flight path
|
||||
*/
|
||||
private final static Vector3f OVER_SHOT_DIFF = new Vector3f(-1, -1, -1);
|
||||
// Target shot position
|
||||
private final Vector3f shotPosition;
|
||||
// Position on top of shotPosition used for Bezier curve
|
||||
private final Vector3f overShotPosition;
|
||||
// Current position of the shell
|
||||
private Vector3f position;
|
||||
// Current rotation of the shell
|
||||
private final Quaternion rotation;
|
||||
|
||||
/**
|
||||
* Constructs a new {@code Shell} object using the given {@code Shot} target.
|
||||
* The initial position, target position, and overshot position are calculated.
|
||||
*
|
||||
* @param shot The target {@code Shot} object containing the destination coordinates.
|
||||
*/
|
||||
public Shell(Shot shot) {
|
||||
this.shotPosition = new Vector3f(shot.getX(), 0, shot.getY());
|
||||
this.overShotPosition = new Vector3f(shotPosition.x, INIT_POS.y, shotPosition.z).add(OVER_SHOT_DIFF);
|
||||
this.position = INIT_POS;
|
||||
this.rotation = new Quaternion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current position of the shell.
|
||||
*
|
||||
* @return The current position as a {@code Vector3f}.
|
||||
*/
|
||||
public Vector3f getPosition() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current rotation of the shell.
|
||||
*
|
||||
* @return The current rotation as a {@code Quaternion}.
|
||||
*/
|
||||
public Quaternion getRotation() {
|
||||
return this.rotation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the shell along a Bezier curve based on the given time factor {@code t}.
|
||||
* The position and rotation of the shell are updated.
|
||||
*
|
||||
* @param t The time factor between 0 and 1, representing the progress of the shell's flight.
|
||||
*/
|
||||
public void move(float t) {
|
||||
if (t > 1f) t = 1f;
|
||||
Vector3f newPosition = bezInt(INIT_POS, overShotPosition, shotPosition, t);
|
||||
updateRotation(position, newPosition);
|
||||
this.position = newPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a quadratic Bezier interpolation between three points based on the time factor {@code t}.
|
||||
*
|
||||
* @param p1 The start position.
|
||||
* @param p2 The overshot position.
|
||||
* @param p3 The target position.
|
||||
* @param t The time factor for interpolation.
|
||||
* @return The interpolated position as a {@code Vector3f}.
|
||||
*/
|
||||
private Vector3f bezInt(Vector3f p1, Vector3f p2, Vector3f p3, float t) {
|
||||
Vector3f inA = linInt(p1, p2, t);
|
||||
Vector3f inB = linInt(p2, p3, t);
|
||||
return linInt(inA, inB, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs linear interpolation between two points {@code p1} and {@code p2} based on the time factor {@code t}.
|
||||
*
|
||||
* @param p1 The start position.
|
||||
* @param p2 The end position.
|
||||
* @param t The time factor for interpolation.
|
||||
* @return The interpolated position as a {@code Vector3f}.
|
||||
*/
|
||||
private Vector3f linInt(Vector3f p1, Vector3f p2, float t) {
|
||||
float x = p1.getX() + t * (p2.getX() - p1.getX());
|
||||
float y = p1.getY() + t * (p2.getY() - p1.getY());
|
||||
float z = p1.getZ() + t * (p2.getZ() - p1.getZ());
|
||||
return new Vector3f(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the rotation of the shell to face the new position along its flight path.
|
||||
*
|
||||
* @param oldPos The previous position of the shell.
|
||||
* @param newPos The new position of the shell.
|
||||
*/
|
||||
private void updateRotation(Vector3f oldPos, Vector3f newPos) {
|
||||
Vector3f direction = newPos.subtract(oldPos).normalize();
|
||||
if (direction.lengthSquared() > 0) {
|
||||
this.rotation.lookAt(direction, Vector3f.UNIT_Y);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T accept(Visitor<T> visitor) {
|
||||
return visitor.visit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(VoidVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
||||
|
@@ -91,16 +91,6 @@ public class ShipMap {
|
||||
addItem(shot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a shot on the map and triggers an item addition event.
|
||||
*
|
||||
* @param shell the shell to be registered on the map
|
||||
*/
|
||||
public void add(Shell shell) {
|
||||
addItem(shell);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes an item from the map and triggers an item removal event.
|
||||
*
|
||||
|
@@ -28,14 +28,4 @@ public interface Visitor<T> {
|
||||
* @return the result of visiting the Battleship element
|
||||
*/
|
||||
T visit(Battleship ship);
|
||||
/**
|
||||
* Visits a Shell element
|
||||
*
|
||||
* @param shell the Shell element to visit
|
||||
* @return the result of visitung the Battleship element
|
||||
*/
|
||||
|
||||
T visit(Shell shell);
|
||||
|
||||
|
||||
}
|
||||
|
@@ -25,11 +25,4 @@ public interface VoidVisitor {
|
||||
* @param ship the Battleship element to visit
|
||||
*/
|
||||
void visit(Battleship ship);
|
||||
|
||||
/**
|
||||
* * Visits a Shell element
|
||||
* @param shell the Shell element to visit
|
||||
*/
|
||||
void visit(Shell shell);
|
||||
|
||||
}
|
||||
|
@@ -22,10 +22,5 @@ public enum Sound {
|
||||
/**
|
||||
* Sound of a ship being destroyed.
|
||||
*/
|
||||
DESTROYED_SHIP,
|
||||
/**
|
||||
* Sound of a shell flying
|
||||
*/
|
||||
SHELL_FLYING
|
||||
|
||||
DESTROYED_SHIP
|
||||
}
|
||||
|
@@ -25,12 +25,11 @@ button.cancel=Cancel
|
||||
server.dialog=Server
|
||||
host.name=Host
|
||||
port.number=Port
|
||||
server.host= Self-Host Game
|
||||
wait.its.not.your.turn=Wait, it's not your turn!!
|
||||
menu.quit=Quit game
|
||||
menu.return-to-game=Return to game
|
||||
menu.sound-enabled=Sound switched on
|
||||
menu.background-sound-enabled=Music switched on
|
||||
menu.background-sound-enabled=Background music switched on
|
||||
menu.map.load=Load map from file...
|
||||
menu.map.save=Save map in file...
|
||||
label.file=File:
|
||||
@@ -39,3 +38,4 @@ dialog.error=Error
|
||||
dialog.question=Question
|
||||
port.must.be.integer=Port must be an integer number
|
||||
map.doesnt.fit=The map doesn't fit to this game
|
||||
client.server-start=Start server
|
||||
|
@@ -25,12 +25,11 @@ button.cancel=Abbruch
|
||||
server.dialog=Server
|
||||
host.name=Host
|
||||
port.number=Port
|
||||
server.host= Spiel selbst hosten
|
||||
wait.its.not.your.turn=Warte, Du bist nicht dran!!
|
||||
menu.quit=Spiel beenden
|
||||
menu.return-to-game=Zurück zum Spiel
|
||||
menu.sound-enabled=Sound eingeschaltet
|
||||
menu.background-sound-enabled=Musik eingeschaltet
|
||||
menu.background-sound-enabled=Hintergrundmusik eingeschaltet
|
||||
menu.map.load=Karte von Datei laden...
|
||||
menu.map.save=Karte in Datei speichern...
|
||||
label.file=Datei:
|
||||
@@ -39,3 +38,4 @@ dialog.error=Fehler
|
||||
dialog.question=Frage
|
||||
port.must.be.integer=Der Port muss eine ganze Zahl sein
|
||||
map.doesnt.fit=Diese Karte passt nicht zu diesem Spiel
|
||||
client.server-start=Server starten
|
||||
|
@@ -21,7 +21,6 @@ import pp.battleship.game.server.ServerSender;
|
||||
import pp.battleship.message.client.ClientMessage;
|
||||
import pp.battleship.message.client.MapMessage;
|
||||
import pp.battleship.message.client.ShootMessage;
|
||||
import pp.battleship.message.client.AnimationFinishedMessage;
|
||||
import pp.battleship.message.server.EffectMessage;
|
||||
import pp.battleship.message.server.GameDetails;
|
||||
import pp.battleship.message.server.ServerMessage;
|
||||
@@ -81,9 +80,8 @@ public class BattleshipServer implements MessageListener<HostedConnection>, Conn
|
||||
|
||||
public void run() {
|
||||
startServer();
|
||||
while (true) {
|
||||
while (true)
|
||||
processNextMessage();
|
||||
}
|
||||
}
|
||||
|
||||
private void startServer() {
|
||||
@@ -117,17 +115,14 @@ public class BattleshipServer implements MessageListener<HostedConnection>, Conn
|
||||
Serializer.registerClass(MapMessage.class);
|
||||
Serializer.registerClass(ShootMessage.class);
|
||||
Serializer.registerClass(EffectMessage.class);
|
||||
Serializer.registerClass(AnimationFinishedMessage.class);
|
||||
Serializer.registerClass(Battleship.class);
|
||||
Serializer.registerClass(IntPoint.class);
|
||||
Serializer.registerClass(Shot.class);
|
||||
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
myServer.addMessageListener(this, MapMessage.class);
|
||||
myServer.addMessageListener(this, ShootMessage.class);
|
||||
myServer.addMessageListener(this, AnimationFinishedMessage.class);
|
||||
myServer.addConnectionListener(this);
|
||||
}
|
||||
|
||||
|
@@ -19,6 +19,7 @@ dependencyResolutionManagement {
|
||||
library('jme3-testdata', 'org.jmonkeyengine', 'jme3-testdata').versionRef('jme')
|
||||
library('jme3-lwjgl', 'org.jmonkeyengine', 'jme3-lwjgl').versionRef('jme')
|
||||
library('jme3-lwjgl3', 'org.jmonkeyengine', 'jme3-lwjgl3').versionRef('jme')
|
||||
library('jme3-effects', 'org.jmonkeyengine', 'jme3-effects').versionRef('jme')
|
||||
|
||||
library('lemur', 'com.simsilica:lemur:1.16.0')
|
||||
library('lemur-proto', 'com.simsilica:lemur-proto:1.13.0')
|
||||
|