part solution for exercise 13
added an animation state for the server and client and gave it the functionality to display a 3d model representing the shot of the other person adjusted the server to serialize the new messages for handling the animation states
This commit is contained in:
parent
da2508395c
commit
f99b91324c
@@ -12,6 +12,7 @@
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import pp.battleship.model.Battleship;
|
||||
import pp.battleship.model.Shell;
|
||||
import pp.battleship.model.Shot;
|
||||
import pp.util.Position;
|
||||
|
||||
@@ -109,6 +110,21 @@ public Spatial visit(Battleship ship) {
|
||||
return shipNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spatial visit(Shell shell) {
|
||||
final Node shellNode = new Node("shell");
|
||||
|
||||
final Position p1 = view.modelToView(shell.getX(), shell.getY());
|
||||
final Position p2 = view.modelToView(shell.getX() + 1, shell.getY() + 1);
|
||||
|
||||
final float x1 = p1.getX() + INDENT;
|
||||
final float y1 = p1.getY() + INDENT;
|
||||
final float x2 = p2.getX() - INDENT;
|
||||
final float y2 = p2.getY() - INDENT;
|
||||
|
||||
return shellNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a line geometry representing part of the ship's border.
|
||||
*
|
||||
|
||||
@@ -18,10 +18,7 @@
|
||||
import com.jme3.scene.shape.Box;
|
||||
import com.jme3.scene.shape.Cylinder;
|
||||
import pp.battleship.client.BattleshipApp;
|
||||
import pp.battleship.model.Battleship;
|
||||
import pp.battleship.model.Rotation;
|
||||
import pp.battleship.model.ShipMap;
|
||||
import pp.battleship.model.Shot;
|
||||
import pp.battleship.model.*;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static pp.util.FloatMath.HALF_PI;
|
||||
@@ -39,9 +36,11 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
private static final String UBOAT = "Models/UBoat/14084_WWII_Ship_German_Type_II_U-boat_v2_L1.obj"; //NON-NLS
|
||||
private static final String BATTLE_SHIP_MODERN = "Models/BattleShipModern/10619_Battleship.obj";
|
||||
private static final String PATROL_BOAT = "Models/PatrolBoat/12219_boat_v2_L2.obj";
|
||||
private static final String SHELL_ROCKET = "Models/Rocket/Rocket.obj";
|
||||
private static final String COLOR = "Color"; //NON-NLS
|
||||
private static final String SHIP = "ship"; //NON-NLS
|
||||
private static final String SHOT = "shot"; //NON-NLS
|
||||
private static final String SHELL = "shell";
|
||||
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 HIT_COLOR = new ColorRGBA(1f, 0f, 0f, 0.4f);
|
||||
@@ -138,6 +137,42 @@ public Spatial visit(Battleship ship) {
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a shell and creates a graphical representation
|
||||
*
|
||||
* @param shell the Shell element to visit
|
||||
* @return the node containing the graphical representation
|
||||
*/
|
||||
@Override
|
||||
public Spatial visit(Shell shell){
|
||||
final Node node = new Node(SHELL);
|
||||
node.attachChild(createRocket());
|
||||
|
||||
final float x = shell.getY();
|
||||
final float z = shell.getX();
|
||||
|
||||
node.setLocalTranslation(x + 0.5f, 10f, z + 0.5f);
|
||||
ShellControl shellControl = new ShellControl(shell, app);
|
||||
node.addControl(shellControl);
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates the spatial representation of a rocket
|
||||
*
|
||||
* @return a spatial the rocket
|
||||
*/
|
||||
private Spatial createRocket() {
|
||||
final Spatial model = app.getAssetManager().loadModel(SHELL_ROCKET);
|
||||
|
||||
model.rotate(PI, 0f, 0f);
|
||||
model.scale(0.005f);
|
||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||
model.move(0, 0, 0);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
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.lang.System.Logger;
|
||||
|
||||
public class ShellControl extends AbstractControl {
|
||||
private final Shell shell;
|
||||
private final BattleshipApp app;
|
||||
|
||||
private static final float MOVE_SPEED = 8.0f;
|
||||
|
||||
static final Logger LOGGER = System.getLogger(ShellControl.class.getName());
|
||||
|
||||
public ShellControl(Shell shell, BattleshipApp app) {
|
||||
this.shell = shell;
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void controlUpdate(float tpf) {
|
||||
spatial.move(0, -MOVE_SPEED * tpf, 0);
|
||||
//LOGGER.log(System.Logger.Level.DEBUG, "moved rocket {0}", spatial.getLocalTranslation().getY());
|
||||
if (spatial.getLocalTranslation().getY() <= 1.5){
|
||||
spatial.getParent().detachChild(spatial);
|
||||
app.getGameLogic().send(new AnimationEndMessage(new IntPoint(shell.getX(), shell.getY())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -18,13 +18,11 @@
|
||||
import pp.battleship.game.server.Player;
|
||||
import pp.battleship.game.server.ServerGameLogic;
|
||||
import pp.battleship.game.server.ServerSender;
|
||||
import pp.battleship.message.client.AnimationEndMessage;
|
||||
import pp.battleship.message.client.ClientMessage;
|
||||
import pp.battleship.message.client.MapMessage;
|
||||
import pp.battleship.message.client.ShootMessage;
|
||||
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.message.server.*;
|
||||
import pp.battleship.model.Battleship;
|
||||
import pp.battleship.model.IntPoint;
|
||||
import pp.battleship.model.Shot;
|
||||
@@ -114,11 +112,15 @@ private void initializeSerializables() {
|
||||
Serializer.registerClass(Battleship.class);
|
||||
Serializer.registerClass(IntPoint.class);
|
||||
Serializer.registerClass(Shot.class);
|
||||
Serializer.registerClass(AnimationEndMessage.class);
|
||||
Serializer.registerClass(AnimationStartMessage.class);
|
||||
Serializer.registerClass(SwitchBattleState.class);
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
myServer.addMessageListener(this, MapMessage.class);
|
||||
myServer.addMessageListener(this, ShootMessage.class);
|
||||
myServer.addMessageListener(this, AnimationEndMessage.class);
|
||||
myServer.addConnectionListener(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,250 @@
|
||||
#
|
||||
# Generated by Sweet Home 3D - ven. janv. 02 20:37:08 CET 2015
|
||||
# http://www.sweethome3d.com/
|
||||
#
|
||||
|
||||
newmtl FrontColorNoCulling
|
||||
illum 1
|
||||
Ka 0.2 0.2 0.2
|
||||
Kd 0.2 0.2 0.2
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 0.0
|
||||
|
||||
newmtl ForegroundColor
|
||||
illum 1
|
||||
Ka 0.2 0.2 0.2
|
||||
Kd 0.2 0.2 0.2
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 0.0
|
||||
|
||||
newmtl white
|
||||
illum 1
|
||||
Ka 0.48235294 0.5019608 0.5803922
|
||||
Kd 0.48235294 0.5019608 0.5803922
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 0.0
|
||||
|
||||
newmtl white_Cylinder_5
|
||||
illum 1
|
||||
Ka 0.47843137 0.49803922 0.5764706
|
||||
Kd 0.47843137 0.49803922 0.5764706
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 0.0
|
||||
|
||||
newmtl white_Cylinder_10
|
||||
illum 1
|
||||
Ka 0.8784314 0.8745098 0.8901961
|
||||
Kd 0.8784314 0.8745098 0.8901961
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 0.0
|
||||
|
||||
newmtl FrontColorNoCulling_11
|
||||
illum 1
|
||||
Ka 0.8784314 0.8745098 0.8901961
|
||||
Kd 0.8784314 0.8745098 0.8901961
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 0.0
|
||||
|
||||
newmtl ForegroundColor_12
|
||||
illum 1
|
||||
Ka 0.8784314 0.8745098 0.8901961
|
||||
Kd 0.8784314 0.8745098 0.8901961
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 0.0
|
||||
|
||||
newmtl white_Mesh_13
|
||||
illum 1
|
||||
Ka 0.6 0.6 0.6
|
||||
Kd 0.6 0.6 0.6
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 0.0
|
||||
|
||||
newmtl Cube_1_1_1
|
||||
illum 1
|
||||
Ka 0.0 0.0 0.0
|
||||
Kd 0.0 0.0 0.0
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
|
||||
newmtl Cylinder_7_7
|
||||
illum 1
|
||||
Ka 0.4 0.4 0.4
|
||||
Kd 0.4 0.4 0.4
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
|
||||
newmtl Cylinder_10_10
|
||||
illum 1
|
||||
Ka 0.8 0.4 0.0
|
||||
Kd 0.8 0.4 0.0
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
|
||||
newmtl Cylinder_11_11
|
||||
illum 2
|
||||
Ka 0.2 0.2 0.2
|
||||
Kd 0.2 0.2 0.2
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
|
||||
newmtl 12_12
|
||||
illum 1
|
||||
Ka 0.2 0.2 0.2
|
||||
Kd 0.2 0.2 0.2
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
|
||||
newmtl Cube_1_1_1_Cube_1_1_1_38
|
||||
illum 1
|
||||
Ka 0.6 0.6 0.6
|
||||
Kd 0.6 0.6 0.6
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
|
||||
newmtl white_Cylinder_58
|
||||
illum 1
|
||||
Ka 0.1882353 0.27058825 0.58431375
|
||||
Kd 0.1882353 0.27058825 0.58431375
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 0.0
|
||||
|
||||
newmtl white_Cylinder_59
|
||||
illum 1
|
||||
Ka 0.3137255 0.14901961 0.011764706
|
||||
Kd 0.3137255 0.14901961 0.011764706
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 0.0
|
||||
|
||||
newmtl 1_1
|
||||
illum 2
|
||||
Ka 0.2 0.2 0.2
|
||||
Kd 1.0 1.0 1.0
|
||||
Ks 0.5 0.5 0.5
|
||||
Ns 64.0
|
||||
Ni 1.0
|
||||
d 0.48000002
|
||||
map_Kd Missile_AIM-120_D_[AMRAAM]_1_1.png
|
||||
|
||||
newmtl Cube_1_2_2
|
||||
illum 1
|
||||
Ka 0.8 0.4 0.0
|
||||
Kd 0.8 0.4 0.0
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
|
||||
newmtl Cylinder_4_4
|
||||
illum 2
|
||||
Ka 0.6 0.6 0.6
|
||||
Kd 0.6 0.6 0.6
|
||||
Ks 0.5 0.5 0.5
|
||||
Ns 64.0
|
||||
|
||||
newmtl Cylinder_5_5
|
||||
illum 2
|
||||
Ka 0.8 0.8 0.0
|
||||
Kd 0.8 0.8 0.0
|
||||
Ks 0.5 0.5 0.5
|
||||
Ns 64.0
|
||||
|
||||
newmtl Cylinder_6_6
|
||||
illum 2
|
||||
Ka 0.8784314 0.8745098 0.8901961
|
||||
Kd 0.8784314 0.8745098 0.8901961
|
||||
Ks 0.5 0.5 0.5
|
||||
Ns 64.0
|
||||
|
||||
newmtl Cylinder_10_10_Cylinder_10_10_73
|
||||
illum 1
|
||||
Ka 0.2 0.2 0.2
|
||||
Kd 0.2 0.2 0.2
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
|
||||
newmtl 11_11
|
||||
illum 1
|
||||
Ka 0.6 0.6 0.6
|
||||
Kd 0.6 0.6 0.6
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
|
||||
newmtl Cube_1_1_1_Cube_1_1_1_76
|
||||
illum 1
|
||||
Ka 0.2 0.2 0.2
|
||||
Kd 1.0 1.0 1.0
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
Ni 1.0
|
||||
map_Kd Missile_AIM-120_D_[AMRAAM]_Cube_1_1_1_Cube_1_1_1_76.png
|
||||
|
||||
newmtl Cylinder_2_2
|
||||
illum 2
|
||||
Ka 0.6 0.6 0.6
|
||||
Kd 0.6 0.6 0.6
|
||||
Ks 0.5 0.5 0.5
|
||||
Ns 64.0
|
||||
|
||||
newmtl Cylinder_3_3
|
||||
illum 1
|
||||
Ka 0.4 0.4 0.0
|
||||
Kd 0.4 0.4 0.0
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
|
||||
newmtl Cylinder_4_4_Cylinder_4_4_79
|
||||
illum 1
|
||||
Ka 0.0 0.0 0.0
|
||||
Kd 0.0 0.0 0.0
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
|
||||
newmtl Cube_1_5_5
|
||||
illum 1
|
||||
Ka 0.2 0.2 0.2
|
||||
Kd 1.0 1.0 1.0
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
map_Kd Missile_AIM-120_D_[AMRAAM]_Cube_1_5_5.png
|
||||
|
||||
newmtl Cube_1_6_6
|
||||
illum 1
|
||||
Ka 0.2 0.2 0.2
|
||||
Kd 1.0 1.0 1.0
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
Ni 1.0
|
||||
map_Kd Missile_AIM-120_D_[AMRAAM]_Cube_1_6_6.png
|
||||
|
||||
newmtl Cylinder_1_1
|
||||
illum 1
|
||||
Ka 0.4 0.4 0.4
|
||||
Kd 0.4 0.4 0.4
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
|
||||
newmtl Cube_1_5_5_Cube_1_5_5_86
|
||||
illum 1
|
||||
Ka 0.2 0.2 0.2
|
||||
Kd 0.2 0.2 0.2
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
|
||||
newmtl Cube_1_6_6_Cube_1_6_6_87
|
||||
illum 1
|
||||
Ka 0.8 0.0 0.0
|
||||
Kd 0.8 0.0 0.0
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
|
||||
newmtl Cylinder_7_7_Cylinder_7_7_88
|
||||
illum 1
|
||||
Ka 0.8 0.4 0.0
|
||||
Kd 0.8 0.4 0.0
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
|
||||
newmtl Cylinder_8_8
|
||||
illum 1
|
||||
Ka 0.4 0.6 0.0
|
||||
Kd 0.4 0.6 0.0
|
||||
Ks 0.0 0.0 0.0
|
||||
Ns 1.0
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 210 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 164 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 289 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
22889
Projekte/battleship/client/src/main/resources/Models/Rocket/Rocket.obj
Normal file
22889
Projekte/battleship/client/src/main/resources/Models/Rocket/Rocket.obj
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Reference in New Issue
Block a user