|
|
@ -8,6 +8,7 @@ import com.jme3.collision.CollisionResults; |
|
|
|
import com.jme3.export.JmeExporter; |
|
|
|
import com.jme3.export.JmeExporter; |
|
|
|
import com.jme3.export.JmeImporter; |
|
|
|
import com.jme3.export.JmeImporter; |
|
|
|
import com.jme3.export.Savable; |
|
|
|
import com.jme3.export.Savable; |
|
|
|
|
|
|
|
import com.jme3.input.ChaseCamera; |
|
|
|
import com.jme3.input.KeyInput; |
|
|
|
import com.jme3.input.KeyInput; |
|
|
|
import com.jme3.input.controls.ActionListener; |
|
|
|
import com.jme3.input.controls.ActionListener; |
|
|
|
import com.jme3.input.controls.AnalogListener; |
|
|
|
import com.jme3.input.controls.AnalogListener; |
|
|
@ -27,6 +28,7 @@ import com.jme3.scene.control.Control; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import static mygame.Main.level; |
|
|
|
import static mygame.Main.level; |
|
|
|
import static mygame.Main.main; |
|
|
|
import static mygame.Main.main; |
|
|
|
|
|
|
|
import mygame.camera.CustomChaseCamera; |
|
|
|
import mygame.server.ServerMain.PlayerActionMessage; |
|
|
|
import mygame.server.ServerMain.PlayerActionMessage; |
|
|
|
import mygame.server.ServerMain.PlayerPositionMessage; |
|
|
|
import mygame.server.ServerMain.PlayerPositionMessage; |
|
|
|
import mygame.server.ServerMain.ServerMessage; |
|
|
|
import mygame.server.ServerMain.ServerMessage; |
|
|
@ -52,6 +54,11 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone |
|
|
|
PhysicsControl physics; |
|
|
|
PhysicsControl physics; |
|
|
|
Vector3f walkDirection; |
|
|
|
Vector3f walkDirection; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float lastActionPerformed = 0.0f; |
|
|
|
|
|
|
|
static final float FREECAMERATIME = 0.5f; |
|
|
|
|
|
|
|
float cameraTransition = 0.0f; |
|
|
|
|
|
|
|
float oldRotation = 0.0f; |
|
|
|
|
|
|
|
|
|
|
|
// empty serialization constructor
|
|
|
|
// empty serialization constructor
|
|
|
|
|
|
|
|
|
|
|
|
/** This method is called when the control is added to the spatial, |
|
|
|
/** This method is called when the control is added to the spatial, |
|
|
@ -87,8 +94,8 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone |
|
|
|
main.getInputManager().addMapping("StrafeLeft", new KeyTrigger(KeyInput.KEY_A)); |
|
|
|
main.getInputManager().addMapping("StrafeLeft", new KeyTrigger(KeyInput.KEY_A)); |
|
|
|
main.getInputManager().addMapping("StrafeRight", new KeyTrigger(KeyInput.KEY_D)); |
|
|
|
main.getInputManager().addMapping("StrafeRight", new KeyTrigger(KeyInput.KEY_D)); |
|
|
|
main.getInputManager().addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE)); |
|
|
|
main.getInputManager().addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE)); |
|
|
|
main.getInputManager().addListener(this, "WalkForward"); |
|
|
|
//main.getInputManager().addListener(this, "WalkForward");
|
|
|
|
main.getInputManager().addListener(this, "WalkBackward"); |
|
|
|
//main.getInputManager().addListener(this, "WalkBackward");
|
|
|
|
main.getInputManager().addListener(this, "StrafeRight"); |
|
|
|
main.getInputManager().addListener(this, "StrafeRight"); |
|
|
|
main.getInputManager().addListener(this, "StrafeLeft"); |
|
|
|
main.getInputManager().addListener(this, "StrafeLeft"); |
|
|
|
main.getInputManager().addListener(this, "Jump"); |
|
|
|
main.getInputManager().addListener(this, "Jump"); |
|
|
@ -108,7 +115,13 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone |
|
|
|
/*if (this instanceof NetworkPlayableCharacter) { |
|
|
|
/*if (this instanceof NetworkPlayableCharacter) { |
|
|
|
System.out.println("1:"+getWalkDirection()+"Moving:"+moving+"/"+strafingLeft+"/"+strafingRight+"/"+walkingBackward+"/"+walkingForward); |
|
|
|
System.out.println("1:"+getWalkDirection()+"Moving:"+moving+"/"+strafingLeft+"/"+strafingRight+"/"+walkingBackward+"/"+walkingForward); |
|
|
|
}*/ |
|
|
|
}*/ |
|
|
|
|
|
|
|
main.getCamera().setLocation(spatial.getLocalTranslation().add(-20,7f,0)); |
|
|
|
if (moving) { |
|
|
|
if (moving) { |
|
|
|
|
|
|
|
if (!(this instanceof NetworkPlayableCharacter)) { |
|
|
|
|
|
|
|
cameraTransition+=tpf*4; |
|
|
|
|
|
|
|
spatial.getControl(CustomChaseCamera.class).setHorizontalRotation(FastMath.interpolateLinear(cameraTransition, (float)(oldRotation), (float)Math.PI)); |
|
|
|
|
|
|
|
lastActionPerformed = 0.0f; |
|
|
|
|
|
|
|
} |
|
|
|
if (!channel.getAnimationName().equalsIgnoreCase("Walk")) { |
|
|
|
if (!channel.getAnimationName().equalsIgnoreCase("Walk")) { |
|
|
|
channel.setAnim("Walk"); |
|
|
|
channel.setAnim("Walk"); |
|
|
|
channel.setLoopMode(LoopMode.Loop); |
|
|
|
channel.setLoopMode(LoopMode.Loop); |
|
|
@ -132,8 +145,16 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone |
|
|
|
channel.setAnim("stand"); |
|
|
|
channel.setAnim("stand"); |
|
|
|
channel.setLoopMode(LoopMode.DontLoop); |
|
|
|
channel.setLoopMode(LoopMode.DontLoop); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (!(this instanceof NetworkPlayableCharacter)) { |
|
|
|
|
|
|
|
//System.out.println(spatial.getControl(CustomChaseCamera.class).getHorizontalRotation()+","+(spatial.getControl(CustomChaseCamera.class).getHorizontalRotation()%(2*Math.PI)));
|
|
|
|
|
|
|
|
oldRotation = spatial.getControl(CustomChaseCamera.class).getHorizontalRotation(); |
|
|
|
|
|
|
|
cameraTransition = 0.0f; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!(this instanceof NetworkPlayableCharacter)) { |
|
|
|
|
|
|
|
lastActionPerformed+=tpf; |
|
|
|
} |
|
|
|
} |
|
|
|
//isOnGround();
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void SmoothMoveWalk(Vector3f walkDirection, float tpf) { |
|
|
|
private void SmoothMoveWalk(Vector3f walkDirection, float tpf) { |
|
|
@ -174,6 +195,7 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onAction(String name, boolean isPressed, float tpf) { |
|
|
|
public void onAction(String name, boolean isPressed, float tpf) { |
|
|
|
|
|
|
|
lastActionPerformed = 0.0f; |
|
|
|
switch (name) { |
|
|
|
switch (name) { |
|
|
|
case "StrafeLeft":{ |
|
|
|
case "StrafeLeft":{ |
|
|
|
current_time = 0.0f; |
|
|
|
current_time = 0.0f; |
|
|
@ -195,7 +217,7 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone |
|
|
|
main.client.send(action); |
|
|
|
main.client.send(action); |
|
|
|
} |
|
|
|
} |
|
|
|
}break; |
|
|
|
}break; |
|
|
|
case "WalkBackward":{ |
|
|
|
/*case "WalkBackward":{ |
|
|
|
current_time = 0.0f; |
|
|
|
current_time = 0.0f; |
|
|
|
prevRot = spatial.getLocalRotation(); |
|
|
|
prevRot = spatial.getLocalRotation(); |
|
|
|
walkingBackward = isPressed; |
|
|
|
walkingBackward = isPressed; |
|
|
@ -214,7 +236,7 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone |
|
|
|
PlayerActionMessage action = new PlayerActionMessage(name,Boolean.toString(isPressed),main.client.getId(),spatial.getLocalTranslation(),spatial.getLocalRotation(),main.getCamera().getDirection(),main.getCamera().getLeft()); |
|
|
|
PlayerActionMessage action = new PlayerActionMessage(name,Boolean.toString(isPressed),main.client.getId(),spatial.getLocalTranslation(),spatial.getLocalRotation(),main.getCamera().getDirection(),main.getCamera().getLeft()); |
|
|
|
main.client.send(action); |
|
|
|
main.client.send(action); |
|
|
|
} |
|
|
|
} |
|
|
|
}break; |
|
|
|
}break;*/ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -254,22 +276,22 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone |
|
|
|
Vector3f walkDirection = new Vector3f(0,0,0); |
|
|
|
Vector3f walkDirection = new Vector3f(0,0,0); |
|
|
|
|
|
|
|
|
|
|
|
if (strafingLeft) { |
|
|
|
if (strafingLeft) { |
|
|
|
walkDirection.addLocal(camLeftDir); |
|
|
|
walkDirection.addLocal(0,0,-1); |
|
|
|
moving=true; |
|
|
|
moving=true; |
|
|
|
} |
|
|
|
} |
|
|
|
if (strafingRight) { |
|
|
|
if (strafingRight) { |
|
|
|
walkDirection.addLocal(camLeftDir.negate()); |
|
|
|
walkDirection.addLocal(0,0,1); |
|
|
|
moving=true; |
|
|
|
moving=true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (walkingForward) { |
|
|
|
/*if (walkingForward) { |
|
|
|
walkDirection.addLocal(camDir); |
|
|
|
walkDirection.addLocal(camDir); |
|
|
|
moving=true; |
|
|
|
moving=true; |
|
|
|
} |
|
|
|
} |
|
|
|
if (walkingBackward) { |
|
|
|
if (walkingBackward) { |
|
|
|
walkDirection.addLocal(camDir.negate()); |
|
|
|
walkDirection.addLocal(camDir.negate()); |
|
|
|
moving=true; |
|
|
|
moving=true; |
|
|
|
} |
|
|
|
} */ |
|
|
|
return walkDirection; |
|
|
|
return walkDirection; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |