Skip to content

Commit

Permalink
Big update. Now adding some StaticNpc to the game.
Browse files Browse the repository at this point in the history
  • Loading branch information
WASDi committed Mar 8, 2012
1 parent f4c5789 commit d4c08f7
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 22 deletions.
4 changes: 1 addition & 3 deletions src/mygame/ResourceLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
import com.jme3.post.filters.DepthOfFieldFilter;
import com.jme3.post.filters.LightScatteringFilter;
import com.jme3.renderer.Camera;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.terrain.geomipmap.TerrainLodControl;
import com.jme3.terrain.geomipmap.TerrainQuad;
import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;
Expand Down Expand Up @@ -108,7 +106,7 @@ public Spatial getPlayerModel(){
}

public void resetPlayerTranslations(){
playerModel.setLocalTranslation(0, -1.95f, -1.6f); //centers the player model
playerModel.setLocalTranslation(0, -2f, -1.6f); //centers the player model
playerModel.setLocalScale(.5f); //fixes the scale
}

Expand Down
5 changes: 4 additions & 1 deletion src/mygame/controls/PlayerControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ public void onAction(String name, boolean isPressed, float tpf) {
return;
}
if(isPressed && name.equals("debug")){
System.out.println(getPhysicsLocation().y);
System.out.printf("addSandGuy(%.1ff, %.1ff, %.1ff, %.5ff, %.5ff);\n",
getPhysicsLocation().x, getPhysicsLocation().y, getPhysicsLocation().z,
getViewDirection().x, getViewDirection().z);
// System.out.println(getViewDirection());
return;
}
if(isPressed && name.equals("EE")){
Expand Down
7 changes: 7 additions & 0 deletions src/mygame/npc/Npc.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ public interface Npc {
* @return Where the Npc is located in the 3D space
*/
public Vector3f getPosition();

public void setPosition(float x, float y, float z);

/**
* Looks at a direction
*/
public void lookAt(float xlook, float zlook);

/**
* Called when the player has targeted the Npc
* @param arrow The spatial to be attached to the Npc
Expand Down
13 changes: 6 additions & 7 deletions src/mygame/npc/NpcManager.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package mygame.npc;

import com.jme3.asset.AssetManager;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
Expand Down Expand Up @@ -30,17 +28,18 @@ public NpcManager(AssetManager assetManager, ResourceLoader loader) {
this.loader = loader;
}

public Node createSandGuy(float x, float y, float z){
public Node createSandGuy(float x, float y, float z, float xlook, float zlook){
Spatial model = loader.getSandGuyModel();
model.setLocalRotation(new Quaternion().fromAngles(0, FastMath.HALF_PI, 0)); //fix the rotation
model.setLocalTranslation(0, -2.8f, 0); //centers the model
// model.setLocalRotation(new Quaternion().fromAngles(0, FastMath.HALF_PI, 0)); //fix the rotation
model.setLocalTranslation(0, -2.1f, 0); //centers the model
Node node = new Node("SandGuyNode");
node.attachChild(model);

NpcPhysics control = new NpcPhysics(1.3f, 2.9f, node);
StaticNpc control = new StaticNpc(node);
npcList.add(control);
node.addControl(control);
control.setPhysicsLocation(new Vector3f(x, y, z));
control.setPosition(x,y,z);
control.lookAt(xlook, zlook);
return node;
}

Expand Down
12 changes: 10 additions & 2 deletions src/mygame/npc/NpcPhysics.java → src/mygame/npc/PhysicNpc.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
*
* @author wasd
*/
public class NpcPhysics extends CharacterControl implements Npc{
public class PhysicNpc extends CharacterControl implements Npc{

private Node node;
private Vector3f arrowTranslation;

public NpcPhysics(float sizex, float sizey, Node node) {
public PhysicNpc(float sizex, float sizey, Node node) {
super(new CapsuleCollisionShape(sizex, sizey), .1f);
this.node = node;
arrowTranslation = new Vector3f(0, sizey+1f, 0);
Expand All @@ -33,5 +33,13 @@ public void onTargeted(Spatial arrow) {
arrow.setLocalTranslation(arrowTranslation);
node.attachChild(arrow);
}

public void setPosition(float x, float y, float z) {
setPhysicsLocation(new Vector3f(x, y, z));
}

public void lookAt(float xlook, float zlook) {
setViewDirection(getPosition().add(xlook, 0, zlook));
}

}
17 changes: 13 additions & 4 deletions src/mygame/npc/NpcRegular.java → src/mygame/npc/StaticNpc.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
*
* @author wasd
*/
public class NpcRegular extends AbstractControl implements Npc{
public class StaticNpc extends AbstractControl implements Npc{

private Node node;

public NpcRegular(Node node) {
public StaticNpc(Node node) {
this.node=node;
}

Expand All @@ -38,12 +38,21 @@ public Control cloneForSpatial(Spatial spatial) {
}

public Vector3f getPosition() {
return spatial.getLocalTranslation();
return node.getLocalTranslation();
}

public void onTargeted(Spatial arrow) {
//TODO set translation of arrow.
//TODO set translation of arrow based on npc size.
arrow.setLocalTranslation(0, 4, 0);
node.attachChild(arrow);
}

public void setPosition(float x, float y, float z) {
node.setLocalTranslation(x, y, z);
}

public void lookAt(float xlook, float zlook) {
node.lookAt(getPosition().add(xlook, 0, zlook), Vector3f.UNIT_Y);
}

}
10 changes: 5 additions & 5 deletions src/mygame/states/InGameAppState.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ public Void call() throws Exception {
protected void finishedIntroCinematic(){
initPlayerControl();

addSandGuy(315, 5f, 240);
addSandGuy(315, 5f, 230);
addSandGuy(245.6f, -0.4f, 388.2f, -0.00041f, -0.00194f);
addSandGuy(232.7f, 0.5f, 381.6f, 0.00014f, -0.00029f);
addSandGuy(226.8f, 0.6f, 368.0f, 0.00174f, -0.00096f);

Spatial ship = app.getResourceLoader().getShipModel();
ship.setLocalTranslation(325, -4.5f, 240);
Expand All @@ -125,10 +126,9 @@ protected void finishedIntroCinematic(){
// bulletAppState.getPhysicsSpace().enableDebug(app.getAssetManager());
}

private void addSandGuy(float x, float y, float z){
Node n = npcManager.createSandGuy(x, y, z);
private void addSandGuy(float x, float y, float z, float xlook, float zlook){
Node n = npcManager.createSandGuy(x, y, z, xlook, zlook);
stateNode.attachChild(n);
bulletAppState.getPhysicsSpace().add(n.getControl(CharacterControl.class));
}

}

0 comments on commit d4c08f7

Please sign in to comment.