Add Shell
This commit is contained in:
@@ -13,13 +13,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;
|
||||
@@ -105,6 +103,9 @@ private void processNextMessage() {
|
||||
}
|
||||
|
||||
private void initializeSerializables() {
|
||||
Serializer.registerClass(AnimationEndMessage.class);
|
||||
Serializer.registerClass(AnimationStartMessage.class);
|
||||
Serializer.registerClass(SwitchBattleState.class);
|
||||
Serializer.registerClass(GameDetails.class);
|
||||
Serializer.registerClass(StartBattleMessage.class);
|
||||
Serializer.registerClass(MapMessage.class);
|
||||
@@ -116,6 +117,7 @@ private void initializeSerializables() {
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
myServer.addMessageListener(this, AnimationEndMessage.class);
|
||||
myServer.addMessageListener(this, MapMessage.class);
|
||||
myServer.addMessageListener(this, ShootMessage.class);
|
||||
myServer.addConnectionListener(this);
|
||||
|
||||
@@ -8,10 +8,13 @@
|
||||
package pp.battleship.client.gui;
|
||||
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import pp.battleship.model.Battleship;
|
||||
import pp.battleship.model.IntPoint;
|
||||
import pp.battleship.model.Shell;
|
||||
import pp.battleship.model.Shot;
|
||||
import pp.util.Position;
|
||||
|
||||
@@ -26,6 +29,10 @@ class MapViewSynchronizer extends ShipMapSynchronizer {
|
||||
private static final float SHOT_DEPTH = -2f;
|
||||
private static final float SHIP_DEPTH = 0f;
|
||||
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;
|
||||
|
||||
|
||||
// Colors used for different visual elements
|
||||
private static final ColorRGBA HIT_COLOR = ColorRGBA.Red;
|
||||
@@ -109,6 +116,29 @@ public Spatial visit(Battleship ship) {
|
||||
return shipNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a visual representation of a shell on the map.
|
||||
*
|
||||
* @param shell the Shell object representing the shell in the model
|
||||
* @return a Spatial representing the shell
|
||||
*/
|
||||
@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() + SHELL_SIZE, shell.getY() + SHELL_SIZE);
|
||||
|
||||
final Position startPosition = view.modelToView(SHELL_CENTERED_IN_MAP_GRID, SHELL_CENTERED_IN_MAP_GRID);
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a line geometry representing part of the ship's border.
|
||||
*
|
||||
|
||||
@@ -82,6 +82,22 @@ public void createHitParticles(Node node, Shot shot) {
|
||||
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));
|
||||
|
||||
@@ -91,6 +107,9 @@ public void createHitParticles(Node node, Shot shot) {
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,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;
|
||||
@@ -44,6 +41,7 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
||||
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);
|
||||
private static final String BOMB = "Models/Bomb/Files/Bomb GBU-43B(MOAB).obj";
|
||||
|
||||
private final ShipMap map;
|
||||
private final BattleshipApp app;
|
||||
@@ -66,6 +64,35 @@ public SeaSynchronizer(BattleshipApp app, Node root, ShipMap map) {
|
||||
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.
|
||||
* If the shot is a hit, it attaches the representation to the ship node.
|
||||
@@ -84,7 +111,7 @@ public Spatial visit(Shot shot) {
|
||||
* contains the ship model as a child so that it moves with the ship.
|
||||
*
|
||||
* @param shot a hit
|
||||
* @return always null to prevent the representation from being attached
|
||||
* @return always null to prevent the representation from being sattached
|
||||
* to the items node as well
|
||||
*/
|
||||
private Spatial handleHit(Shot shot) {
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 55 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 55 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
# Blender MTL File: 'untitletttd.blend'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl None
|
||||
Ns 0
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.8 0.8 0.8
|
||||
Ks 0.8 0.8 0.8
|
||||
d 1
|
||||
illum 2
|
||||
map_Kd C:\Users\Convidado.Cliente-JMF-PC\Desktop\ghftht.png
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 54 KiB |
Reference in New Issue
Block a user