mirror of
https://github.com/Dejvino/roadtrip
synced 2024-11-14 04:57:28 +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,88 +230,122 @@ 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) {
|
||||||
float steerMax = 0.5f;
|
if (carType == FOOT) {
|
||||||
if (carType == TRUCK) {
|
float walkSpeed = 3f;
|
||||||
steerMax = 0.7f;
|
if (binding.equals("Lefts")) {
|
||||||
}
|
if (value) {
|
||||||
if (binding.equals("Lefts")) {
|
walkDir.x -= walkSpeed;
|
||||||
if (value) {
|
} else {
|
||||||
steeringValue += steerMax;
|
walkDir.x += walkSpeed;
|
||||||
} else {
|
}
|
||||||
steeringValue += -steerMax;
|
} 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
vehicle.steer(steeringValue);
|
playerPersonControl.setWalkDirection(walkDir);
|
||||||
} else if (binding.equals("Rights")) {
|
playerPersonControl.setViewDirection(walkDir);
|
||||||
if (value) {
|
} else {
|
||||||
steeringValue += -steerMax;
|
float steerMax = 0.5f;
|
||||||
} else {
|
|
||||||
steeringValue += steerMax;
|
|
||||||
}
|
|
||||||
vehicle.steer(steeringValue);
|
|
||||||
} else if (binding.equals("Ups")) {
|
|
||||||
if (value) {
|
|
||||||
accelerationValue += accelerationForce;
|
|
||||||
} else {
|
|
||||||
accelerationValue -= accelerationForce;
|
|
||||||
}
|
|
||||||
vehicle.accelerate(2, accelerationValue);
|
|
||||||
vehicle.accelerate(3, accelerationValue);
|
|
||||||
if (carType == TRUCK) {
|
if (carType == TRUCK) {
|
||||||
vehicle.accelerate(4, accelerationValue);
|
steerMax = 0.7f;
|
||||||
vehicle.accelerate(5, accelerationValue);
|
|
||||||
}
|
}
|
||||||
} else if (binding.equals("Downs")) {
|
if (binding.equals("Lefts")) {
|
||||||
float b;
|
if (value) {
|
||||||
if (value) {
|
steeringValue += steerMax;
|
||||||
b = brakeForce;
|
} else {
|
||||||
} else {
|
steeringValue += -steerMax;
|
||||||
b = 0f;
|
}
|
||||||
}
|
vehicle.steer(steeringValue);
|
||||||
vehicle.brake(0, b);
|
} else if (binding.equals("Rights")) {
|
||||||
vehicle.brake(1, b);
|
if (value) {
|
||||||
} else if (binding.equals("Revs")) {
|
steeringValue += -steerMax;
|
||||||
if (value) {
|
} else {
|
||||||
accelerationValue += accelerationForce;
|
steeringValue += steerMax;
|
||||||
} else {
|
}
|
||||||
accelerationValue -= accelerationForce;
|
vehicle.steer(steeringValue);
|
||||||
}
|
} else if (binding.equals("Ups")) {
|
||||||
vehicle.accelerate(2, -accelerationValue);
|
if (value) {
|
||||||
vehicle.accelerate(3, -accelerationValue);
|
accelerationValue += accelerationForce;
|
||||||
if (carType == TRUCK) {
|
} else {
|
||||||
vehicle.accelerate(4, -accelerationValue);
|
accelerationValue -= accelerationForce;
|
||||||
vehicle.accelerate(5, -accelerationValue);
|
}
|
||||||
}
|
vehicle.accelerate(2, accelerationValue);
|
||||||
} else if (binding.equals("Space")) {
|
vehicle.accelerate(3, accelerationValue);
|
||||||
if (value) {
|
if (carType == TRUCK) {
|
||||||
vehicle.applyImpulse(jumpForce, Vector3f.ZERO);
|
vehicle.accelerate(4, accelerationValue);
|
||||||
}
|
vehicle.accelerate(5, accelerationValue);
|
||||||
} else if (binding.equals("Reset")) {
|
}
|
||||||
if (value) {
|
} else if (binding.equals("Downs")) {
|
||||||
System.out.println("Reset");
|
float b;
|
||||||
vehicle.setPhysicsLocation(Vector3f.ZERO);
|
if (value) {
|
||||||
vehicle.setPhysicsRotation(new Matrix3f());
|
b = brakeForce;
|
||||||
vehicle.setLinearVelocity(Vector3f.ZERO);
|
} else {
|
||||||
vehicle.setAngularVelocity(Vector3f.ZERO);
|
b = 0f;
|
||||||
vehicle.resetSuspension();
|
}
|
||||||
} else {
|
vehicle.brake(0, b);
|
||||||
|
vehicle.brake(1, b);
|
||||||
|
} else if (binding.equals("Revs")) {
|
||||||
|
if (value) {
|
||||||
|
accelerationValue += accelerationForce;
|
||||||
|
} else {
|
||||||
|
accelerationValue -= accelerationForce;
|
||||||
|
}
|
||||||
|
vehicle.accelerate(2, -accelerationValue);
|
||||||
|
vehicle.accelerate(3, -accelerationValue);
|
||||||
|
if (carType == TRUCK) {
|
||||||
|
vehicle.accelerate(4, -accelerationValue);
|
||||||
|
vehicle.accelerate(5, -accelerationValue);
|
||||||
|
}
|
||||||
|
} else if (binding.equals("Space")) {
|
||||||
|
if (value) {
|
||||||
|
vehicle.applyImpulse(jumpForce, Vector3f.ZERO);
|
||||||
|
}
|
||||||
|
} else if (binding.equals("Reset")) {
|
||||||
|
if (value) {
|
||||||
|
System.out.println("Reset");
|
||||||
|
vehicle.setPhysicsLocation(Vector3f.ZERO);
|
||||||
|
vehicle.setPhysicsRotation(new Matrix3f());
|
||||||
|
vehicle.setLinearVelocity(Vector3f.ZERO);
|
||||||
|
vehicle.setAngularVelocity(Vector3f.ZERO);
|
||||||
|
vehicle.resetSuspension();
|
||||||
|
} else {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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