Compare commits
17 Commits
b_koppe_fe
...
b_Bauer_Lu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66798eb3e4 | ||
|
|
edff9e1ad9 | ||
|
|
bf16a18b71 | ||
|
|
6100e95e76 | ||
|
|
1b7b842ca7 | ||
|
|
865b0fc33c | ||
|
|
5a9b0b1de0 | ||
|
|
8650fa5b58 | ||
|
|
113da79df6 | ||
|
|
e41d21584a | ||
|
|
5e773ca1ba | ||
|
|
b2b3bc23bf | ||
|
|
ce490fb877 | ||
|
|
ce5e908349 | ||
|
|
07e922d01e | ||
|
|
42b442e937 | ||
|
|
93ade34282 |
@@ -1,18 +1,17 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="BattleshipApp (Mac)" type="Application" factoryName="Application"
|
<configuration default="false" name="BattleshipApp (Mac)" type="Application" factoryName="Application" singleton="false">
|
||||||
singleton="false">
|
<option name="MAIN_CLASS_NAME" value="pp.battleship.client.BattleshipApp" />
|
||||||
<option name="MAIN_CLASS_NAME" value="pp.battleship.client.BattleshipApp"/>
|
<module name="Projekte.battleship.client.main" />
|
||||||
<module name="Projekte.battleship.client.main"/>
|
<option name="VM_PARAMETERS" value="-XstartOnFirstThread" />
|
||||||
<option name="VM_PARAMETERS" value="-XstartOnFirstThread"/>
|
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$" />
|
||||||
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$"/>
|
<extension name="coverage">
|
||||||
<extension name="coverage">
|
<pattern>
|
||||||
<pattern>
|
<option name="PATTERN" value="pp.battleship.client.server.*" />
|
||||||
<option name="PATTERN" value="pp.battleship.client.*"/>
|
<option name="ENABLED" value="true" />
|
||||||
<option name="ENABLED" value="true"/>
|
</pattern>
|
||||||
</pattern>
|
</extension>
|
||||||
</extension>
|
<method v="2">
|
||||||
<method v="2">
|
<option name="Make" enabled="true" />
|
||||||
<option name="Make" enabled="true"/>
|
</method>
|
||||||
</method>
|
</configuration>
|
||||||
</configuration>
|
|
||||||
</component>
|
</component>
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="BattleshipApp" type="Application" factoryName="Application" singleton="false"
|
<configuration default="false" name="BattleshipApp" type="Application" factoryName="Application" singleton="false" nameIsGenerated="true">
|
||||||
nameIsGenerated="true">
|
<option name="ALTERNATIVE_JRE_PATH" value="temurin-20" />
|
||||||
<option name="MAIN_CLASS_NAME" value="pp.battleship.client.BattleshipApp"/>
|
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
|
||||||
<module name="Projekte.battleship.client.main"/>
|
<option name="MAIN_CLASS_NAME" value="pp.battleship.client.BattleshipApp" />
|
||||||
<option name="VM_PARAMETERS" value="-Djava.util.logging.config.file=logging.properties"/>
|
<module name="Gruppe-01" />
|
||||||
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$"/>
|
<option name="VM_PARAMETERS" value="-Djava.util.logging.config.file=logging.properties" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$" />
|
||||||
<extension name="coverage">
|
<extension name="coverage">
|
||||||
<pattern>
|
<pattern>
|
||||||
<option name="PATTERN" value="pp.battleship.client.*"/>
|
<option name="PATTERN" value="pp.battleship.client.server.*" />
|
||||||
<option name="ENABLED" value="true"/>
|
<option name="ENABLED" value="true" />
|
||||||
</pattern>
|
</pattern>
|
||||||
</extension>
|
</extension>
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="Make" enabled="true"/>
|
<option name="Make" enabled="true" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
</component>
|
</component>
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<configuration default="false" name="Projekte [test]" type="GradleRunConfiguration" factoryName="Gradle">
|
<configuration default="false" name="Projekte [test]" type="GradleRunConfiguration" factoryName="Gradle">
|
||||||
<ExternalSystemSettings>
|
<ExternalSystemSettings>
|
||||||
<option name="executionName" />
|
<option name="executionName" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$/Projekte" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="externalSystemIdString" value="GRADLE" />
|
<option name="externalSystemIdString" value="GRADLE" />
|
||||||
<option name="scriptParameters" value="--continue" />
|
<option name="scriptParameters" value="--continue" />
|
||||||
<option name="taskDescriptions">
|
<option name="taskDescriptions">
|
||||||
|
|||||||
66
Projekte/battleship/client/maps/map3.json
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
{
|
||||||
|
"width": 10,
|
||||||
|
"height": 10,
|
||||||
|
"ships": [
|
||||||
|
{
|
||||||
|
"length": 4,
|
||||||
|
"x": 2,
|
||||||
|
"y": 8,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 3,
|
||||||
|
"x": 2,
|
||||||
|
"y": 5,
|
||||||
|
"rot": "DOWN"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 3,
|
||||||
|
"x": 5,
|
||||||
|
"y": 6,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 2,
|
||||||
|
"x": 4,
|
||||||
|
"y": 4,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 2,
|
||||||
|
"x": 7,
|
||||||
|
"y": 4,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 2,
|
||||||
|
"x": 7,
|
||||||
|
"y": 4,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 1,
|
||||||
|
"x": 6,
|
||||||
|
"y": 2,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 1,
|
||||||
|
"x": 8,
|
||||||
|
"y": 2,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 1,
|
||||||
|
"x": 6,
|
||||||
|
"y": 0,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 1,
|
||||||
|
"x": 8,
|
||||||
|
"y": 0,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
66
Projekte/battleship/client/maps/map4.json
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
{
|
||||||
|
"width": 10,
|
||||||
|
"height": 10,
|
||||||
|
"ships": [
|
||||||
|
{
|
||||||
|
"length": 1,
|
||||||
|
"x": 9,
|
||||||
|
"y": 0,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 1,
|
||||||
|
"x": 9,
|
||||||
|
"y": 1,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 1,
|
||||||
|
"x": 8,
|
||||||
|
"y": 0,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 1,
|
||||||
|
"x": 8,
|
||||||
|
"y": 1,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 2,
|
||||||
|
"x": 8,
|
||||||
|
"y": 2,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 2,
|
||||||
|
"x": 6,
|
||||||
|
"y": 0,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 2,
|
||||||
|
"x": 6,
|
||||||
|
"y": 1,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 3,
|
||||||
|
"x": 5,
|
||||||
|
"y": 2,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 3,
|
||||||
|
"x": 7,
|
||||||
|
"y": 3,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"length": 4,
|
||||||
|
"x": 6,
|
||||||
|
"y": 4,
|
||||||
|
"rot": "RIGHT"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package pp.battleship.client;
|
||||||
|
|
||||||
|
import com.jme3.app.Application;
|
||||||
|
import com.jme3.audio.AudioData.DataType;
|
||||||
|
import com.jme3.audio.AudioNode;
|
||||||
|
import com.jme3.audio.AudioSource.Status;
|
||||||
|
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
|
public class BackgroundMusic {
|
||||||
|
|
||||||
|
private static final String VOLUME_PREF = "volume";
|
||||||
|
private static final String MUSIC_ENABLED_PREF = "musicEnabled";
|
||||||
|
private Preferences prefs = Preferences.userNodeForPackage(BackgroundMusic.class);
|
||||||
|
|
||||||
|
private final AudioNode backgroundMusic;
|
||||||
|
private boolean musicEnabled;
|
||||||
|
private float volume;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constuctor for the BackgroundMusic
|
||||||
|
* @param app for synchronising and saving data with the application
|
||||||
|
* @param musicFilePath the filepath for the BackgroundMusic
|
||||||
|
*/
|
||||||
|
public BackgroundMusic(Application app, String musicFilePath) {
|
||||||
|
this.volume = prefs.getFloat(VOLUME_PREF, 1.0f);
|
||||||
|
this.musicEnabled = prefs.getBoolean(MUSIC_ENABLED_PREF, true);
|
||||||
|
|
||||||
|
backgroundMusic = new AudioNode(app.getAssetManager(), musicFilePath, DataType.Stream);
|
||||||
|
backgroundMusic.setLooping(true);
|
||||||
|
backgroundMusic.setPositional(false);
|
||||||
|
backgroundMusic.setVolume(1.0f);
|
||||||
|
|
||||||
|
if (musicEnabled) {
|
||||||
|
play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the condition is met to play BackgroundMusic
|
||||||
|
*/
|
||||||
|
public void play() {
|
||||||
|
if (musicEnabled && (backgroundMusic.getStatus() == Status.Stopped || backgroundMusic.getStatus() == Status.Paused)) {
|
||||||
|
backgroundMusic.play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* function to stop the BackgroundMusic
|
||||||
|
*/
|
||||||
|
public void stop() {
|
||||||
|
if (backgroundMusic.getStatus() == Status.Playing) {
|
||||||
|
backgroundMusic.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* function to toggle the Backgroundmusic also sets the volume to the previous session
|
||||||
|
*/
|
||||||
|
public void toogleMusic() {
|
||||||
|
this.musicEnabled = !this.musicEnabled;
|
||||||
|
if (musicEnabled) {
|
||||||
|
play();
|
||||||
|
} else {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
prefs.putFloat(VOLUME_PREF, volume);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for the Volume also safes the volume from the previous session
|
||||||
|
* @param volume variable for the volume of the BackgroundMusic
|
||||||
|
*/
|
||||||
|
public void setVolume(float volume) {
|
||||||
|
this.volume = volume;
|
||||||
|
backgroundMusic.setVolume(volume);
|
||||||
|
prefs.putFloat(VOLUME_PREF, volume);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for Volume
|
||||||
|
* @return a float value of the volume
|
||||||
|
*/
|
||||||
|
public float getVolume() {
|
||||||
|
return volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for musicEnabled
|
||||||
|
* @return if the music is enabled return true, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean isMusicEnabled() {
|
||||||
|
return musicEnabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -121,11 +121,10 @@ public class BattleshipApp extends SimpleApplication implements BattleshipClient
|
|||||||
* Listener for handling actions triggered by the Escape key.
|
* Listener for handling actions triggered by the Escape key.
|
||||||
*/
|
*/
|
||||||
private final ActionListener escapeListener = (name, isPressed, tpf) -> escape(isPressed);
|
private final ActionListener escapeListener = (name, isPressed, tpf) -> escape(isPressed);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener for handling actions triggered by the Escape key.
|
*
|
||||||
*/
|
*/
|
||||||
private GameMusic music;
|
private BackgroundMusic backgroundMusic;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Configure logging
|
// Configure logging
|
||||||
@@ -146,6 +145,7 @@ public class BattleshipApp extends SimpleApplication implements BattleshipClient
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new BattleshipApp().start();
|
new BattleshipApp().start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -198,15 +198,6 @@ DialogManager getDialogManager() {
|
|||||||
return dialogManager;
|
return dialogManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the GameMusic responsible for playing music.
|
|
||||||
*
|
|
||||||
* @return The {@link GameMusic} instance.
|
|
||||||
*/
|
|
||||||
GameMusic getGameMusic() {
|
|
||||||
return music;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the game logic handler for the client.
|
* Returns the game logic handler for the client.
|
||||||
*
|
*
|
||||||
@@ -239,8 +230,7 @@ public void simpleInitApp() {
|
|||||||
setupStates();
|
setupStates();
|
||||||
setupGui();
|
setupGui();
|
||||||
serverConnection.connect();
|
serverConnection.connect();
|
||||||
|
backgroundMusic = new BackgroundMusic(this, "Sound/Effects/BackgroundMusic/boss_battle_#2_metal_opening.wav");
|
||||||
music = new GameMusic(this, "Sound/Music/battleship.ogg");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -442,4 +432,12 @@ void errorDialog(String errorMessage) {
|
|||||||
.build()
|
.build()
|
||||||
.open();
|
.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for the BackgroundMusic
|
||||||
|
* @return the BackgroundMusic
|
||||||
|
*/
|
||||||
|
public BackgroundMusic getBackgroundMusic(){
|
||||||
|
return backgroundMusic;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,170 +0,0 @@
|
|||||||
////////////////////////////////////////
|
|
||||||
// Programming project code
|
|
||||||
// UniBw M, 2022, 2023, 2024
|
|
||||||
// www.unibw.de/inf2
|
|
||||||
// (c) Mark Minas (mark.minas@unibw.de)
|
|
||||||
////////////////////////////////////////
|
|
||||||
|
|
||||||
package pp.battleship.client;
|
|
||||||
|
|
||||||
import com.jme3.app.Application;
|
|
||||||
import com.jme3.app.state.AbstractAppState;
|
|
||||||
import com.jme3.app.state.AppStateManager;
|
|
||||||
import com.jme3.asset.AssetLoadException;
|
|
||||||
import com.jme3.asset.AssetNotFoundException;
|
|
||||||
import com.jme3.audio.AudioData;
|
|
||||||
import com.jme3.audio.AudioNode;
|
|
||||||
import com.jme3.audio.AudioSource;
|
|
||||||
import pp.battleship.notification.GameEventListener;
|
|
||||||
import pp.battleship.notification.SoundEvent;
|
|
||||||
|
|
||||||
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 implements GameEventListener {
|
|
||||||
private static final Logger LOGGER = System.getLogger(GameMusic.class.getName());
|
|
||||||
|
|
||||||
private static final Preferences PREFERENCES = getPreferences(GameMusic.class);
|
|
||||||
private static final String ENABLED_PREF = "toggle"; //NON-NLS
|
|
||||||
private static final String SLIDER_PREF = "slider"; //NON-NLS
|
|
||||||
|
|
||||||
private AudioNode music;
|
|
||||||
private boolean enabled;
|
|
||||||
private float volume;
|
|
||||||
|
|
||||||
public GameMusic(Application app, String musicFilePath) {
|
|
||||||
this.enabled = PREFERENCES.getBoolean(ENABLED_PREF, true);
|
|
||||||
this.volume = PREFERENCES.getFloat(SLIDER_PREF, 2.0f);
|
|
||||||
|
|
||||||
music = new AudioNode(app.getAssetManager(), musicFilePath, AudioData.DataType.Stream);
|
|
||||||
music.setLooping(true);
|
|
||||||
music.setPositional(false);
|
|
||||||
music.setVolume(1.0f);
|
|
||||||
|
|
||||||
if(enabled) {
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if music is enabled in the preferences.
|
|
||||||
*
|
|
||||||
* @return {@code true} if music is enabled, {@code false} otherwise.
|
|
||||||
*/
|
|
||||||
public static boolean enabledInPreferences() {
|
|
||||||
return PREFERENCES.getBoolean(ENABLED_PREF, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the volume value that is set in the preferences.
|
|
||||||
*
|
|
||||||
* @return {@code true} if sound is enabled, {@code false} otherwise.
|
|
||||||
*/
|
|
||||||
public static float volumeInPreferences() {
|
|
||||||
return PREFERENCES.getFloat(SLIDER_PREF, 2.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Toggles the game music on or off.
|
|
||||||
*/
|
|
||||||
public void toggleMusic() {
|
|
||||||
setEnabled(!isEnabled());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the enabled state of this AppState.
|
|
||||||
* Overrides {@link AbstractAppState#setEnabled(boolean)}
|
|
||||||
*
|
|
||||||
* @param enabled {@code true} to enable the AppState, {@code false} to disable it.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setEnabled(boolean enabled) {
|
|
||||||
super.setEnabled(enabled);
|
|
||||||
|
|
||||||
if(enabled) {
|
|
||||||
start();
|
|
||||||
} else {
|
|
||||||
stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGGER.log(Level.INFO, "Music enabled: {0}", enabled); //NON-NLS
|
|
||||||
PREFERENCES.putBoolean(ENABLED_PREF, enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the volume for the music
|
|
||||||
*
|
|
||||||
* @param volume the new volume to be set
|
|
||||||
*/
|
|
||||||
public void setVolume(float volume) {
|
|
||||||
this.volume = volume;
|
|
||||||
music.setVolume(volume);
|
|
||||||
|
|
||||||
LOGGER.log(Level.INFO, "Volume set to: {0}", volume); //NON-NLS
|
|
||||||
PREFERENCES.putFloat(SLIDER_PREF, volume);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads a music from the specified file.
|
|
||||||
*
|
|
||||||
* @param app The application
|
|
||||||
* @param name The name of the sound file.
|
|
||||||
* @return The loaded AudioNode.
|
|
||||||
*/
|
|
||||||
private AudioNode loadSound(Application app, String name) {
|
|
||||||
try {
|
|
||||||
final AudioNode sound = new AudioNode(app.getAssetManager(), name, AudioData.DataType.Buffer);
|
|
||||||
sound.setLooping(false);
|
|
||||||
sound.setPositional(false);
|
|
||||||
return sound;
|
|
||||||
}
|
|
||||||
catch (AssetLoadException | AssetNotFoundException ex) {
|
|
||||||
LOGGER.log(Level.ERROR, ex.getMessage(), ex);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the music.
|
|
||||||
*/
|
|
||||||
public void start() {
|
|
||||||
if (enabled && (music.getStatus() == AudioSource.Status.Stopped || music.getStatus() == AudioSource.Status.Paused)) {
|
|
||||||
music.play();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the music.
|
|
||||||
*/
|
|
||||||
public void stop() {
|
|
||||||
if (music.getStatus() == AudioSource.Status.Playing) {
|
|
||||||
music.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method returns the volume
|
|
||||||
*
|
|
||||||
* @return float the current volume
|
|
||||||
*/
|
|
||||||
public float getVolume() {
|
|
||||||
return volume;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns if music should be played or not
|
|
||||||
*
|
|
||||||
* @return boolean value if music is enabled
|
|
||||||
*/
|
|
||||||
public boolean isMusicEnabled() {
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -34,7 +34,7 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
|||||||
private AudioNode splashSound;
|
private AudioNode splashSound;
|
||||||
private AudioNode shipDestroyedSound;
|
private AudioNode shipDestroyedSound;
|
||||||
private AudioNode explosionSound;
|
private AudioNode explosionSound;
|
||||||
private AudioNode missleSound;
|
private AudioNode missileLaunch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if sound is enabled in the preferences.
|
* Checks if sound is enabled in the preferences.
|
||||||
@@ -45,13 +45,6 @@ public static boolean enabledInPreferences() {
|
|||||||
return PREFERENCES.getBoolean(ENABLED_PREF, true);
|
return PREFERENCES.getBoolean(ENABLED_PREF, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Toggles the game sound on or off.
|
|
||||||
*/
|
|
||||||
public void toggleSound() {
|
|
||||||
setEnabled(!isEnabled());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the enabled state of this AppState.
|
* Sets the enabled state of this AppState.
|
||||||
* Overrides {@link com.jme3.app.state.AbstractAppState#setEnabled(boolean)}
|
* Overrides {@link com.jme3.app.state.AbstractAppState#setEnabled(boolean)}
|
||||||
@@ -79,7 +72,7 @@ public void initialize(AppStateManager stateManager, Application app) {
|
|||||||
shipDestroyedSound = loadSound(app, "Sound/Effects/sunken.wav"); //NON-NLS
|
shipDestroyedSound = loadSound(app, "Sound/Effects/sunken.wav"); //NON-NLS
|
||||||
splashSound = loadSound(app, "Sound/Effects/splash.wav"); //NON-NLS
|
splashSound = loadSound(app, "Sound/Effects/splash.wav"); //NON-NLS
|
||||||
explosionSound = loadSound(app, "Sound/Effects/explosion.wav"); //NON-NLS
|
explosionSound = loadSound(app, "Sound/Effects/explosion.wav"); //NON-NLS
|
||||||
missleSound = loadSound(app, "Sound/Effects/missle.wav");
|
missileLaunch = loadSound(app, "Sound/Effects/missileLaunch.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,13 +88,19 @@ private AudioNode loadSound(Application app, String name) {
|
|||||||
sound.setLooping(false);
|
sound.setLooping(false);
|
||||||
sound.setPositional(false);
|
sound.setPositional(false);
|
||||||
return sound;
|
return sound;
|
||||||
}
|
} catch (AssetLoadException | AssetNotFoundException ex) {
|
||||||
catch (AssetLoadException | AssetNotFoundException ex) {
|
|
||||||
LOGGER.log(Level.ERROR, ex.getMessage(), ex);
|
LOGGER.log(Level.ERROR, ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plays the missile launch sound effect.
|
||||||
|
*/
|
||||||
|
public void missileLaunch() {
|
||||||
|
missileLaunch.playInstance();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays the splash sound effect.
|
* Plays the splash sound effect.
|
||||||
*/
|
*/
|
||||||
@@ -110,14 +109,6 @@ public void splash() {
|
|||||||
splashSound.playInstance();
|
splashSound.playInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Plays the missle flyby sound effect.
|
|
||||||
*/
|
|
||||||
public void flyBy() {
|
|
||||||
if (isEnabled() && missleSound != null)
|
|
||||||
missleSound.playInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays the explosion sound effect.
|
* Plays the explosion sound effect.
|
||||||
*/
|
*/
|
||||||
@@ -134,13 +125,17 @@ public void shipDestroyed() {
|
|||||||
shipDestroyedSound.playInstance();
|
shipDestroyedSound.playInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the according case for the soundeffect
|
||||||
|
* @param event the received event
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void receivedEvent(SoundEvent event) {
|
public void receivedEvent(SoundEvent event) {
|
||||||
switch (event.sound()) {
|
switch (event.sound()) {
|
||||||
case EXPLOSION -> explosion();
|
case EXPLOSION -> explosion();
|
||||||
case SPLASH -> splash();
|
case SPLASH -> splash();
|
||||||
case DESTROYED_SHIP -> shipDestroyed();
|
case DESTROYED_SHIP -> shipDestroyed();
|
||||||
case MISSLE_FLYBY -> flyBy();
|
case MISSILE_LAUNCH -> missileLaunch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,17 @@
|
|||||||
|
|
||||||
package pp.battleship.client;
|
package pp.battleship.client;
|
||||||
|
|
||||||
import com.simsilica.lemur.*;
|
import com.simsilica.lemur.Button;
|
||||||
import com.simsilica.lemur.core.VersionedReference;
|
import com.simsilica.lemur.Checkbox;
|
||||||
|
import com.simsilica.lemur.Label;
|
||||||
import com.simsilica.lemur.style.ElementId;
|
import com.simsilica.lemur.style.ElementId;
|
||||||
import pp.dialog.Dialog;
|
import pp.dialog.Dialog;
|
||||||
import pp.dialog.StateCheckboxModel;
|
import pp.dialog.StateCheckboxModel;
|
||||||
import pp.dialog.TextInputDialog;
|
import pp.dialog.TextInputDialog;
|
||||||
|
import com.simsilica.lemur.DefaultRangedValueModel;
|
||||||
|
import com.simsilica.lemur.Slider;
|
||||||
|
import com.simsilica.lemur.core.VersionedReference;
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -32,7 +37,6 @@ class Menu extends Dialog {
|
|||||||
private final BattleshipApp app;
|
private final BattleshipApp app;
|
||||||
private final Button loadButton = new Button(lookup("menu.map.load"));
|
private final Button loadButton = new Button(lookup("menu.map.load"));
|
||||||
private final Button saveButton = new Button(lookup("menu.map.save"));
|
private final Button saveButton = new Button(lookup("menu.map.save"));
|
||||||
|
|
||||||
private final VersionedReference<Double> volumeRef;
|
private final VersionedReference<Double> volumeRef;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,24 +50,24 @@ 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)));
|
||||||
addChild(loadButton)
|
|
||||||
.addClickCommands(s -> ifTopDialog(this::loadDialog));
|
|
||||||
addChild(saveButton)
|
|
||||||
.addClickCommands(s -> ifTopDialog(this::saveDialog));
|
|
||||||
|
|
||||||
Checkbox musicToggle = new Checkbox(lookup("menu.music.toggle"));
|
Checkbox musicToggle = new Checkbox(lookup("menu.music.toggle"));
|
||||||
musicToggle.setChecked(app.getGameMusic().isMusicEnabled());
|
musicToggle.setChecked(app.getBackgroundMusic().isMusicEnabled());
|
||||||
musicToggle.addClickCommands(s -> toggleMusic());
|
musicToggle.addClickCommands(s -> toggleMusic());
|
||||||
|
|
||||||
addChild(musicToggle);
|
addChild(musicToggle);
|
||||||
|
|
||||||
Slider volumeSlider = new Slider(lookup("menu.music.slider"));
|
Slider volumeSlider = new Slider();
|
||||||
volumeSlider.setModel(new DefaultRangedValueModel(0.0 , 4.0, app.getGameMusic().getVolume()));
|
volumeSlider.setModel(new DefaultRangedValueModel(0.0 , 2.0, app.getBackgroundMusic().getVolume()));
|
||||||
volumeSlider.setDelta(0.4);
|
volumeSlider.setDelta(0.1);
|
||||||
addChild(volumeSlider);
|
addChild(volumeSlider);
|
||||||
|
|
||||||
volumeRef = volumeSlider.getModel().createReference();
|
volumeRef = volumeSlider.getModel().createReference();
|
||||||
|
|
||||||
|
addChild(loadButton)
|
||||||
|
.addClickCommands(s -> ifTopDialog(this::loadDialog));
|
||||||
|
addChild(saveButton)
|
||||||
|
.addClickCommands(s -> ifTopDialog(this::saveDialog));
|
||||||
addChild(new Button(lookup("menu.return-to-game")))
|
addChild(new Button(lookup("menu.return-to-game")))
|
||||||
.addClickCommands(s -> ifTopDialog(this::close));
|
.addClickCommands(s -> ifTopDialog(this::close));
|
||||||
addChild(new Button(lookup("menu.quit")))
|
addChild(new Button(lookup("menu.quit")))
|
||||||
@@ -72,33 +76,39 @@ public Menu(BattleshipApp app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the state of the load/save buttons and volume based on the game logic.
|
* Updates the volume if there is a change and adjusts it accordingly.
|
||||||
|
* @param tmp unused time parameter
|
||||||
*/
|
*/
|
||||||
@Override
|
public void update(float tmp){
|
||||||
public void update() {
|
if(volumeRef.update()) {
|
||||||
loadButton.setEnabled(app.getGameLogic().mayLoadMap());
|
|
||||||
saveButton.setEnabled(app.getGameLogic().maySaveMap());
|
|
||||||
|
|
||||||
if(volumeRef.update()){
|
|
||||||
double newVolume = volumeRef.get();
|
double newVolume = volumeRef.get();
|
||||||
adjustVolume(newVolume);
|
adjustVolume(newVolume);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this method adjust the volume for the background music
|
* Adjusts the background music volume to the specified value.
|
||||||
*
|
* @param newVolume the new volume level
|
||||||
* @param volume is the double value of the volume
|
|
||||||
*/
|
*/
|
||||||
private void adjustVolume(double volume) {
|
|
||||||
app.getGameMusic().setVolume((float) volume);
|
private void adjustVolume(double newVolume) {
|
||||||
|
app.getBackgroundMusic().setVolume((float) newVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this method toggles the background music on and off
|
* Toggles the background music on or off.
|
||||||
*/
|
*/
|
||||||
private void toggleMusic() {
|
private void toggleMusic(){
|
||||||
app.getGameMusic().toggleMusic();
|
app.getBackgroundMusic().toogleMusic();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the state of the load and save buttons based on the game logic.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
loadButton.setEnabled(app.getGameLogic().mayLoadMap());
|
||||||
|
saveButton.setEnabled(app.getGameLogic().maySaveMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,11 +7,9 @@
|
|||||||
|
|
||||||
package pp.battleship.client;
|
package pp.battleship.client;
|
||||||
|
|
||||||
import com.simsilica.lemur.Checkbox;
|
import com.simsilica.lemur.*;
|
||||||
import com.simsilica.lemur.Container;
|
|
||||||
import com.simsilica.lemur.Label;
|
|
||||||
import com.simsilica.lemur.TextField;
|
|
||||||
import com.simsilica.lemur.component.SpringGridLayout;
|
import com.simsilica.lemur.component.SpringGridLayout;
|
||||||
|
import pp.battleship.client.server.BattleshipServer;
|
||||||
import pp.dialog.Dialog;
|
import pp.dialog.Dialog;
|
||||||
import pp.dialog.DialogBuilder;
|
import pp.dialog.DialogBuilder;
|
||||||
import pp.dialog.SimpleDialog;
|
import pp.dialog.SimpleDialog;
|
||||||
@@ -38,7 +36,10 @@ class NetworkDialog extends SimpleDialog {
|
|||||||
private int portNumber;
|
private int portNumber;
|
||||||
private Future<Object> connectionFuture;
|
private Future<Object> connectionFuture;
|
||||||
private Dialog progressDialog;
|
private Dialog progressDialog;
|
||||||
private boolean hostServer = false;
|
private BattleshipServer battleshipServer;
|
||||||
|
private boolean GUI = true;
|
||||||
|
private Container menu;
|
||||||
|
private boolean serverToggle = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new NetworkDialog.
|
* Constructs a new NetworkDialog.
|
||||||
@@ -52,89 +53,127 @@ class NetworkDialog extends SimpleDialog {
|
|||||||
host.setPreferredWidth(400f);
|
host.setPreferredWidth(400f);
|
||||||
port.setSingleLine(true);
|
port.setSingleLine(true);
|
||||||
|
|
||||||
Checkbox serverHost = new Checkbox(lookup("menu.host"));
|
this.menu = new Container();
|
||||||
serverHost.setChecked(false);
|
menu();
|
||||||
serverHost.addClickCommands(s -> toggleServerHost());
|
addChild(menu);
|
||||||
addChild(serverHost);
|
}
|
||||||
|
|
||||||
final BattleshipApp app = network.getApp();
|
/**
|
||||||
final Container input = new Container(new SpringGridLayout());
|
* Main Menu creation
|
||||||
input.addChild(new Label(lookup("host.name") + ": "));
|
*/
|
||||||
input.addChild(host, 1);
|
private void menu() {
|
||||||
input.addChild(new Label(lookup("port.number") + ": "));
|
|
||||||
input.addChild(port, 1);
|
|
||||||
|
|
||||||
DialogBuilder.simple(app.getDialogManager())
|
Button connectGame = new Button("Multiplayer");
|
||||||
.setTitle(lookup("server.dialog"))
|
connectGame.addClickCommands(source -> serverConnectGUI());
|
||||||
.setExtension(d -> d.addChild(input))
|
Checkbox serverHost = new Checkbox("Host own Game");
|
||||||
.setOkButton(lookup("button.connect"), d -> connectLocally())
|
serverHost.addClickCommands(source -> toggleServer());
|
||||||
.setNoButton(lookup("button.cancel"), app::closeApp)
|
|
||||||
.setOkClose(false)
|
|
||||||
.setNoClose(false)
|
menu.addChild(serverHost);
|
||||||
.build(this);
|
menu.addChild(connectGame);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logic for the ServerGUI
|
||||||
|
*/
|
||||||
|
private void serverConnectGUI() {
|
||||||
|
LOGGER.log(Level.INFO, "Hosting Server...");
|
||||||
|
|
||||||
|
if (GUI) {
|
||||||
|
host.setSingleLine(true);
|
||||||
|
host.setPreferredWidth(400f);
|
||||||
|
port.setSingleLine(true);
|
||||||
|
|
||||||
|
final BattleshipApp app = network.getApp();
|
||||||
|
final Container input = new Container(new SpringGridLayout());
|
||||||
|
|
||||||
|
input.addChild(new Label(lookup("host.name") + ": "));
|
||||||
|
input.addChild(host, 1);
|
||||||
|
input.addChild(new Label(lookup("port.number") + ": "));
|
||||||
|
input.addChild(port, 1);
|
||||||
|
|
||||||
|
DialogBuilder.simple(app.getDialogManager())
|
||||||
|
.setTitle(lookup("server.dialog"))
|
||||||
|
.setExtension(d -> d.addChild(input))
|
||||||
|
.setOkButton(lookup("button.connect"), d -> connect())
|
||||||
|
.setOkClose(false)
|
||||||
|
.build(this);
|
||||||
|
GUI = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect to server if serverToggle is false hosts otherwise
|
||||||
|
*/
|
||||||
|
private void connect(){
|
||||||
|
if (serverToggle) {
|
||||||
|
hostServer();
|
||||||
|
} else {
|
||||||
|
connectServer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the action for the connect button in the connection dialog.
|
* Handles the action for the connect button in the connection dialog.
|
||||||
* Tries to parse the port number and initiate connection to the server.
|
* Tries to parse the port number and initiate connection to the server.
|
||||||
*/
|
*/
|
||||||
private void connect() {
|
private void connectServer() {
|
||||||
LOGGER.log(Level.INFO, "connect to host={0}, port={1}", host, port); //NON-NLS
|
LOGGER.log(Level.INFO, "connect to host={0}, port={1}", host, port); //NON-NLS
|
||||||
try {
|
try {
|
||||||
hostname = host.getText().trim().isEmpty() ? LOCALHOST : host.getText();
|
hostname = host.getText().trim().isEmpty() ? LOCALHOST : host.getText();
|
||||||
portNumber = Integer.parseInt(port.getText());
|
portNumber = Integer.parseInt(port.getText());
|
||||||
openProgressDialog();
|
openProgressDialog();
|
||||||
connectionFuture = network.getApp().getExecutor().submit(this::initNetwork);
|
connectionFuture = network.getApp().getExecutor().submit(this::initNetwork);
|
||||||
}
|
} catch (NumberFormatException e) {
|
||||||
catch (NumberFormatException e) {
|
|
||||||
network.getApp().errorDialog(lookup("port.must.be.integer"));
|
network.getApp().errorDialog(lookup("port.must.be.integer"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a server or if not host connects to one
|
* Checks if the Server is running or starts the Server and handles Exceptions *
|
||||||
*/
|
*/
|
||||||
private void connectLocally() {
|
private void hostServer() {
|
||||||
if(hostServer){
|
if (battleshipServer == null) {
|
||||||
startServer();
|
startServer(); // Starts the server in a new thread
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000); // Wait for the server to start
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
LOGGER.log(Level.WARNING, e.getMessage(), e.getMessage());
|
LOGGER.log(Level.WARNING, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Proceed with connecting to the server
|
||||||
connect();
|
connectServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a host server in a new thread
|
* Toggle Method for Boolean
|
||||||
|
*/
|
||||||
|
private void toggleServer(){
|
||||||
|
serverToggle = !serverToggle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows Client to Start a Server in a new Thread
|
||||||
*/
|
*/
|
||||||
private void startServer() {
|
private void startServer() {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try{
|
try {
|
||||||
BattleshipServer battleshipServer = new BattleshipServer();
|
// Initialize and run the server
|
||||||
battleshipServer.run();
|
battleshipServer = new BattleshipServer();
|
||||||
|
battleshipServer.run(Integer.parseInt(port.getText()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.log(Level.ERROR,e);
|
LOGGER.log(Level.ERROR, e);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Toggles client/host mode
|
|
||||||
*/
|
|
||||||
private void toggleServerHost(){
|
|
||||||
hostServer = !hostServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a dialog indicating that the connection is in progress.
|
* Creates a dialog indicating that the connection is in progress.
|
||||||
*/
|
*/
|
||||||
private void openProgressDialog() {
|
private void openProgressDialog() {
|
||||||
progressDialog = DialogBuilder.simple(network.getApp().getDialogManager())
|
progressDialog = DialogBuilder.simple(network.getApp().getDialogManager())
|
||||||
.setText(lookup("label.connecting"))
|
.setText(lookup("label.connecting"))
|
||||||
.build();
|
.build();
|
||||||
progressDialog.open();
|
progressDialog.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,8 +186,7 @@ private Object initNetwork() {
|
|||||||
try {
|
try {
|
||||||
network.initNetwork(hostname, portNumber);
|
network.initNetwork(hostname, portNumber);
|
||||||
return null;
|
return null;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,11 +201,9 @@ public void update(float delta) {
|
|||||||
try {
|
try {
|
||||||
connectionFuture.get();
|
connectionFuture.get();
|
||||||
success();
|
success();
|
||||||
}
|
} catch (ExecutionException e) {
|
||||||
catch (ExecutionException e) {
|
|
||||||
failure(e.getCause());
|
failure(e.getCause());
|
||||||
}
|
} catch (InterruptedException e) {
|
||||||
catch (InterruptedException e) {
|
|
||||||
LOGGER.log(Level.WARNING, "Interrupted!", e); //NON-NLS
|
LOGGER.log(Level.WARNING, "Interrupted!", e); //NON-NLS
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,155 @@
|
|||||||
|
package pp.battleship.client.gui;
|
||||||
|
|
||||||
|
import com.jme3.asset.AssetManager;
|
||||||
|
import com.jme3.effect.ParticleEmitter;
|
||||||
|
import com.jme3.effect.ParticleMesh.Type;
|
||||||
|
import com.jme3.material.Material;
|
||||||
|
import com.jme3.math.ColorRGBA;
|
||||||
|
import com.jme3.math.Vector3f;
|
||||||
|
import com.jme3.scene.Node;
|
||||||
|
import com.jme3.scene.control.AbstractControl;
|
||||||
|
import pp.battleship.client.BattleshipApp;
|
||||||
|
import pp.battleship.model.Shot;
|
||||||
|
|
||||||
|
import java.lang.System.Logger;
|
||||||
|
import java.lang.System.Logger.Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages the visual effects for impact events such as hits and misses.
|
||||||
|
*/
|
||||||
|
public class ImpactEffectManager {
|
||||||
|
|
||||||
|
private final AssetManager assetManager;
|
||||||
|
private static final Logger LOGGER = System.getLogger(ImpactEffectManager.class.getName());
|
||||||
|
|
||||||
|
private Material particleMaterial;
|
||||||
|
private BattleshipApp app;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to initialize the asset manager via the main application.
|
||||||
|
*
|
||||||
|
* @param app The main application instance.
|
||||||
|
*/
|
||||||
|
public ImpactEffectManager(BattleshipApp app) {
|
||||||
|
this.app = app;
|
||||||
|
this.assetManager = app.getAssetManager();
|
||||||
|
this.particleMaterial = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a visual effect for a hit at the specified position.
|
||||||
|
*
|
||||||
|
* @param battleshipNode The node where the effect should be attached.
|
||||||
|
* @param shot The details of the shot where the hit occurred.
|
||||||
|
*/
|
||||||
|
public void triggerHitEffect(Node battleshipNode, Shot shot) {
|
||||||
|
ParticleEmitter hitEffect = createParticleEmitter("HitEffect", 50, ColorRGBA.Orange, ColorRGBA.Red, 0.45f, 0.1f, 1f, 2f);
|
||||||
|
|
||||||
|
hitEffect.setLocalTranslation(shot.getY() + 0.5f, 0, shot.getX() + 0.5f);
|
||||||
|
|
||||||
|
LOGGER.log(Level.DEBUG, "Hit effect created at position: {0}", hitEffect.getLocalTranslation().toString());
|
||||||
|
|
||||||
|
// hitEffect.emitAllParticles();
|
||||||
|
hitEffect.addControl(new EffectCleanupControl(hitEffect));
|
||||||
|
|
||||||
|
app.getRootNode().attachChild(hitEffect);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a visual effect for a missed shot at the specified location.
|
||||||
|
*
|
||||||
|
* @param shot The details of the missed shot.
|
||||||
|
* @return The particle emitter representing the miss effect.
|
||||||
|
*/
|
||||||
|
public ParticleEmitter triggerMissEffect(Shot shot) {
|
||||||
|
ParticleEmitter missEffect = createParticleEmitter("MissEffect", 50, ColorRGBA.Blue, ColorRGBA.Cyan, 0.3f, 0.05f, 0.5f, 1.5f);
|
||||||
|
missEffect.setLocalTranslation(shot.getY() + 0.5f, 0, shot.getX() + 0.5f);
|
||||||
|
missEffect.addControl(new EffectCleanupControl(missEffect));
|
||||||
|
return missEffect;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to create a particle emitter with predefined parameters.
|
||||||
|
*
|
||||||
|
* @param name The name of the particle emitter.
|
||||||
|
* @param count The number of particles to emit.
|
||||||
|
* @param startColor The initial color of the particles.
|
||||||
|
* @param endColor The final color of the particles.
|
||||||
|
* @param startSize The initial size of the particles.
|
||||||
|
* @param endSize The final size of the particles.
|
||||||
|
* @param lowLife The minimum lifetime of the particles.
|
||||||
|
* @param highLife The maximum lifetime of the particles.
|
||||||
|
* @return The configured ParticleEmitter instance.
|
||||||
|
*/
|
||||||
|
private ParticleEmitter createParticleEmitter(String name, int count, ColorRGBA startColor, ColorRGBA endColor, float startSize, float endSize, float lowLife, float highLife) {
|
||||||
|
ParticleEmitter emitter = new ParticleEmitter(name, Type.Triangle, count);
|
||||||
|
emitter.setNumParticles(0);
|
||||||
|
emitter.setMaterial(particleMaterial);
|
||||||
|
emitter.setImagesX(2);
|
||||||
|
emitter.setImagesY(2);
|
||||||
|
emitter.setStartColor(startColor);
|
||||||
|
emitter.setEndColor(endColor);
|
||||||
|
emitter.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 1, 0));
|
||||||
|
emitter.setStartSize(startSize);
|
||||||
|
emitter.setEndSize(endSize);
|
||||||
|
emitter.setGravity(0, -0.5f, 0);
|
||||||
|
emitter.setLowLife(lowLife);
|
||||||
|
emitter.setHighLife(highLife);
|
||||||
|
return emitter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom control class to handle the cleanup of particle effects once they are no longer visible.
|
||||||
|
*/
|
||||||
|
private static class EffectCleanupControl extends AbstractControl {
|
||||||
|
|
||||||
|
private final ParticleEmitter emitter;
|
||||||
|
|
||||||
|
private float currentTime = 0;
|
||||||
|
private final float duration = 3.5f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for managing cleanup of a standalone particle emitter.
|
||||||
|
*
|
||||||
|
* @param emitter The particle emitter to manage.
|
||||||
|
*/
|
||||||
|
public EffectCleanupControl(ParticleEmitter emitter) {
|
||||||
|
this.emitter = emitter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the emitter when all particles are no longer visible.
|
||||||
|
*
|
||||||
|
* @param tpf Time per frame.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void controlUpdate(float tpf) {
|
||||||
|
currentTime += tpf;
|
||||||
|
if (currentTime <= duration) {
|
||||||
|
}
|
||||||
|
if (currentTime >= 1f && currentTime <= 1.1) {
|
||||||
|
//Start
|
||||||
|
emitter.setNumParticles(50);
|
||||||
|
emitter.setParticlesPerSec(50);
|
||||||
|
}
|
||||||
|
if (currentTime >= duration){
|
||||||
|
emitter.setParticlesPerSec(0);
|
||||||
|
}
|
||||||
|
if (currentTime >= duration+1f) {
|
||||||
|
//Ende
|
||||||
|
spatial.removeFromParent();
|
||||||
|
emitter.emitAllParticles();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* No custom rendering needed; particle behavior is handled in controlUpdate.
|
||||||
|
* @param rm handles rendering, and ViewPort
|
||||||
|
* @param vp defines the view where the scene is displayed.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void controlRender(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp) {
|
||||||
|
// No rendering-specific behavior needed for this control.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,15 +8,14 @@
|
|||||||
package pp.battleship.client.gui;
|
package pp.battleship.client.gui;
|
||||||
|
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.Vector3f;
|
|
||||||
import com.jme3.scene.Geometry;
|
import com.jme3.scene.Geometry;
|
||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
import pp.battleship.model.Battleship;
|
import pp.battleship.model.Battleship;
|
||||||
import pp.battleship.model.IntPoint;
|
|
||||||
import pp.battleship.model.Shell;
|
import pp.battleship.model.Shell;
|
||||||
import pp.battleship.model.Shot;
|
import pp.battleship.model.Shot;
|
||||||
import pp.util.Position;
|
import pp.util.Position;
|
||||||
|
import java.lang.System.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synchronizes the visual representation of the ship map with the game model.
|
* Synchronizes the visual representation of the ship map with the game model.
|
||||||
@@ -29,10 +28,8 @@ class MapViewSynchronizer extends ShipMapSynchronizer {
|
|||||||
private static final float SHOT_DEPTH = -2f;
|
private static final float SHOT_DEPTH = -2f;
|
||||||
private static final float SHIP_DEPTH = 0f;
|
private static final float SHIP_DEPTH = 0f;
|
||||||
private static final float INDENT = 4f;
|
private static final float INDENT = 4f;
|
||||||
private static final float SHELL_DEPTH = 8f;
|
|
||||||
private static final float SHELL_SIZE = 0.75f;
|
|
||||||
private static final float SHELL_CENTERED_IN_MAP_GRID = 0.0625f;
|
|
||||||
|
|
||||||
|
private static final float SHELL_DEPTH = 8f;
|
||||||
|
|
||||||
// Colors used for different visual elements
|
// Colors used for different visual elements
|
||||||
private static final ColorRGBA HIT_COLOR = ColorRGBA.Red;
|
private static final ColorRGBA HIT_COLOR = ColorRGBA.Red;
|
||||||
@@ -117,28 +114,23 @@ public Spatial visit(Battleship ship) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a visual representation of a shell on the map.
|
* Creates a visual representation (Spatial) for the given shell, attaching a control for its behavior.
|
||||||
*
|
* @param shell the shell to visit and visualize
|
||||||
* @param shell the Shell object representing the shell in the model
|
* @return the constructed shell node (Spatial)
|
||||||
* @return a Spatial representing the shell
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Spatial visit(Shell shell) {
|
public Spatial visit(Shell shell) {
|
||||||
|
LOGGER.log(Logger.Level.DEBUG, "Visiting {0}", shell);
|
||||||
final Node shellNode = new Node("shell");
|
final Node shellNode = new Node("shell");
|
||||||
|
final Position startPosition = view.modelToView(shell.getCurrentPosition().x,shell.getCurrentPosition().z);
|
||||||
|
|
||||||
final Position p1 = view.modelToView(shell.getX(), shell.getY());
|
shellNode.attachChild(view.getApp().getDraw().makeRectangle(startPosition.getX(),startPosition.getY(), SHELL_DEPTH, 30, 30, ColorRGBA.Black));
|
||||||
final Position p2 = view.modelToView(shell.getX() + SHELL_SIZE, shell.getY() + SHELL_SIZE);
|
|
||||||
|
|
||||||
final Position startPosition = view.modelToView(SHELL_CENTERED_IN_MAP_GRID, SHELL_CENTERED_IN_MAP_GRID);
|
shellNode.addControl(new ShellControl(shell, this.view, shell.getLogic()));
|
||||||
|
|
||||||
shellNode.attachChild(view.getApp().getDraw().makeRectangle(startPosition.getX(), startPosition.getY(), SHELL_DEPTH, p2.getX() - p1.getX(), p2.getY() - p1.getY(), ColorRGBA.Magenta));
|
|
||||||
shellNode.setLocalTranslation(startPosition.getX(), startPosition.getY(), SHELL_DEPTH);
|
|
||||||
shellNode.addControl(new ShellControlMap(p1, view.getApp(), new IntPoint(shell.getX(), shell.getY())));
|
|
||||||
return shellNode;
|
return shellNode;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a line geometry representing part of the ship's border.
|
* Creates a line geometry representing part of the ship's border.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,193 +0,0 @@
|
|||||||
package pp.battleship.client.gui;
|
|
||||||
|
|
||||||
import com.jme3.effect.ParticleEmitter;
|
|
||||||
import com.jme3.effect.ParticleMesh;
|
|
||||||
import com.jme3.material.Material;
|
|
||||||
import com.jme3.math.ColorRGBA;
|
|
||||||
import com.jme3.math.Vector3f;
|
|
||||||
import com.jme3.scene.Node;
|
|
||||||
import com.jme3.scene.control.AbstractControl;
|
|
||||||
import com.jme3.scene.control.Control;
|
|
||||||
import pp.battleship.client.BattleshipApp;
|
|
||||||
import pp.battleship.model.Shot;
|
|
||||||
|
|
||||||
public class ParticleHandler {
|
|
||||||
private final BattleshipApp app;
|
|
||||||
static final System.Logger LOGGER = System.getLogger(ParticleHandler.class.getName());
|
|
||||||
|
|
||||||
private Material material;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new ParticleHandler
|
|
||||||
*
|
|
||||||
* @param app the main battleship application
|
|
||||||
*/
|
|
||||||
public ParticleHandler(BattleshipApp app) {
|
|
||||||
this.app = app;
|
|
||||||
material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* this method is used to create a hit effect at the position of a node
|
|
||||||
*
|
|
||||||
* @param node the node of the battleship where the effect should be attached to
|
|
||||||
* @param shot the shot that hit a target
|
|
||||||
*/
|
|
||||||
public void createHitParticles(Node node, Shot shot) {
|
|
||||||
ParticleEmitter smokeParticles = new ParticleEmitter("Effect", ParticleMesh.Type.Triangle,1000);
|
|
||||||
smokeParticles.setMaterial(material);
|
|
||||||
smokeParticles.setImagesX(2);
|
|
||||||
smokeParticles.setImagesY(2);
|
|
||||||
smokeParticles.setStartColor(ColorRGBA.Orange);
|
|
||||||
smokeParticles.setEndColor(ColorRGBA.Black);
|
|
||||||
smokeParticles.getParticleInfluencer().setInitialVelocity(new Vector3f(0,0.8f,0));
|
|
||||||
smokeParticles.setStartSize(0.5f);
|
|
||||||
smokeParticles.setEndSize(0.04f);
|
|
||||||
smokeParticles.setGravity(0, -0.1f, 0);
|
|
||||||
smokeParticles.setLowLife(1f);
|
|
||||||
smokeParticles.setHighLife(4f);
|
|
||||||
smokeParticles.setParticlesPerSec(0);
|
|
||||||
smokeParticles.setLocalTranslation(shot.getY() + 0.5f, 0 , shot.getX() + 0.5f);
|
|
||||||
smokeParticles.emitAllParticles();
|
|
||||||
|
|
||||||
ParticleEmitter particles2 = new ParticleEmitter("Effect", ParticleMesh.Type.Triangle,300);
|
|
||||||
particles2.setMaterial(material);
|
|
||||||
particles2.setImagesX(2);
|
|
||||||
particles2.setImagesY(2);
|
|
||||||
particles2.setStartColor(ColorRGBA.Orange);
|
|
||||||
particles2.setEndColor(ColorRGBA.Yellow);
|
|
||||||
particles2.getParticleInfluencer().setInitialVelocity(new Vector3f(0,2,0));
|
|
||||||
particles2.setStartSize(0.7f);
|
|
||||||
particles2.setEndSize(0.1f);
|
|
||||||
particles2.setGravity(0, 0, 0);
|
|
||||||
particles2.setLowLife(0.5f);
|
|
||||||
particles2.setHighLife(1.5f);
|
|
||||||
particles2.setParticlesPerSec(0);
|
|
||||||
particles2.setLocalTranslation(shot.getY() + 1f, 0 , shot.getX() + 1f);
|
|
||||||
particles2.emitAllParticles();
|
|
||||||
|
|
||||||
ParticleEmitter particles3 = new ParticleEmitter("Effect", ParticleMesh.Type.Triangle,300);
|
|
||||||
particles3.setMaterial(material);
|
|
||||||
particles3.setImagesX(1);
|
|
||||||
particles3.setImagesY(1);
|
|
||||||
particles3.setStartColor(ColorRGBA.Red);
|
|
||||||
particles3.setEndColor(ColorRGBA.Gray);
|
|
||||||
particles3.getParticleInfluencer().setInitialVelocity(new Vector3f(0,0.5f,0));
|
|
||||||
particles3.setStartSize(0.8f);
|
|
||||||
particles3.setEndSize(0.1f);
|
|
||||||
particles3.setGravity(0, 0, 0);
|
|
||||||
particles3.setLowLife(0.5f);
|
|
||||||
particles3.setHighLife(0.8f);
|
|
||||||
particles3.setParticlesPerSec(0);
|
|
||||||
particles3.setLocalTranslation(shot.getY() + 1f, 0 , shot.getX() + 1f);
|
|
||||||
particles3.emitAllParticles();
|
|
||||||
|
|
||||||
ParticleEmitter flames = new ParticleEmitter("Effect", ParticleMesh.Type.Triangle,300);
|
|
||||||
flames.setMaterial(material);
|
|
||||||
flames.setImagesX(1);
|
|
||||||
flames.setImagesY(1);
|
|
||||||
flames.setStartColor(ColorRGBA.Red);
|
|
||||||
flames.setEndColor(ColorRGBA.Orange);
|
|
||||||
flames.getParticleInfluencer().setInitialVelocity(new Vector3f(0,1.0f,0));
|
|
||||||
flames.setStartSize(0.4f);
|
|
||||||
flames.setEndSize(0.1f);
|
|
||||||
flames.setGravity(0, -0.2f, 0);
|
|
||||||
flames.setLowLife(0.7f);
|
|
||||||
flames.setHighLife(1.5f);
|
|
||||||
flames.setLocalTranslation(shot.getY(), 0 , shot.getX());
|
|
||||||
flames.setLocalTranslation(flames.getLocalTranslation().subtract(node.getLocalTranslation()));
|
|
||||||
flames.setParticlesPerSec(70);
|
|
||||||
|
|
||||||
node.attachChild(smokeParticles);
|
|
||||||
smokeParticles.addControl((Control) new ParticleControl(smokeParticles, node));
|
|
||||||
|
|
||||||
node.attachChild(particles2);
|
|
||||||
particles2.addControl((Control) new ParticleControl(particles2, node));
|
|
||||||
|
|
||||||
node.attachChild(particles3);
|
|
||||||
particles3.addControl((Control) new ParticleControl(particles3, node));
|
|
||||||
|
|
||||||
//node.attachChild(flames);
|
|
||||||
//flames.addControl((Control) new ParticleControl(flames, node));
|
|
||||||
|
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Hit-particles at {0}", smokeParticles.getLocalTranslation().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a miss effect at a certain location
|
|
||||||
* @param shot the shot that missed
|
|
||||||
* @return A ParticleEmitter
|
|
||||||
*/
|
|
||||||
public ParticleEmitter createMissParticles(Shot shot) {
|
|
||||||
ParticleEmitter particles = new ParticleEmitter("MissEffect", ParticleMesh.Type.Triangle, 200);
|
|
||||||
particles.setMaterial(material);
|
|
||||||
particles.setImagesX(2);
|
|
||||||
particles.setImagesY(2);
|
|
||||||
particles.setStartColor(ColorRGBA.Blue);
|
|
||||||
particles.setEndColor(ColorRGBA.White);
|
|
||||||
particles.getParticleInfluencer().setInitialVelocity(new Vector3f(0.01f, 3f, 0.01f));
|
|
||||||
particles.setStartSize(0.05f);
|
|
||||||
particles.setEndSize(0.4f);
|
|
||||||
particles.setGravity(0, 2f, 0);
|
|
||||||
particles.setLowLife(1.0f);
|
|
||||||
particles.setHighLife(2.2f);
|
|
||||||
particles.setParticlesPerSec(0);
|
|
||||||
particles.setLocalTranslation(shot.getY(), -0.5f , shot.getX());
|
|
||||||
particles.emitAllParticles();
|
|
||||||
|
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Miss-particles at {0}", particles.getLocalTranslation().toString());
|
|
||||||
|
|
||||||
return particles;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This inner class is used to control the effects
|
|
||||||
*/
|
|
||||||
private static class ParticleControl extends AbstractControl {
|
|
||||||
private final ParticleEmitter emitter;
|
|
||||||
private final Node parentNode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* this constructor is used to when the particle should be attached to a specific node
|
|
||||||
*
|
|
||||||
* @param emitter the Particle emitter to be controlled
|
|
||||||
* @param parentNode the node to be attached
|
|
||||||
*/
|
|
||||||
public ParticleControl(ParticleEmitter emitter, Node parentNode) {
|
|
||||||
this.emitter = emitter;
|
|
||||||
this.parentNode = parentNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This constructor is used when the particle shouldn't be attached to
|
|
||||||
* a specific node
|
|
||||||
*
|
|
||||||
* @param emitter the Particle emitter to be controlled
|
|
||||||
*/
|
|
||||||
public ParticleControl(ParticleEmitter emitter) {
|
|
||||||
this.emitter = emitter;
|
|
||||||
this.parentNode = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The method which checks if the particle is not rendered anymore so it can be removed
|
|
||||||
*
|
|
||||||
* @param tpf time per frame (in seconds)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void controlUpdate(float tpf) {
|
|
||||||
if (emitter.getParticlesPerSec() == 0 && emitter.getNumVisibleParticles() == 0) {
|
|
||||||
if (parentNode != null)
|
|
||||||
parentNode.detachChild(emitter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param rm the RenderManager rendering the controlled Spatial (not null)
|
|
||||||
* @param vp the ViewPort being rendered (not null)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void controlRender(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,9 +10,6 @@
|
|||||||
import com.jme3.material.Material;
|
import com.jme3.material.Material;
|
||||||
import com.jme3.material.RenderState.BlendMode;
|
import com.jme3.material.RenderState.BlendMode;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.FastMath;
|
|
||||||
import com.jme3.math.Quaternion;
|
|
||||||
import com.jme3.math.Vector3f;
|
|
||||||
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
|
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
|
||||||
import com.jme3.scene.Geometry;
|
import com.jme3.scene.Geometry;
|
||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
@@ -34,18 +31,21 @@
|
|||||||
*/
|
*/
|
||||||
class SeaSynchronizer extends ShipMapSynchronizer {
|
class SeaSynchronizer extends ShipMapSynchronizer {
|
||||||
private static final String UNSHADED = "Common/MatDefs/Misc/Unshaded.j3md"; //NON-NLS
|
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 KING_GEORGE_V_MODEL = "Models/KingGeorgeV/KingGeorgeV.j3o";//NON-NLS
|
||||||
|
private static final String DESTROYER = "Models/Destroyer/Destroyer.j3o";
|
||||||
|
private static final String FERRY = "Models/Ferry/13922_Staten_Island_Ferry_V1_l1.obj";
|
||||||
|
private static final String SMALL = "Models/Small/10634_SpeedBoat_v01_LOD3.obj";
|
||||||
|
private static final String BOMB = "Models/Bomb/BombGBU.j3o";
|
||||||
private static final String COLOR = "Color"; //NON-NLS
|
private static final String COLOR = "Color"; //NON-NLS
|
||||||
private static final String SHIP = "ship"; //NON-NLS
|
private static final String SHIP = "ship"; //NON-NLS
|
||||||
private static final String SHOT = "shot"; //NON-NLS
|
private static final String SHOT = "shot"; //NON-NLS
|
||||||
private static final ColorRGBA BOX_COLOR = ColorRGBA.Gray;
|
private static final ColorRGBA BOX_COLOR = ColorRGBA.Gray;
|
||||||
private static final ColorRGBA SPLASH_COLOR = new ColorRGBA(0f, 0f, 1f, 0.4f);
|
private static final ColorRGBA SPLASH_COLOR = new ColorRGBA(0f, 0f, 1f, 0.4f);
|
||||||
private static final ColorRGBA HIT_COLOR = new ColorRGBA(1f, 0f, 0f, 0.4f);
|
private static final ColorRGBA HIT_COLOR = new ColorRGBA(1f, 0f, 0f, 0.4f);
|
||||||
private static final String BOMB = "Models/Bomb/Files/Bomb GBU-43B(MOAB).obj";
|
|
||||||
|
|
||||||
private final ShipMap map;
|
private final ShipMap map;
|
||||||
private final BattleshipApp app;
|
private final BattleshipApp app;
|
||||||
private final ParticleHandler handler;
|
private ImpactEffectManager effectHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a {@code SeaSynchronizer} object with the specified application, root node, and ship map.
|
* Constructs a {@code SeaSynchronizer} object with the specified application, root node, and ship map.
|
||||||
@@ -58,41 +58,10 @@ public SeaSynchronizer(BattleshipApp app, Node root, ShipMap map) {
|
|||||||
super(app.getGameLogic().getOwnMap(), root);
|
super(app.getGameLogic().getOwnMap(), root);
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.map = map;
|
this.map = map;
|
||||||
|
effectHandler = new ImpactEffectManager(app);
|
||||||
handler = new ParticleHandler(app);
|
|
||||||
|
|
||||||
addExisting();
|
addExisting();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Visits a {@link Shell} and creates a graphical representation of it.
|
|
||||||
*
|
|
||||||
* @param shell the shell to be represented
|
|
||||||
* @return the graphical representation of the shell
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Spatial visit(Shell shell) {
|
|
||||||
final Node node = new Node("shell");
|
|
||||||
|
|
||||||
final Spatial model = app.getAssetManager().loadModel(BOMB);
|
|
||||||
|
|
||||||
model.rotate(-PI/2, 0, 0);
|
|
||||||
model.scale(0.09f);
|
|
||||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
|
||||||
model.move(0, 0, 0);
|
|
||||||
|
|
||||||
node.attachChild(model);
|
|
||||||
|
|
||||||
final float x = shell.getY();
|
|
||||||
final float z = shell.getX();
|
|
||||||
|
|
||||||
node.setLocalTranslation(x, 8f, z);
|
|
||||||
ShellControll control = new ShellControll(shell, app);
|
|
||||||
node.addControl(control);
|
|
||||||
return node;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visits a {@link Shot} and creates a graphical representation of it.
|
* Visits a {@link Shot} and creates a graphical representation of it.
|
||||||
* If the shot is a hit, it attaches the representation to the ship node.
|
* If the shot is a hit, it attaches the representation to the ship node.
|
||||||
@@ -103,7 +72,7 @@ public Spatial visit(Shell shell) {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Spatial visit(Shot shot) {
|
public Spatial visit(Shot shot) {
|
||||||
return shot.isHit() ? handleHit(shot) : handler.createMissParticles(shot);
|
return shot.isHit() ? handleHit(shot) : effectHandler.triggerMissEffect(shot);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,14 +80,15 @@ public Spatial visit(Shot shot) {
|
|||||||
* contains the ship model as a child so that it moves with the ship.
|
* contains the ship model as a child so that it moves with the ship.
|
||||||
*
|
*
|
||||||
* @param shot a hit
|
* @param shot a hit
|
||||||
* @return always null to prevent the representation from being sattached
|
* @return always null to prevent the representation from being attached
|
||||||
* to the items node as well
|
* to the items node as well
|
||||||
*/
|
*/
|
||||||
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");
|
||||||
|
|
||||||
handler.createHitParticles(shipNode, shot);
|
System.out.println(shot.getX() + " " + shot.getY());
|
||||||
|
effectHandler.triggerHitEffect(shipNode, shot);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -139,7 +109,7 @@ private Geometry createCylinder(Shot shot) {
|
|||||||
|
|
||||||
geometry.setMaterial(createColoredMaterial(color));
|
geometry.setMaterial(createColoredMaterial(color));
|
||||||
geometry.rotate(HALF_PI, 0f, 0f);
|
geometry.rotate(HALF_PI, 0f, 0f);
|
||||||
// compute the center of the shot in world coordinates
|
|
||||||
geometry.setLocalTranslation(shot.getY() + 0.5f, 0f, shot.getX() + 0.5f);
|
geometry.setLocalTranslation(shot.getY() + 0.5f, 0f, shot.getX() + 0.5f);
|
||||||
|
|
||||||
return geometry;
|
return geometry;
|
||||||
@@ -165,41 +135,42 @@ public Spatial visit(Battleship ship) {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Spatial visit(Shell shell) {
|
||||||
|
final Spatial bombModel = app.getAssetManager().loadModel(BOMB);
|
||||||
|
|
||||||
|
// Apply transformations to the bomb model (scale, rotate, etc. if needed)
|
||||||
|
bombModel.scale(0.05f);
|
||||||
|
bombModel.rotate(-HALF_PI, 0f, 0f);
|
||||||
|
|
||||||
|
// Set the position of the bomb at the shell's current position
|
||||||
|
bombModel.setLocalTranslation(shell.getCurrentPosition());
|
||||||
|
|
||||||
|
// Add a control to animate the bomb's movement (similar to the previous cylinder animation)
|
||||||
|
bombModel.addControl(new ShellControl(shell,shell.getLogic()));
|
||||||
|
|
||||||
|
return bombModel;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the appropriate graphical representation of the specified battleship.
|
* Creates the appropriate graphical representation of the specified battleship.
|
||||||
* The representation is either a detailed model or a simple box based on the length of the ship.
|
* The representation is a detailed model based on the length of the ship.
|
||||||
*
|
*
|
||||||
* @param ship the battleship to be represented
|
* @param ship the battleship to be represented
|
||||||
* @return the spatial representing the battleship
|
* @return the spatial representing the battleship
|
||||||
*/
|
*/
|
||||||
private Spatial createShip(Battleship ship) {
|
private Spatial createShip(Battleship ship) {
|
||||||
final int len = ship.getLength();
|
// return ship.getLength() == 4 ? createBattleship(ship) : createBox(ship);
|
||||||
|
if (ship.getLength() == 4) {
|
||||||
Quaternion q0 = new Quaternion();
|
return createBattleship(ship);
|
||||||
|
} else if (ship.getLength() == 3) {
|
||||||
Quaternion q1 = new Quaternion();
|
return createBigShip(ship);
|
||||||
q1.fromAngleAxis(PI/2, new Vector3f(1, 0, 0));
|
} else if (ship.getLength() == 2) {
|
||||||
|
return createMediumShip(ship);
|
||||||
Quaternion q2 = new Quaternion();
|
} else if (ship.getLength() == 1) {
|
||||||
q2.fromAngleAxis(PI/2, new Vector3f(1, 0, 0));
|
return createSmallShip(ship);
|
||||||
|
|
||||||
switch (len) {
|
|
||||||
case 1 -> {
|
|
||||||
return createBattleship(ship, "Models/Uboat/uboat.j3o", 0.2f, new Vector3f(0.0f, -0.1f, 0.0f), q0);
|
|
||||||
}
|
|
||||||
case 2 -> {
|
|
||||||
return createBattleship(ship, "Models/KingGeorgeV/KingGeorgeV.j3o", 1.0f, new Vector3f(0.0f, 0.0f, 0.0f), q0);
|
|
||||||
}
|
|
||||||
case 3 -> {
|
|
||||||
return createBattleship(ship, "Models/EssexClass/essex.j3o", 0.8f, new Vector3f(0.0f, 0.3f, 0.0f), q2);
|
|
||||||
}
|
|
||||||
case 4 -> {
|
|
||||||
return createBattleship(ship, "Models/Container/container.j3o", 0.05f, new Vector3f(0.0f, 0.0f, 0.0f), q1);
|
|
||||||
}
|
|
||||||
default -> {
|
|
||||||
return createBox(ship);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return createBattleship(ship);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -239,22 +210,63 @@ private Material createColoredMaterial(ColorRGBA color) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a 3D model to represent a "battleship".
|
* Creates a detailed 3D model to represent a "King George V" battleship.
|
||||||
*
|
*
|
||||||
* @param ship the battleship to be represented
|
* @param ship the battleship to be represented
|
||||||
* @param path the battleship to be represented
|
* @return the spatial representing the "King George V" battleship
|
||||||
* @param scale the battleship to be represented
|
|
||||||
* @param translation the battleship to be represented
|
|
||||||
* @param rotation the battleship to be represented
|
|
||||||
* @return the spatial representing the battleship
|
|
||||||
*/
|
*/
|
||||||
private Spatial createBattleship(Battleship ship, String path, float scale, Vector3f translation, Quaternion rotation) {
|
private Spatial createBattleship(Battleship ship) {
|
||||||
final Spatial model = app.getAssetManager().loadModel(path);
|
final Spatial model = app.getAssetManager().loadModel(KING_GEORGE_V_MODEL);
|
||||||
|
|
||||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
||||||
model.rotate(rotation);
|
model.scale(1.48f);
|
||||||
model.scale(scale);
|
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||||
model.setLocalTranslation(translation);
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a detailed 3D model to represent a "Big Ship"
|
||||||
|
* @param ship The Battleship object with position and rotation info.
|
||||||
|
* @return the spatial representing the "Big Ship" battleship
|
||||||
|
*/
|
||||||
|
private Spatial createBigShip(Battleship ship) {
|
||||||
|
final Spatial model = app.getAssetManager().loadModel(DESTROYER);
|
||||||
|
|
||||||
|
model.move(0,0.4f,0);
|
||||||
|
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()) + HALF_PI, 0f);
|
||||||
|
model.scale(0.0001f);
|
||||||
|
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a detailed 3D model to represent a "Medium Ship"
|
||||||
|
* @param ship The Battleship object with position and rotation info.
|
||||||
|
* @return the spatial representing the "Medium Ship" battleship
|
||||||
|
*/
|
||||||
|
private Spatial createMediumShip(Battleship ship) {
|
||||||
|
final Spatial model = app.getAssetManager().loadModel(FERRY);
|
||||||
|
|
||||||
|
model.move(0,0.25f,0);
|
||||||
|
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
||||||
|
model.scale(0.00025f);
|
||||||
|
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a detailed 3D model to represent a "Small Ship"
|
||||||
|
* @param ship The Battleship object with position and rotation info.
|
||||||
|
* @return the spatial representing the "Small Ship" battleship
|
||||||
|
*/
|
||||||
|
private Spatial createSmallShip(Battleship ship) {
|
||||||
|
final Spatial model = app.getAssetManager().loadModel(SMALL);
|
||||||
|
|
||||||
|
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()) + HALF_PI, 0f);
|
||||||
|
model.scale(0.0009f);
|
||||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
////////////////////////////////////////
|
||||||
|
// Programming project code
|
||||||
|
// UniBw M, 2022, 2023, 2024
|
||||||
|
// www.unibw.de/inf2
|
||||||
|
// (c) Mark Minas (mark.minas@unibw.de)
|
||||||
|
////////////////////////////////////////
|
||||||
|
|
||||||
|
package pp.battleship.client.gui;
|
||||||
|
|
||||||
|
import com.jme3.renderer.RenderManager;
|
||||||
|
import com.jme3.renderer.ViewPort;
|
||||||
|
import com.jme3.scene.control.AbstractControl;
|
||||||
|
import pp.battleship.game.client.ClientGameLogic;
|
||||||
|
import pp.battleship.message.server.EffectMessage;
|
||||||
|
import pp.battleship.model.Shell;
|
||||||
|
import pp.battleship.notification.Sound;
|
||||||
|
import pp.util.Position;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controls the oscillating pitch motion of a battleship model in the game.
|
||||||
|
* The ship oscillates to simulate a realistic movement on water, based on its orientation and length.
|
||||||
|
*/
|
||||||
|
class ShellControl extends AbstractControl {
|
||||||
|
|
||||||
|
private final Shell shell;
|
||||||
|
private MapView view;
|
||||||
|
private final ClientGameLogic logic;
|
||||||
|
private final EffectMessage msg;
|
||||||
|
private boolean hasPlayedSound = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new ShipControl instance for the specified Battleship.
|
||||||
|
* The ship's orientation determines the axis of rotation, while its length influences
|
||||||
|
* the cycle duration and amplitude of the oscillation.
|
||||||
|
*
|
||||||
|
* @param shell the Battleship object to control
|
||||||
|
*/
|
||||||
|
public ShellControl(Shell shell, ClientGameLogic clientGameLogic) {
|
||||||
|
this.shell = shell;
|
||||||
|
this.logic = clientGameLogic;
|
||||||
|
this.msg = shell.getMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes ShellControl with a shell, map view, and game logic.
|
||||||
|
* @param shell the shell to be controlled
|
||||||
|
* @param view the map view to display the shell
|
||||||
|
* @param clientGameLogic the game logic instance
|
||||||
|
*/
|
||||||
|
public ShellControl(Shell shell, MapView view, ClientGameLogic clientGameLogic) {
|
||||||
|
this.shell = shell;
|
||||||
|
this.view = view;
|
||||||
|
this.logic = clientGameLogic;
|
||||||
|
this.msg = shell.getMsg();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the ship's pitch oscillation each frame. The ship's pitch is adjusted
|
||||||
|
* to create a continuous tilting motion, simulating the effect of waves.
|
||||||
|
*
|
||||||
|
* @param tpf time per frame (in seconds), used to calculate the new pitch angle
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void controlUpdate(float tpf) {
|
||||||
|
|
||||||
|
if (spatial == null)
|
||||||
|
return;
|
||||||
|
if (shell.isFinished() && !hasPlayedSound) {
|
||||||
|
if (!msg.getShot().isHit())
|
||||||
|
logic.playSound(Sound.SPLASH);
|
||||||
|
else if (msg.getDestroyedShip() == null)
|
||||||
|
logic.playSound(Sound.EXPLOSION);
|
||||||
|
else
|
||||||
|
logic.playSound(Sound.DESTROYED_SHIP);
|
||||||
|
hasPlayedSound = true;
|
||||||
|
}
|
||||||
|
if (view == null) {
|
||||||
|
shell.updatePosition(tpf);
|
||||||
|
spatial.setLocalTranslation(shell.getCurrentPosition());
|
||||||
|
} else {
|
||||||
|
shell.updatePosition(tpf);
|
||||||
|
Position pos2d = view.modelToView(shell.getCurrentPosition().x - 0.3f, shell.getCurrentPosition().z - 0.3f);
|
||||||
|
spatial.setLocalTranslation(pos2d.getY(), pos2d.getX(), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called during rendering, but no operations are needed as this control only affects spatial transformation.
|
||||||
|
* @param rm the RenderManager rendering the spatial
|
||||||
|
* @param vp the ViewPort being rendered
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||||
|
// No rendering logic is needed for this control
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,67 +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.client.BattleshipApp;
|
|
||||||
import pp.battleship.message.client.AnimationEndMessage;
|
|
||||||
import pp.battleship.model.IntPoint;
|
|
||||||
import pp.util.Position;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Controls the movement of a shell in a specified position on the battlefield.
|
|
||||||
* This control updates the shell's position and sends a message when it reaches
|
|
||||||
* its target location.
|
|
||||||
*/
|
|
||||||
public class ShellControlMap extends AbstractControl {
|
|
||||||
private final Position position; // Target position for the shell
|
|
||||||
private final IntPoint pos; // Target coordinates as an IntPoint
|
|
||||||
private static final Vector3f vector = new Vector3f(); // Movement vector
|
|
||||||
private final BattleshipApp app; // Reference to the main application
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a ShellControlMap object with the specified target position,
|
|
||||||
* application instance, and target coordinates.
|
|
||||||
*
|
|
||||||
* @param position The target Position for the shell.
|
|
||||||
* @param app The BattleshipApp instance managing the game logic.
|
|
||||||
* @param pos The IntPoint representing the target coordinates of the shell.
|
|
||||||
*/
|
|
||||||
public ShellControlMap(Position position, BattleshipApp app, IntPoint pos) {
|
|
||||||
super();
|
|
||||||
this.position = position;
|
|
||||||
this.pos = pos;
|
|
||||||
this.app = app;
|
|
||||||
vector.set(new Vector3f(position.getX(), position.getY(), 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the shell's position based on the time per frame.
|
|
||||||
* If the shell reaches or exceeds the target position, it detaches
|
|
||||||
* the shell from the scene and sends an animation end message.
|
|
||||||
*
|
|
||||||
* @param tpf Time per frame, used to calculate movement.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void controlUpdate(float tpf) {
|
|
||||||
spatial.move(vector.mult(tpf));
|
|
||||||
if (spatial.getLocalTranslation().getX() >= position.getX() &&
|
|
||||||
spatial.getLocalTranslation().getY() >= position.getY()) {
|
|
||||||
spatial.getParent().detachChild(spatial);
|
|
||||||
app.getGameLogic().send(new AnimationEndMessage(pos));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders the shell control. This method can be overridden to implement
|
|
||||||
* custom rendering behavior, but it is currently empty.
|
|
||||||
*
|
|
||||||
* @param rm The RenderManager for rendering the control.
|
|
||||||
* @param vp The ViewPort where the control is rendered.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
|
||||||
// No rendering logic implemented for ShellControlMap
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
package pp.battleship.client.gui;
|
|
||||||
|
|
||||||
import com.jme3.renderer.RenderManager;
|
|
||||||
import com.jme3.renderer.ViewPort;
|
|
||||||
import com.jme3.scene.control.AbstractControl;
|
|
||||||
import pp.battleship.client.BattleshipApp;
|
|
||||||
import pp.battleship.message.client.AnimationEndMessage;
|
|
||||||
import pp.battleship.model.IntPoint;
|
|
||||||
import pp.battleship.model.Shell;
|
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Controls the movement and behavior of a shell in the battleship game.
|
|
||||||
* This control updates the position of the shell and sends a message
|
|
||||||
* when the shell reaches the ground.
|
|
||||||
*/
|
|
||||||
public class ShellControll extends AbstractControl {
|
|
||||||
private final Shell shell;
|
|
||||||
private final BattleshipApp app;
|
|
||||||
|
|
||||||
private static final float MOVE_SPEED = 20.0f; // Speed at which the shell moves
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a ShellControll object with the specified shell and application instance.
|
|
||||||
*
|
|
||||||
* @param shell The Shell instance to control.
|
|
||||||
* @param app The BattleshipApp instance managing the game logic.
|
|
||||||
*/
|
|
||||||
public ShellControll(Shell shell, BattleshipApp app) {
|
|
||||||
this.shell = shell;
|
|
||||||
this.app = app;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the shell's position based on the time per frame.
|
|
||||||
* If the shell's position falls below a certain threshold,
|
|
||||||
* it detaches the shell from the scene and sends an animation end message.
|
|
||||||
*
|
|
||||||
* @param tpf Time per frame, used to calculate movement.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void controlUpdate(float tpf) {
|
|
||||||
spatial.move(0, -MOVE_SPEED * tpf, 0);
|
|
||||||
if (spatial.getLocalTranslation().getY() <= 0.1f) {
|
|
||||||
spatial.getParent().detachChild(spatial);
|
|
||||||
app.getGameLogic().send(new AnimationEndMessage(new IntPoint(shell.getX(), shell.getY())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders the shell control. This method can be overridden to implement
|
|
||||||
* custom rendering behavior, but it is currently empty.
|
|
||||||
*
|
|
||||||
* @param rm The RenderManager for rendering the control.
|
|
||||||
* @param vp The ViewPort where the control is rendered.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
|
||||||
// No rendering logic implemented for ShellControll
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,6 +14,10 @@
|
|||||||
import com.jme3.scene.control.AbstractControl;
|
import com.jme3.scene.control.AbstractControl;
|
||||||
import pp.battleship.model.Battleship;
|
import pp.battleship.model.Battleship;
|
||||||
|
|
||||||
|
import java.lang.System.Logger;
|
||||||
|
import java.lang.System.Logger.Level;
|
||||||
|
|
||||||
|
|
||||||
import static pp.util.FloatMath.DEG_TO_RAD;
|
import static pp.util.FloatMath.DEG_TO_RAD;
|
||||||
import static pp.util.FloatMath.TWO_PI;
|
import static pp.util.FloatMath.TWO_PI;
|
||||||
import static pp.util.FloatMath.sin;
|
import static pp.util.FloatMath.sin;
|
||||||
@@ -23,12 +27,6 @@
|
|||||||
* The ship oscillates to simulate a realistic movement on water, based on its orientation and length.
|
* The ship oscillates to simulate a realistic movement on water, based on its orientation and length.
|
||||||
*/
|
*/
|
||||||
class ShipControl extends AbstractControl {
|
class ShipControl extends AbstractControl {
|
||||||
/**
|
|
||||||
* The sinking height, after wich the ship will get removed
|
|
||||||
*/
|
|
||||||
private static final Float SINKING_HEIGHT = -0.6f;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The axis of rotation for the ship's pitch (tilting forward and backward).
|
* The axis of rotation for the ship's pitch (tilting forward and backward).
|
||||||
*/
|
*/
|
||||||
@@ -53,11 +51,14 @@ class ShipControl extends AbstractControl {
|
|||||||
* The current time within the oscillation cycle, used to calculate the ship's pitch angle.
|
* The current time within the oscillation cycle, used to calculate the ship's pitch angle.
|
||||||
*/
|
*/
|
||||||
private float time;
|
private float time;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ship, that the ShipControl controls
|
* The current Ship
|
||||||
*/
|
*/
|
||||||
private final Battleship ship;
|
private final Battleship battleship;
|
||||||
|
/**
|
||||||
|
* Logger for logging messages related to ShipControl operations.
|
||||||
|
*/
|
||||||
|
static final Logger LOGGER = System.getLogger(ShipControl.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new ShipControl instance for the specified Battleship.
|
* Constructs a new ShipControl instance for the specified Battleship.
|
||||||
@@ -67,8 +68,7 @@ class ShipControl extends AbstractControl {
|
|||||||
* @param ship the Battleship object to control
|
* @param ship the Battleship object to control
|
||||||
*/
|
*/
|
||||||
public ShipControl(Battleship ship) {
|
public ShipControl(Battleship ship) {
|
||||||
this.ship = ship;
|
battleship = ship;
|
||||||
|
|
||||||
// Determine the axis of rotation based on the ship's orientation
|
// Determine the axis of rotation based on the ship's orientation
|
||||||
axis = switch (ship.getRot()) {
|
axis = switch (ship.getRot()) {
|
||||||
case LEFT, RIGHT -> Vector3f.UNIT_X;
|
case LEFT, RIGHT -> Vector3f.UNIT_X;
|
||||||
@@ -76,7 +76,7 @@ public ShipControl(Battleship ship) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Set the cycle duration and amplitude based on the ship's length
|
// Set the cycle duration and amplitude based on the ship's length
|
||||||
cycle = ship.getLength() * 2f;
|
cycle = battleship.getLength() * 2f;
|
||||||
amplitude = 5f * DEG_TO_RAD / ship.getLength();
|
amplitude = 5f * DEG_TO_RAD / ship.getLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,24 +91,23 @@ protected void controlUpdate(float tpf) {
|
|||||||
// If spatial is null, do nothing
|
// If spatial is null, do nothing
|
||||||
if (spatial == null) return;
|
if (spatial == null) return;
|
||||||
|
|
||||||
if (ship.isDestroyed() && spatial.getLocalTranslation().getY() < SINKING_HEIGHT) { // removes the ship, if it is completely sunk
|
|
||||||
spatial.getParent().detachChild(spatial);
|
|
||||||
}
|
|
||||||
else if (ship.isDestroyed() && spatial.getLocalTranslation().getY() >= SINKING_HEIGHT) { // sink the ship, if it's not completely sunk
|
|
||||||
spatial.move(0, tpf * -0.03f, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the time within the oscillation cycle
|
// Update the time within the oscillation cycle
|
||||||
time = (time + tpf) % cycle;
|
time = (time + tpf) % cycle;
|
||||||
|
if (battleship.isDestroyed() && spatial.getLocalTranslation().getY() <= -0.6f) {
|
||||||
|
LOGGER.log(Level.INFO, "Ship removed {0}", spatial.getName());
|
||||||
|
spatial.getParent().detachChild(spatial);
|
||||||
|
} else if (battleship.isDestroyed()) {
|
||||||
|
spatial.move(0, -0.05f * tpf, 0);
|
||||||
|
} else {
|
||||||
|
// Update the time within the oscillation cycle
|
||||||
|
time = (time + tpf) % cycle;
|
||||||
|
|
||||||
// Calculate the current angle of the oscillation
|
// Apply the pitch rotation to the spatial
|
||||||
final float angle = amplitude * sin(time * TWO_PI / cycle);
|
spatial.setLocalRotation(pitch);
|
||||||
|
}
|
||||||
|
|
||||||
// Update the pitch Quaternion with the new angle
|
|
||||||
pitch.fromAngleAxis(angle, axis);
|
|
||||||
|
|
||||||
// Apply the pitch rotation to the spatial
|
|
||||||
spatial.setLocalRotation(pitch);
|
spatial.setLocalRotation(pitch);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
// (c) Mark Minas (mark.minas@unibw.de)
|
// (c) Mark Minas (mark.minas@unibw.de)
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
|
||||||
package pp.battleship.client;
|
package pp.battleship.client.server;
|
||||||
|
|
||||||
import com.jme3.network.*;
|
import com.jme3.network.*;
|
||||||
import com.jme3.network.serializing.Serializer;
|
import com.jme3.network.serializing.Serializer;
|
||||||
@@ -13,11 +13,13 @@
|
|||||||
import pp.battleship.game.server.Player;
|
import pp.battleship.game.server.Player;
|
||||||
import pp.battleship.game.server.ServerGameLogic;
|
import pp.battleship.game.server.ServerGameLogic;
|
||||||
import pp.battleship.game.server.ServerSender;
|
import pp.battleship.game.server.ServerSender;
|
||||||
import pp.battleship.message.client.AnimationEndMessage;
|
|
||||||
import pp.battleship.message.client.ClientMessage;
|
import pp.battleship.message.client.ClientMessage;
|
||||||
import pp.battleship.message.client.MapMessage;
|
import pp.battleship.message.client.MapMessage;
|
||||||
import pp.battleship.message.client.ShootMessage;
|
import pp.battleship.message.client.ShootMessage;
|
||||||
import pp.battleship.message.server.*;
|
import pp.battleship.message.server.EffectMessage;
|
||||||
|
import pp.battleship.message.server.GameDetails;
|
||||||
|
import pp.battleship.message.server.ServerMessage;
|
||||||
|
import pp.battleship.message.server.StartBattleMessage;
|
||||||
import pp.battleship.model.Battleship;
|
import pp.battleship.model.Battleship;
|
||||||
import pp.battleship.model.IntPoint;
|
import pp.battleship.model.IntPoint;
|
||||||
import pp.battleship.model.Shot;
|
import pp.battleship.model.Shot;
|
||||||
@@ -38,7 +40,6 @@ public class BattleshipServer implements MessageListener<HostedConnection>, Conn
|
|||||||
private static final Logger LOGGER = System.getLogger(BattleshipServer.class.getName());
|
private static final Logger LOGGER = System.getLogger(BattleshipServer.class.getName());
|
||||||
private static final File CONFIG_FILE = new File("server.properties");
|
private static final File CONFIG_FILE = new File("server.properties");
|
||||||
|
|
||||||
private final BattleshipConfig config = new BattleshipConfig();
|
|
||||||
private Server myServer;
|
private Server myServer;
|
||||||
private final ServerGameLogic logic;
|
private final ServerGameLogic logic;
|
||||||
private final BlockingQueue<ReceivedMessage> pendingMessages = new LinkedBlockingQueue<>();
|
private final BlockingQueue<ReceivedMessage> pendingMessages = new LinkedBlockingQueue<>();
|
||||||
@@ -55,32 +56,35 @@ public class BattleshipServer implements MessageListener<HostedConnection>, Conn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the Battleships server.
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) {
|
|
||||||
new BattleshipServer().run();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the server.
|
* Creates the server.
|
||||||
*/
|
*/
|
||||||
BattleshipServer() {
|
public BattleshipServer() {
|
||||||
|
BattleshipConfig config = new BattleshipConfig();
|
||||||
config.readFromIfExists(CONFIG_FILE);
|
config.readFromIfExists(CONFIG_FILE);
|
||||||
LOGGER.log(Level.INFO, "Configuration: {0}", config); //NON-NLS
|
LOGGER.log(Level.INFO, "Configuration: {0}", config); //NON-NLS
|
||||||
logic = new ServerGameLogic(this, config);
|
logic = new ServerGameLogic(this, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
/**
|
||||||
startServer();
|
* Starts the server on the given port and continuously processes incoming messages.
|
||||||
|
* @param port the port to start the server on
|
||||||
|
*/
|
||||||
|
public void run(int port) {
|
||||||
|
startServer(port);
|
||||||
while (true)
|
while (true)
|
||||||
processNextMessage();
|
processNextMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startServer() {
|
/**
|
||||||
|
* Initializes and starts the server on the specified port, handling exceptions if the server fails to start.
|
||||||
|
* @param port the port to start the server on
|
||||||
|
*/
|
||||||
|
private void startServer(int port) {
|
||||||
try {
|
try {
|
||||||
LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS
|
LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS
|
||||||
myServer = Network.createServer(config.getPort());
|
myServer = Network.createServer(port);
|
||||||
initializeSerializables();
|
initializeSerializables();
|
||||||
myServer.start();
|
myServer.start();
|
||||||
registerListeners();
|
registerListeners();
|
||||||
@@ -92,6 +96,9 @@ private void startServer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves and processes the next message from the queue, handling interruptions during the wait.
|
||||||
|
*/
|
||||||
private void processNextMessage() {
|
private void processNextMessage() {
|
||||||
try {
|
try {
|
||||||
pendingMessages.take().process(logic);
|
pendingMessages.take().process(logic);
|
||||||
@@ -102,10 +109,10 @@ private void processNextMessage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the next message from the queue, handling interruptions during message retrieval.
|
||||||
|
*/
|
||||||
private void initializeSerializables() {
|
private void initializeSerializables() {
|
||||||
Serializer.registerClass(AnimationEndMessage.class);
|
|
||||||
Serializer.registerClass(AnimationStartMessage.class);
|
|
||||||
Serializer.registerClass(SwitchBattleState.class);
|
|
||||||
Serializer.registerClass(GameDetails.class);
|
Serializer.registerClass(GameDetails.class);
|
||||||
Serializer.registerClass(StartBattleMessage.class);
|
Serializer.registerClass(StartBattleMessage.class);
|
||||||
Serializer.registerClass(MapMessage.class);
|
Serializer.registerClass(MapMessage.class);
|
||||||
@@ -116,13 +123,20 @@ private void initializeSerializables() {
|
|||||||
Serializer.registerClass(Shot.class);
|
Serializer.registerClass(Shot.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers message and connection listeners for the server.
|
||||||
|
*/
|
||||||
private void registerListeners() {
|
private void registerListeners() {
|
||||||
myServer.addMessageListener(this, AnimationEndMessage.class);
|
|
||||||
myServer.addMessageListener(this, MapMessage.class);
|
myServer.addMessageListener(this, MapMessage.class);
|
||||||
myServer.addMessageListener(this, ShootMessage.class);
|
myServer.addMessageListener(this, ShootMessage.class);
|
||||||
myServer.addConnectionListener(this);
|
myServer.addConnectionListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles received messages, logging the source and adding client messages to the pending queue.
|
||||||
|
* @param source the connection the message was received from
|
||||||
|
* @param message the received message
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(HostedConnection source, Message message) {
|
public void messageReceived(HostedConnection source, Message message) {
|
||||||
LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS
|
LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS
|
||||||
@@ -130,12 +144,22 @@ public void messageReceived(HostedConnection source, Message message) {
|
|||||||
pendingMessages.add(new ReceivedMessage(clientMessage, source.getId()));
|
pendingMessages.add(new ReceivedMessage(clientMessage, source.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles a new connection by logging it and adding a new player to the game logic.
|
||||||
|
* @param server the server receiving the connection
|
||||||
|
* @param hostedConnection the newly added connection
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
||||||
LOGGER.log(Level.INFO, "new connection {0}", hostedConnection); //NON-NLS
|
LOGGER.log(Level.INFO, "new connection {0}", hostedConnection); //NON-NLS
|
||||||
logic.addPlayer(hostedConnection.getId());
|
logic.addPlayer(hostedConnection.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the removal of a connection by logging it, checking if it belongs to an active player, and exiting if necessary.
|
||||||
|
* @param server the server losing the connection
|
||||||
|
* @param hostedConnection the removed connection
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void connectionRemoved(Server server, HostedConnection hostedConnection) {
|
public void connectionRemoved(Server server, HostedConnection hostedConnection) {
|
||||||
LOGGER.log(Level.INFO, "connection closed: {0}", hostedConnection); //NON-NLS
|
LOGGER.log(Level.INFO, "connection closed: {0}", hostedConnection); //NON-NLS
|
||||||
@@ -148,6 +172,10 @@ public void connectionRemoved(Server server, HostedConnection hostedConnection)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes all client connections and terminates the server with the given exit value.
|
||||||
|
* @param exitValue the exit code to terminate the application with
|
||||||
|
*/
|
||||||
private void exit(int exitValue) { //NON-NLS
|
private void exit(int exitValue) { //NON-NLS
|
||||||
LOGGER.log(Level.INFO, "close request"); //NON-NLS
|
LOGGER.log(Level.INFO, "close request"); //NON-NLS
|
||||||
if (myServer != null)
|
if (myServer != null)
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
// (c) Mark Minas (mark.minas@unibw.de)
|
// (c) Mark Minas (mark.minas@unibw.de)
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
|
|
||||||
package pp.battleship.client;
|
package pp.battleship.client.server;
|
||||||
|
|
||||||
import pp.battleship.message.client.ClientInterpreter;
|
import pp.battleship.message.client.ClientInterpreter;
|
||||||
import pp.battleship.message.client.ClientMessage;
|
import pp.battleship.message.client.ClientMessage;
|
||||||
|
Before Width: | Height: | Size: 55 KiB |
|
Before Width: | Height: | Size: 55 KiB |
|
Before Width: | Height: | Size: 59 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 54 KiB |
|
Before Width: | Height: | Size: 332 KiB |
|
Before Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 51 KiB |
|
Before Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 74 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 629 KiB |
|
Before Width: | Height: | Size: 95 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 49 KiB |
|
Before Width: | Height: | Size: 122 KiB |
@@ -1,35 +0,0 @@
|
|||||||
# Blender 4.2.1 LTS MTL File: 'untitled.blend'
|
|
||||||
# www.blender.org
|
|
||||||
|
|
||||||
newmtl Bridge
|
|
||||||
Ns 250.000000
|
|
||||||
Ka 1.000000 1.000000 1.000000
|
|
||||||
Ks 0.500000 0.500000 0.500000
|
|
||||||
Ni 1.500000
|
|
||||||
illum 2
|
|
||||||
map_Kd Bridge_baseColor.png
|
|
||||||
map_Ke Bridge_emissive.jpg
|
|
||||||
map_d Bridge_baseColor.png
|
|
||||||
map_Bump -bm 1.000000 Bridge_normal.jpg
|
|
||||||
|
|
||||||
newmtl Containers
|
|
||||||
Ns 250.000000
|
|
||||||
Ka 1.000000 1.000000 1.000000
|
|
||||||
Ks 0.500000 0.500000 0.500000
|
|
||||||
Ke 0.000000 0.000000 0.000000
|
|
||||||
Ni 1.500000
|
|
||||||
d 1.000000
|
|
||||||
illum 2
|
|
||||||
map_Kd Containers_baseColor.jpg
|
|
||||||
map_Bump -bm 1.000000 Containers_normal.jpg
|
|
||||||
|
|
||||||
newmtl Hull
|
|
||||||
Ns 250.000000
|
|
||||||
Ka 1.000000 1.000000 1.000000
|
|
||||||
Ks 0.500000 0.500000 0.500000
|
|
||||||
Ke 0.000000 0.000000 0.000000
|
|
||||||
Ni 1.500000
|
|
||||||
d 1.000000
|
|
||||||
illum 2
|
|
||||||
map_Kd Hull_baseColor.jpg
|
|
||||||
map_Bump -bm 1.000000 Hull_normal.jpg
|
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
newmtl Battleship
|
||||||
|
illum 4
|
||||||
|
Kd 0.00 0.00 0.00
|
||||||
|
Ka 0.00 0.00 0.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
map_Kd BattleshipC.jpg
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.00 0.00 0.00
|
||||||
|
Ns 256.00
|
||||||
|
newmtl blinn1SG
|
||||||
|
illum 4
|
||||||
|
Kd 0.50 0.50 0.50
|
||||||
|
Ka 0.00 0.00 0.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.00 0.00 0.00
|
||||||
|
Ns 256.00
|
||||||
|
newmtl blinn2SG
|
||||||
|
illum 4
|
||||||
|
Kd 0.50 0.50 0.50
|
||||||
|
Ka 0.00 0.00 0.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.00 0.00 0.00
|
||||||
|
Ns 256.00
|
||||||
|
newmtl blinn3SG
|
||||||
|
illum 4
|
||||||
|
Kd 0.50 0.50 0.50
|
||||||
|
Ka 0.00 0.00 0.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 256.00
|
||||||
|
newmtl blinn4SG
|
||||||
|
illum 4
|
||||||
|
Kd 0.50 0.50 0.50
|
||||||
|
Ka 0.00 0.00 0.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 256.00
|
||||||
|
newmtl blinn5SG
|
||||||
|
illum 4
|
||||||
|
Kd 0.50 0.50 0.50
|
||||||
|
Ka 0.00 0.00 0.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 256.00
|
||||||
|
newmtl blinn6SG
|
||||||
|
illum 4
|
||||||
|
Kd 0.50 0.50 0.50
|
||||||
|
Ka 0.00 0.00 0.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 256.00
|
||||||
|
newmtl blinn7SG
|
||||||
|
illum 4
|
||||||
|
Kd 0.50 0.50 0.50
|
||||||
|
Ka 0.00 0.00 0.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 256.00
|
||||||
|
newmtl blinn8SG
|
||||||
|
illum 4
|
||||||
|
Kd 0.50 0.50 0.50
|
||||||
|
Ka 0.00 0.00 0.00
|
||||||
|
Tf 1.00 1.00 1.00
|
||||||
|
Ni 1.00
|
||||||
|
Ks 0.50 0.50 0.50
|
||||||
|
Ns 256.00
|
||||||
|
After Width: | Height: | Size: 360 KiB |
@@ -0,0 +1,3 @@
|
|||||||
|
based on:
|
||||||
|
https://free3d.com/3d-model/battleship-v1--611736.html
|
||||||
|
License: Free Personal Use Only
|
||||||
|
Before Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 54 KiB |
|
Before Width: | Height: | Size: 9.3 KiB |
|
Before Width: | Height: | Size: 66 KiB |
|
Before Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 9.4 KiB |
|
Before Width: | Height: | Size: 264 KiB |
|
Before Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 98 B |
|
Before Width: | Height: | Size: 79 B |
|
Before Width: | Height: | Size: 79 B |
|
Before Width: | Height: | Size: 79 B |
|
Before Width: | Height: | Size: 78 B |
|
Before Width: | Height: | Size: 78 B |
|
Before Width: | Height: | Size: 79 B |
|
Before Width: | Height: | Size: 78 B |
|
Before Width: | Height: | Size: 78 B |
|
Before Width: | Height: | Size: 78 B |
|
Before Width: | Height: | Size: 79 B |
|
Before Width: | Height: | Size: 79 B |
|
Before Width: | Height: | Size: 79 B |
|
Before Width: | Height: | Size: 78 B |
|
Before Width: | Height: | Size: 78 B |
|
Before Width: | Height: | Size: 79 B |
|
Before Width: | Height: | Size: 79 B |
|
Before Width: | Height: | Size: 79 B |
|
Before Width: | Height: | Size: 78 B |
|
Before Width: | Height: | Size: 79 B |
|
Before Width: | Height: | Size: 79 B |
|
Before Width: | Height: | Size: 78 B |
|
Before Width: | Height: | Size: 78 B |
|
Before Width: | Height: | Size: 78 B |
|
Before Width: | Height: | Size: 78 B |
|
Before Width: | Height: | Size: 79 B |
|
Before Width: | Height: | Size: 79 B |
|
Before Width: | Height: | Size: 79 B |
|
Before Width: | Height: | Size: 78 B |
|
Before Width: | Height: | Size: 78 B |
|
Before Width: | Height: | Size: 78 B |
|
Before Width: | Height: | Size: 79 B |