mirror of
https://github.com/Dejvino/roadtrip
synced 2024-11-22 07:52:36 +00:00
Added player as a person walking around.
This commit is contained in:
parent
4f7dc30897
commit
8049608ac3
20
README.md
20
README.md
@ -11,9 +11,23 @@ A game about a journey involving vehicles and obstacles.
|
|||||||
* Hilly ground
|
* Hilly ground
|
||||||
* Collidable objects - static and dynamic
|
* Collidable objects - static and dynamic
|
||||||
* People
|
* People
|
||||||
* Walking around - NPCs
|
* Walking around (Player & NPCs)
|
||||||
|
|
||||||
### TODO
|
### TODO
|
||||||
* Orbit camera
|
|
||||||
* Walking around - Player
|
|
||||||
* Enter / Exit a car
|
* Enter / Exit a car
|
||||||
|
* Sounds - car engine
|
||||||
|
* Sounds - crashes
|
||||||
|
* Sounds - wheels
|
||||||
|
* Target location (winning condition)
|
||||||
|
* Main menu
|
||||||
|
* Health indicator
|
||||||
|
* NPC AI
|
||||||
|
* Enemy NPCs - punching, shooting
|
||||||
|
* Car models
|
||||||
|
* Scenery models
|
||||||
|
* Bigger map
|
||||||
|
* Map transitions
|
||||||
|
* Roadblocks
|
||||||
|
* FPS camera
|
||||||
|
* Orbit camera
|
||||||
|
|
||||||
|
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
Before Width: | Height: | Size: 912 KiB After Width: | Height: | Size: 904 KiB |
@ -32,8 +32,9 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
final int WEAK = 1;
|
final int WEAK = 1;
|
||||||
final int TRUCK = 2;
|
final int TRUCK = 2;
|
||||||
final int SPORT = 3;
|
final int SPORT = 3;
|
||||||
|
final int FOOT = 4;
|
||||||
|
|
||||||
final int carType = SPORT;
|
final int carType = FOOT;
|
||||||
|
|
||||||
private BulletAppState bulletAppState;
|
private BulletAppState bulletAppState;
|
||||||
private VehicleControl vehicle;
|
private VehicleControl vehicle;
|
||||||
@ -42,14 +43,18 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
private float steeringValue = 0;
|
private float steeringValue = 0;
|
||||||
private float accelerationValue = 0;
|
private float accelerationValue = 0;
|
||||||
private Vector3f jumpForce = new Vector3f(0, 3000, 0);
|
private Vector3f jumpForce = new Vector3f(0, 3000, 0);
|
||||||
|
private Vector3f walkDir = new Vector3f();
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
RoadTrip app = new RoadTrip();
|
RoadTrip app = new RoadTrip();
|
||||||
app.start();
|
app.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Node playerNode;
|
||||||
|
|
||||||
Spatial map;
|
Spatial map;
|
||||||
Spatial car;
|
Spatial car;
|
||||||
|
private BetterCharacterControl playerPersonControl;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
@ -58,13 +63,16 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
if (DEBUG) bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
if (DEBUG) bulletAppState.getPhysicsSpace().enableDebug(assetManager);
|
||||||
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
|
PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
|
||||||
setupKeys();
|
setupKeys();
|
||||||
buildPlayer();
|
|
||||||
|
|
||||||
map = assetManager.loadModel("Scenes/TestMap.j3o");
|
map = assetManager.loadModel("Scenes/TestMap.j3o");
|
||||||
rootNode.attachChild(map);
|
rootNode.attachChild(map);
|
||||||
getPhysicsSpace().addAll(map);
|
getPhysicsSpace().addAll(map);
|
||||||
|
|
||||||
vehicle.setPhysicsLocation(new Vector3f(5f, 30f, 5f));
|
if (carType == FOOT) {
|
||||||
|
addPlayerPerson();
|
||||||
|
} else {
|
||||||
|
addPlayerCar();
|
||||||
|
}
|
||||||
|
|
||||||
addPerson();
|
addPerson();
|
||||||
addPerson();
|
addPerson();
|
||||||
@ -94,7 +102,7 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
inputManager.addListener(this, "Reset");
|
inputManager.addListener(this, "Reset");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildPlayer() {
|
private void addPlayerCar() {
|
||||||
Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||||
mat.getAdditionalRenderState().setWireframe(true);
|
mat.getAdditionalRenderState().setWireframe(true);
|
||||||
mat.setColor("Color", ColorRGBA.Black);
|
mat.setColor("Color", ColorRGBA.Black);
|
||||||
@ -222,19 +230,52 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
} else if (carType == SPORT) {
|
} else if (carType == SPORT) {
|
||||||
accelerationForce = 20000f;
|
accelerationForce = 20000f;
|
||||||
brakeForce = 200f;
|
brakeForce = 200f;
|
||||||
|
|
||||||
}
|
}
|
||||||
mat.getAdditionalRenderState().setWireframe(false);
|
vehicle.setPhysicsLocation(new Vector3f(5f, 30f, 5f));
|
||||||
|
|
||||||
|
playerNode = vehicleNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleUpdate(float tpf) {
|
public void simpleUpdate(float tpf) {
|
||||||
Vector3f vehicleLocation = vehicle.getPhysicsLocation();
|
Vector3f playerLocation = playerNode.getLocalTranslation();
|
||||||
Vector3f newLocation = new Vector3f(vehicleLocation).add(new Vector3f(-1f, 1.5f, 2.4f).mult(20f));
|
Vector3f newLocation = new Vector3f(playerLocation).add(new Vector3f(-1f, 1.5f, 2.4f).mult(20f));
|
||||||
cam.setLocation(new Vector3f(cam.getLocation()).interpolate(newLocation, Math.min(tpf, 1f)));
|
cam.setLocation(new Vector3f(cam.getLocation()).interpolate(newLocation, Math.min(tpf, 1f)));
|
||||||
cam.lookAt(vehicleLocation, Vector3f.UNIT_Y);
|
cam.lookAt(playerLocation, Vector3f.UNIT_Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onAction(String binding, boolean value, float tpf) {
|
public void onAction(String binding, boolean value, float tpf) {
|
||||||
|
if (carType == FOOT) {
|
||||||
|
float walkSpeed = 3f;
|
||||||
|
if (binding.equals("Lefts")) {
|
||||||
|
if (value) {
|
||||||
|
walkDir.x -= walkSpeed;
|
||||||
|
} else {
|
||||||
|
walkDir.x += walkSpeed;
|
||||||
|
}
|
||||||
|
} else if (binding.equals("Rights")) {
|
||||||
|
if (value) {
|
||||||
|
walkDir.x += walkSpeed;
|
||||||
|
} else {
|
||||||
|
walkDir.x -= walkSpeed;
|
||||||
|
}
|
||||||
|
} else if (binding.equals("Ups")) {
|
||||||
|
if (value) {
|
||||||
|
walkDir.z -= walkSpeed;
|
||||||
|
} else {
|
||||||
|
walkDir.z += walkSpeed;
|
||||||
|
}
|
||||||
|
} else if (binding.equals("Downs")) {
|
||||||
|
if (value) {
|
||||||
|
walkDir.z += walkSpeed;
|
||||||
|
} else {
|
||||||
|
walkDir.z -= walkSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
playerPersonControl.setWalkDirection(walkDir);
|
||||||
|
playerPersonControl.setViewDirection(walkDir);
|
||||||
|
} else {
|
||||||
float steerMax = 0.5f;
|
float steerMax = 0.5f;
|
||||||
if (carType == TRUCK) {
|
if (carType == TRUCK) {
|
||||||
steerMax = 0.7f;
|
steerMax = 0.7f;
|
||||||
@ -302,8 +343,9 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void addPerson() {
|
private Node addPerson() {
|
||||||
Spatial personModel = assetManager.loadModel("Models/person.j3o");
|
Spatial personModel = assetManager.loadModel("Models/person.j3o");
|
||||||
Node person = new Node("person");
|
Node person = new Node("person");
|
||||||
person.attachChild(personModel);
|
person.attachChild(personModel);
|
||||||
@ -322,5 +364,13 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
Vector3f dir = new Vector3f((float)Math.random() * 2f - 1f, 0f, (float)Math.random() * 2f - 1f);
|
Vector3f dir = new Vector3f((float)Math.random() * 2f - 1f, 0f, (float)Math.random() * 2f - 1f);
|
||||||
personControl.setViewDirection(dir);
|
personControl.setViewDirection(dir);
|
||||||
personControl.setWalkDirection(dir);
|
personControl.setWalkDirection(dir);
|
||||||
|
|
||||||
|
return person;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addPlayerPerson()
|
||||||
|
{
|
||||||
|
playerNode = addPerson();
|
||||||
|
playerPersonControl = playerNode.getControl(BetterCharacterControl.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user