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.
|
||||
*/
|
||||
public class EffectHandler {
|
||||
//TODO: Ex. 12 EffectHandler
|
||||
private final BattleshipApp app;
|
||||
private final Map<Battleship, List<ParticleEmitter>> effects;
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* An application state that plays sounds.
|
||||
*/
|
||||
public class GameMusic extends AbstractAppState {
|
||||
//TODO: Ex. 10 GameMusic
|
||||
private static final Preferences PREFERENCES = getPreferences(GameMusic.class);
|
||||
private static final String ENABLED_PREF = "enabled";
|
||||
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 AudioNode backgroundMusic;
|
||||
private float volume;
|
||||
|
||||
/**
|
||||
* Returns whether the music is enabled in the user preferences.
|
||||
@@ -99,7 +99,16 @@ public void stopMusic() {
|
||||
public void setMusicVolume(float volume) {
|
||||
if (backgroundMusic != null) {
|
||||
backgroundMusic.setVolume(volume);
|
||||
this.volume = 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 Checkbox(lookup("menu.sound-enabled"),
|
||||
new StateCheckboxModel(app, GameSound.class)));
|
||||
//TODO: Ex. 10 VolumeSlider
|
||||
addChild(new Checkbox(lookup("menu.music-enabled"), new StateCheckboxModel(app, GameMusic.class)));
|
||||
addChild(volumeSlider);
|
||||
|
||||
|
||||
@@ -61,7 +61,6 @@ class NetworkDialog extends SimpleDialog {
|
||||
input.addChild(host, 1);
|
||||
input.addChild(new Label(lookup("port.number") + ": "));
|
||||
input.addChild(port, 1);
|
||||
//TODO: Ex. 11 ClientHost Checkbox
|
||||
clientHostCheckbox = new Checkbox("Host Server");
|
||||
input.addChild(clientHostCheckbox);
|
||||
DialogBuilder.simple(app.getDialogManager())
|
||||
|
||||
@@ -20,7 +20,7 @@ public class VolumeSlider extends Slider {
|
||||
public VolumeSlider(GameMusic gameMusic) {
|
||||
super();
|
||||
this.gameMusic = gameMusic;
|
||||
volume = GameMusic.volumeInPreferences();
|
||||
volume = gameMusic.getVolume();
|
||||
getModel().setPercent(volume);
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,6 @@ public Spatial visit(Battleship ship) {
|
||||
*/
|
||||
@Override
|
||||
public Spatial visit(Shell shell) {
|
||||
//TODO: Ex. 13 2D 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
|
||||
|
||||
@@ -92,7 +92,6 @@ private Spatial handleMiss(Shot shot) {
|
||||
private Spatial handleHit(Shot shot) {
|
||||
final Battleship ship = requireNonNull(map.findShipAt(shot), "Missing ship");
|
||||
final Node shipNode = requireNonNull((Node) getSpatial(ship), "Missing ship node");
|
||||
//TODO: Ex. 12 Hit
|
||||
shipNode.getControl(ShipControl.class).hit(shot);
|
||||
if (ship.isDestroyed()) {
|
||||
shipNode.getControl(ShipControl.class).destroyed();
|
||||
@@ -102,7 +101,7 @@ private Spatial handleHit(Shot shot) {
|
||||
public void run() {
|
||||
handleShipDestroy(shipNode);
|
||||
}
|
||||
}, 9000);
|
||||
}, 10000);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -149,7 +148,6 @@ public Spatial visit(Battleship ship) {
|
||||
final float x = 0.5f * (ship.getMinY() + ship.getMaxY() + 1f);
|
||||
final float z = 0.5f * (ship.getMinX() + ship.getMaxX() + 1f);
|
||||
node.setLocalTranslation(x, 0f, z);
|
||||
//TODO: Ex. 12 ShipControl
|
||||
node.addControl(new ShipControl(ship, node, app.getEffectHandler()));
|
||||
return node;
|
||||
}
|
||||
@@ -163,7 +161,6 @@ public Spatial visit(Battleship ship) {
|
||||
*/
|
||||
@Override
|
||||
public Spatial visit(Shell shell) {
|
||||
//TODO: Ex. 13 3D Shell
|
||||
final Spatial model = app.getAssetManager().loadModel("Models/Shell/shell.j3o");
|
||||
model.setLocalScale(.05f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
import pp.battleship.client.EffectHandler;
|
||||
import pp.battleship.model.Battleship;
|
||||
import pp.battleship.model.Rotation;
|
||||
import pp.battleship.model.Shot;
|
||||
|
||||
import java.util.Timer;
|
||||
@@ -108,7 +109,12 @@ private void handleSinking(float tpf) {
|
||||
if (spatial == null) return;
|
||||
|
||||
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.
|
||||
@@ -158,4 +164,4 @@ public void hit(Shot shot) {
|
||||
Vector3f firePos = shotWorld.subtract(shipNodePos);
|
||||
shipNode.attachChild(effectHandler.createFire(firePos, battleship));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user