fixed sinking-rotation, volumeslider; deleted TODO comments
This commit is contained in:
@@ -20,7 +20,6 @@
|
|||||||
* EffectHandler manages the creation and manipulation of particle effects in the Battleship application.
|
* EffectHandler manages the creation and manipulation of particle effects in the Battleship application.
|
||||||
*/
|
*/
|
||||||
public class EffectHandler {
|
public class EffectHandler {
|
||||||
//TODO: Ex. 12 EffectHandler
|
|
||||||
private final BattleshipApp app;
|
private final BattleshipApp app;
|
||||||
private final Map<Battleship, List<ParticleEmitter>> effects;
|
private final Map<Battleship, List<ParticleEmitter>> effects;
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
* An application state that plays sounds.
|
* An application state that plays sounds.
|
||||||
*/
|
*/
|
||||||
public class GameMusic extends AbstractAppState {
|
public class GameMusic extends AbstractAppState {
|
||||||
//TODO: Ex. 10 GameMusic
|
|
||||||
private static final Preferences PREFERENCES = getPreferences(GameMusic.class);
|
private static final Preferences PREFERENCES = getPreferences(GameMusic.class);
|
||||||
private static final String ENABLED_PREF = "enabled";
|
private static final String ENABLED_PREF = "enabled";
|
||||||
private static final String VOLUME_PREF = "volume";
|
private static final String VOLUME_PREF = "volume";
|
||||||
@@ -22,6 +21,7 @@ public class GameMusic extends AbstractAppState {
|
|||||||
private static final String MUSIC_PATH = "Sound/background.wav";
|
private static final String MUSIC_PATH = "Sound/background.wav";
|
||||||
|
|
||||||
private AudioNode backgroundMusic;
|
private AudioNode backgroundMusic;
|
||||||
|
private float volume;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the music is enabled in the user preferences.
|
* Returns whether the music is enabled in the user preferences.
|
||||||
@@ -99,7 +99,16 @@ public void stopMusic() {
|
|||||||
public void setMusicVolume(float volume) {
|
public void setMusicVolume(float volume) {
|
||||||
if (backgroundMusic != null) {
|
if (backgroundMusic != null) {
|
||||||
backgroundMusic.setVolume(volume);
|
backgroundMusic.setVolume(volume);
|
||||||
|
this.volume = volume;
|
||||||
PREFERENCES.putFloat(VOLUME_PREF, volume);
|
PREFERENCES.putFloat(VOLUME_PREF, volume);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns volume stored in class
|
||||||
|
* @return volume
|
||||||
|
*/
|
||||||
|
public float getVolume() {
|
||||||
|
return this.volume;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ public Menu(BattleshipApp app) {
|
|||||||
addChild(new Label(lookup("battleship.name"), new ElementId("header"))); //NON-NLS
|
addChild(new Label(lookup("battleship.name"), new ElementId("header"))); //NON-NLS
|
||||||
addChild(new Checkbox(lookup("menu.sound-enabled"),
|
addChild(new Checkbox(lookup("menu.sound-enabled"),
|
||||||
new StateCheckboxModel(app, GameSound.class)));
|
new StateCheckboxModel(app, GameSound.class)));
|
||||||
//TODO: Ex. 10 VolumeSlider
|
|
||||||
addChild(new Checkbox(lookup("menu.music-enabled"), new StateCheckboxModel(app, GameMusic.class)));
|
addChild(new Checkbox(lookup("menu.music-enabled"), new StateCheckboxModel(app, GameMusic.class)));
|
||||||
addChild(volumeSlider);
|
addChild(volumeSlider);
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ class NetworkDialog extends SimpleDialog {
|
|||||||
input.addChild(host, 1);
|
input.addChild(host, 1);
|
||||||
input.addChild(new Label(lookup("port.number") + ": "));
|
input.addChild(new Label(lookup("port.number") + ": "));
|
||||||
input.addChild(port, 1);
|
input.addChild(port, 1);
|
||||||
//TODO: Ex. 11 ClientHost Checkbox
|
|
||||||
clientHostCheckbox = new Checkbox("Host Server");
|
clientHostCheckbox = new Checkbox("Host Server");
|
||||||
input.addChild(clientHostCheckbox);
|
input.addChild(clientHostCheckbox);
|
||||||
DialogBuilder.simple(app.getDialogManager())
|
DialogBuilder.simple(app.getDialogManager())
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class VolumeSlider extends Slider {
|
|||||||
public VolumeSlider(GameMusic gameMusic) {
|
public VolumeSlider(GameMusic gameMusic) {
|
||||||
super();
|
super();
|
||||||
this.gameMusic = gameMusic;
|
this.gameMusic = gameMusic;
|
||||||
volume = GameMusic.volumeInPreferences();
|
volume = gameMusic.getVolume();
|
||||||
getModel().setPercent(volume);
|
getModel().setPercent(volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,6 @@ public Spatial visit(Battleship ship) {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Spatial visit(Shell shell) {
|
public Spatial visit(Shell shell) {
|
||||||
//TODO: Ex. 13 2D Shell
|
|
||||||
final ColorRGBA color = ColorRGBA.Black;
|
final ColorRGBA color = ColorRGBA.Black;
|
||||||
Geometry ellipse = new Geometry("ellipse", new Sphere(50, 50, MapView.FIELD_SIZE / 2 * 0.8f));
|
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
|
Material mat = new Material(view.getApp().getAssetManager(), UNSHADED); //NON-NLS
|
||||||
|
|||||||
@@ -92,7 +92,6 @@ private Spatial handleMiss(Shot shot) {
|
|||||||
private Spatial handleHit(Shot shot) {
|
private Spatial handleHit(Shot shot) {
|
||||||
final Battleship ship = requireNonNull(map.findShipAt(shot), "Missing ship");
|
final Battleship ship = requireNonNull(map.findShipAt(shot), "Missing ship");
|
||||||
final Node shipNode = requireNonNull((Node) getSpatial(ship), "Missing ship node");
|
final Node shipNode = requireNonNull((Node) getSpatial(ship), "Missing ship node");
|
||||||
//TODO: Ex. 12 Hit
|
|
||||||
shipNode.getControl(ShipControl.class).hit(shot);
|
shipNode.getControl(ShipControl.class).hit(shot);
|
||||||
if (ship.isDestroyed()) {
|
if (ship.isDestroyed()) {
|
||||||
shipNode.getControl(ShipControl.class).destroyed();
|
shipNode.getControl(ShipControl.class).destroyed();
|
||||||
@@ -102,7 +101,7 @@ private Spatial handleHit(Shot shot) {
|
|||||||
public void run() {
|
public void run() {
|
||||||
handleShipDestroy(shipNode);
|
handleShipDestroy(shipNode);
|
||||||
}
|
}
|
||||||
}, 9000);
|
}, 10000);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -149,7 +148,6 @@ public Spatial visit(Battleship ship) {
|
|||||||
final float x = 0.5f * (ship.getMinY() + ship.getMaxY() + 1f);
|
final float x = 0.5f * (ship.getMinY() + ship.getMaxY() + 1f);
|
||||||
final float z = 0.5f * (ship.getMinX() + ship.getMaxX() + 1f);
|
final float z = 0.5f * (ship.getMinX() + ship.getMaxX() + 1f);
|
||||||
node.setLocalTranslation(x, 0f, z);
|
node.setLocalTranslation(x, 0f, z);
|
||||||
//TODO: Ex. 12 ShipControl
|
|
||||||
node.addControl(new ShipControl(ship, node, app.getEffectHandler()));
|
node.addControl(new ShipControl(ship, node, app.getEffectHandler()));
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@@ -163,7 +161,6 @@ public Spatial visit(Battleship ship) {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Spatial visit(Shell shell) {
|
public Spatial visit(Shell shell) {
|
||||||
//TODO: Ex. 13 3D Shell
|
|
||||||
final Spatial model = app.getAssetManager().loadModel("Models/Shell/shell.j3o");
|
final Spatial model = app.getAssetManager().loadModel("Models/Shell/shell.j3o");
|
||||||
model.setLocalScale(.05f);
|
model.setLocalScale(.05f);
|
||||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
import com.jme3.scene.control.AbstractControl;
|
import com.jme3.scene.control.AbstractControl;
|
||||||
import pp.battleship.client.EffectHandler;
|
import pp.battleship.client.EffectHandler;
|
||||||
import pp.battleship.model.Battleship;
|
import pp.battleship.model.Battleship;
|
||||||
|
import pp.battleship.model.Rotation;
|
||||||
import pp.battleship.model.Shot;
|
import pp.battleship.model.Shot;
|
||||||
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
@@ -108,7 +109,12 @@ private void handleSinking(float tpf) {
|
|||||||
if (spatial == null) return;
|
if (spatial == null) return;
|
||||||
|
|
||||||
spatial.setLocalTranslation(spatial.getLocalTranslation().add(new Vector3f(0, -1, 0).mult(tpf * SINK_SPEED)));
|
spatial.setLocalTranslation(spatial.getLocalTranslation().add(new Vector3f(0, -1, 0).mult(tpf * SINK_SPEED)));
|
||||||
spatial.rotate(tpf * SINK_ROT_SPEED, 0, 0);
|
if (battleship.getRot() == Rotation.UP || battleship.getRot() == Rotation.DOWN) {
|
||||||
|
spatial.rotate(tpf * SINK_ROT_SPEED, 0, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
spatial.rotate(0, 0, tpf * SINK_ROT_SPEED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles the pitch oscillation to simulate wave movement.
|
// Handles the pitch oscillation to simulate wave movement.
|
||||||
|
|||||||
@@ -57,10 +57,8 @@ public void receivedEffect(EffectMessage msg) {
|
|||||||
|
|
||||||
myTurn = msg.isMyTurn();
|
myTurn = msg.isMyTurn();
|
||||||
logic.setInfoText(msg.getInfoTextKey());
|
logic.setInfoText(msg.getInfoTextKey());
|
||||||
//TODO: Ex. 13 add shell -> ItemAddedEvent
|
|
||||||
Shell shell = new Shell(msg.getShot());
|
Shell shell = new Shell(msg.getShot());
|
||||||
affectedMap(msg).add(shell);
|
affectedMap(msg).add(shell);
|
||||||
//TODO: Ex. 13 Shell sound -> GameSound
|
|
||||||
logic.playSound(Sound.SHELL_FLYING);
|
logic.playSound(Sound.SHELL_FLYING);
|
||||||
logic.setState(new ShootingState(logic, shell, myTurn, msg));
|
logic.setState(new ShootingState(logic, shell, myTurn, msg));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ public class ShootingState extends ClientState {
|
|||||||
* @param msg the effect message associated with the shooting action
|
* @param msg the effect message associated with the shooting action
|
||||||
*/
|
*/
|
||||||
public ShootingState(ClientGameLogic logic, Shell shell, boolean myTurn, EffectMessage msg) {
|
public ShootingState(ClientGameLogic logic, Shell shell, boolean myTurn, EffectMessage msg) {
|
||||||
//TODO: Ex. 13 ShootingState
|
|
||||||
super(logic);
|
super(logic);
|
||||||
this.msg = msg;
|
this.msg = msg;
|
||||||
this.myTurn = myTurn;
|
this.myTurn = myTurn;
|
||||||
|
|||||||
@@ -221,7 +221,6 @@ private boolean checkMap(List<Battleship> ships) {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void received(ShootMessage msg, int from) {
|
public void received(ShootMessage msg, int from) {
|
||||||
//TODO: Ex. 13 Server State
|
|
||||||
if (state != ServerState.BATTLE)
|
if (state != ServerState.BATTLE)
|
||||||
LOGGER.log(Level.ERROR, "shoot not allowed in {0}", state); //NON-NLS
|
LOGGER.log(Level.ERROR, "shoot not allowed in {0}", state); //NON-NLS
|
||||||
else{
|
else{
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
* a Bezier curve.
|
* a Bezier curve.
|
||||||
*/
|
*/
|
||||||
public class Shell implements Item {
|
public class Shell implements Item {
|
||||||
//TODO: Ex. 13 Shell
|
|
||||||
/**
|
/**
|
||||||
* Initial position of the shell
|
* Initial position of the shell
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user