mirror of
https://github.com/Dejvino/roadtrip
synced 2024-11-21 23:42:35 +00:00
Refactor: enabled vehicles again.
This commit is contained in:
parent
a2af1e02bb
commit
3c104a3d38
@ -36,6 +36,7 @@ import com.jme3.terrain.geomipmap.TerrainQuad;
|
|||||||
import roadtrip.model.VehicleInstance;
|
import roadtrip.model.VehicleInstance;
|
||||||
import roadtrip.view.GameWorldView;
|
import roadtrip.view.GameWorldView;
|
||||||
import roadtrip.view.VehicleNode;
|
import roadtrip.view.VehicleNode;
|
||||||
|
import roadtrip.view.model.GameWorldState;
|
||||||
import roadtrip.view.model.Player;
|
import roadtrip.view.model.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,6 +54,7 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
|
|
||||||
private BulletAppState bulletAppState;
|
private BulletAppState bulletAppState;
|
||||||
|
|
||||||
|
private GameWorldState gameWorldState;
|
||||||
private GameWorldView gameWorldView;
|
private GameWorldView gameWorldView;
|
||||||
|
|
||||||
private ChaseCamera chaseCam;
|
private ChaseCamera chaseCam;
|
||||||
@ -88,7 +90,8 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
dl.setDirection(new Vector3f(1, -1, 1));
|
dl.setDirection(new Vector3f(1, -1, 1));
|
||||||
rootNode.addLight(dl);
|
rootNode.addLight(dl);
|
||||||
|
|
||||||
gameWorldView = GameWorldView.create(assetManager, cam, rootNode);
|
gameWorldState = new GameWorldState();
|
||||||
|
gameWorldView = GameWorldView.create(gameWorldState, assetManager, cam, rootNode);
|
||||||
gameWorldView.terrain.terrainGrid.addListener(new TerrainGridListener() {
|
gameWorldView.terrain.terrainGrid.addListener(new TerrainGridListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -114,11 +117,11 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/*addCar();
|
|
||||||
addCar();
|
addCar();
|
||||||
addCar();
|
addCar();
|
||||||
addCar();
|
addCar();
|
||||||
addCar();*/
|
addCar();
|
||||||
|
addCar();
|
||||||
addPerson();
|
addPerson();
|
||||||
addPerson();
|
addPerson();
|
||||||
addPerson();
|
addPerson();
|
||||||
@ -157,10 +160,10 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
inputManager.addListener(this, "Esc");
|
inputManager.addListener(this, "Esc");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private void addCar()
|
private void addCar()
|
||||||
{
|
{
|
||||||
Node vehicleModel = new Node("VehicleModel");
|
Node vehicleModel = new Node("VehicleModel");
|
||||||
VehicleInstance vehicleInstance = VehicleInstance.createVehicle(vehicles.size() % VehicleInstance.getVehicleTypesCount());
|
VehicleInstance vehicleInstance = VehicleInstance.createVehicle(gameWorldState.vehicles.size() % VehicleInstance.getVehicleTypesCount());
|
||||||
vehicleInstance.brakeForce = vehicleInstance.accelerationForce;
|
vehicleInstance.brakeForce = vehicleInstance.accelerationForce;
|
||||||
|
|
||||||
Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
Material mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||||
@ -335,9 +338,9 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
getPhysicsSpace().add(vehicleControl);
|
getPhysicsSpace().add(vehicleControl);
|
||||||
vehicleControl.setPhysicsLocation(new Vector3f(10f + (float)Math.random() * 40f, 28f, 12f + (float)Math.random() * 40f));
|
vehicleControl.setPhysicsLocation(new Vector3f(10f + (float)Math.random() * 40f, 28f, 12f + (float)Math.random() * 40f));
|
||||||
|
|
||||||
vehicles.add(vehicle);
|
gameWorldState.vehicles.add(vehicle);
|
||||||
rootNode.attachChild(vehicle);
|
rootNode.attachChild(vehicle);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
private Node addPerson() {
|
private Node addPerson() {
|
||||||
Spatial personModel = assetManager.loadModel("Models/person.j3o");
|
Spatial personModel = assetManager.loadModel("Models/person.j3o");
|
||||||
@ -427,10 +430,8 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
public void simpleUpdate(float tpf) {
|
public void simpleUpdate(float tpf) {
|
||||||
Vector3f playerLocation = player.node.getWorldTranslation();
|
Vector3f playerLocation = player.node.getWorldTranslation();
|
||||||
Vector3f newLocation = new Vector3f(playerLocation).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.lookAt(playerLocation, Vector3f.UNIT_Y);*/
|
|
||||||
|
|
||||||
/*for (VehicleNode vehicle : gameWorldState.vehicles) {
|
for (VehicleNode vehicle : gameWorldState.vehicles) {
|
||||||
vehicle.vehicleInstance.accelerationSmooth = (vehicle.vehicleInstance.accelerationSmooth + vehicle.vehicleInstance.accelerationValue * (tpf * 10f)) / (1 + tpf * 10f);
|
vehicle.vehicleInstance.accelerationSmooth = (vehicle.vehicleInstance.accelerationSmooth + vehicle.vehicleInstance.accelerationValue * (tpf * 10f)) / (1 + tpf * 10f);
|
||||||
vehicle.engineAudio.setVelocity(new Vector3f(0, 0, 0));
|
vehicle.engineAudio.setVelocity(new Vector3f(0, 0, 0));
|
||||||
vehicle.engineAudio.updateGeometricState();
|
vehicle.engineAudio.updateGeometricState();
|
||||||
@ -466,7 +467,7 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
// TODO: pitch
|
// TODO: pitch
|
||||||
//wheelsAudio.setPitch(Math.max(0.5f, Math.min(wheelRot * 4f, 2.0f)));
|
//wheelsAudio.setPitch(Math.max(0.5f, Math.min(wheelRot * 4f, 2.0f)));
|
||||||
vehicle.wheelSlipAudio.setVolume(Math.max(0.0001f, Math.min(wheelSlip, 1.0f)) - 0.0001f);
|
vehicle.wheelSlipAudio.setVolume(Math.max(0.0001f, Math.min(wheelSlip, 1.0f)) - 0.0001f);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
listener.setLocation(cam.getLocation());
|
listener.setLocation(cam.getLocation());
|
||||||
listener.setRotation(cam.getRotation());
|
listener.setRotation(cam.getRotation());
|
||||||
@ -527,7 +528,7 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
if (value) {
|
if (value) {
|
||||||
System.out.println("Reset - to car");
|
System.out.println("Reset - to car");
|
||||||
Vector3f playerPos = player.node.getWorldTranslation();
|
Vector3f playerPos = player.node.getWorldTranslation();
|
||||||
/*for (VehicleNode vehicle : vehicles) {
|
for (VehicleNode vehicle : gameWorldState.vehicles) {
|
||||||
Vector3f vehiclePos = vehicle.getWorldTranslation();
|
Vector3f vehiclePos = vehicle.getWorldTranslation();
|
||||||
float dist = playerPos.distance(vehiclePos);
|
float dist = playerPos.distance(vehiclePos);
|
||||||
System.out.println(" .. dist: " + dist);
|
System.out.println(" .. dist: " + dist);
|
||||||
@ -544,11 +545,11 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
player.walkDir = new Vector3f();
|
player.walkDir = new Vector3f();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/*VehicleInstance playerVehicle = player.vehicleNode.vehicleInstance;
|
VehicleInstance playerVehicle = player.vehicleNode.vehicleInstance;
|
||||||
VehicleControl playerVehicleControl = player.vehicleNode.vehicleControl;
|
VehicleControl playerVehicleControl = player.vehicleNode.vehicleControl;
|
||||||
int playerCarType = playerVehicle.carType;
|
int playerCarType = playerVehicle.carType;
|
||||||
float steerMax = 0.5f;
|
float steerMax = 0.5f;
|
||||||
@ -617,7 +618,7 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
|
|||||||
player.walkDir = new Vector3f();
|
player.walkDir = new Vector3f();
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
if (binding.equals("Esc")) {
|
if (binding.equals("Esc")) {
|
||||||
stop();
|
stop();
|
||||||
|
@ -8,20 +8,20 @@ package roadtrip.model;
|
|||||||
*/
|
*/
|
||||||
public class VehicleInstance
|
public class VehicleInstance
|
||||||
{
|
{
|
||||||
final static int WEAK = 1;
|
public static final int WEAK = 1;
|
||||||
final static int TRUCK = 2;
|
public static final int TRUCK = 2;
|
||||||
final static int SPORT = 3;
|
public static final int SPORT = 3;
|
||||||
|
|
||||||
static int getVehicleTypesCount() {
|
public static int getVehicleTypesCount() {
|
||||||
return SPORT;
|
return SPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int carType;
|
public int carType;
|
||||||
float accelerationForce = 200.0f;
|
public float accelerationForce = 200.0f;
|
||||||
float brakeForce = 100.0f;
|
public float brakeForce = 100.0f;
|
||||||
float steeringValue = 0;
|
public float steeringValue = 0;
|
||||||
float accelerationValue = 0;
|
public float accelerationValue = 0;
|
||||||
float accelerationSmooth = 0;
|
public float accelerationSmooth = 0;
|
||||||
|
|
||||||
VehicleInstance(int carType, float accelerationForce, float brakeForce)
|
VehicleInstance(int carType, float accelerationForce, float brakeForce)
|
||||||
{
|
{
|
||||||
@ -54,7 +54,7 @@ public class VehicleInstance
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static VehicleInstance createVehicle(int i) {
|
public static VehicleInstance createVehicle(int i) {
|
||||||
switch (i + 1) {
|
switch (i + 1) {
|
||||||
case WEAK: return new WeakVehicle();
|
case WEAK: return new WeakVehicle();
|
||||||
case TRUCK: return new TruckVehicle();
|
case TRUCK: return new TruckVehicle();
|
||||||
|
@ -27,7 +27,7 @@ import roadtrip.view.model.GameWorldState;
|
|||||||
*/
|
*/
|
||||||
public class GameWorldView {
|
public class GameWorldView {
|
||||||
|
|
||||||
private GameWorldState state = new GameWorldState();
|
private GameWorldState state;
|
||||||
|
|
||||||
private AssetManager assetManager;
|
private AssetManager assetManager;
|
||||||
private Camera camera;
|
private Camera camera;
|
||||||
@ -35,11 +35,15 @@ public class GameWorldView {
|
|||||||
|
|
||||||
public TerrainView terrain = new TerrainView(new TerrainDataProvider());
|
public TerrainView terrain = new TerrainView(new TerrainDataProvider());
|
||||||
|
|
||||||
public static GameWorldView create(AssetManager assetManager, Camera camera, Node rootNode) {
|
public GameWorldView(GameWorldState gameWorldState, AssetManager assetManager, Camera camera, Node rootNode) {
|
||||||
GameWorldView gameWorldView = new GameWorldView();
|
this.state = gameWorldState;
|
||||||
gameWorldView.assetManager = assetManager;
|
this.assetManager = assetManager;
|
||||||
gameWorldView.camera = camera;
|
this.camera = camera;
|
||||||
gameWorldView.rootNode = rootNode;
|
this.rootNode = rootNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GameWorldView create(GameWorldState gameWorldState, AssetManager assetManager, Camera camera, Node rootNode) {
|
||||||
|
GameWorldView gameWorldView = new GameWorldView(gameWorldState, assetManager, camera, rootNode);
|
||||||
gameWorldView.initialize();
|
gameWorldView.initialize();
|
||||||
return gameWorldView;
|
return gameWorldView;
|
||||||
}
|
}
|
||||||
|
@ -14,15 +14,15 @@ import roadtrip.model.VehicleInstance;
|
|||||||
*/
|
*/
|
||||||
public class VehicleNode extends Node
|
public class VehicleNode extends Node
|
||||||
{
|
{
|
||||||
VehicleInstance vehicleInstance;
|
public VehicleInstance vehicleInstance;
|
||||||
|
|
||||||
VehicleControl vehicleControl;
|
public VehicleControl vehicleControl;
|
||||||
|
|
||||||
Spatial vehicleModel;
|
public Spatial vehicleModel;
|
||||||
|
|
||||||
AudioNode engineAudio;
|
public AudioNode engineAudio;
|
||||||
AudioNode wheelsAudio;
|
public AudioNode wheelsAudio;
|
||||||
AudioNode wheelSlipAudio;
|
public AudioNode wheelSlipAudio;
|
||||||
|
|
||||||
public VehicleNode(String name, VehicleInstance vehicleInstance,
|
public VehicleNode(String name, VehicleInstance vehicleInstance,
|
||||||
VehicleControl vehicleControl, Spatial vehicleModel)
|
VehicleControl vehicleControl, Spatial vehicleModel)
|
||||||
|
@ -9,5 +9,5 @@ import java.util.List;
|
|||||||
* Created by dejvino on 14.01.2017.
|
* Created by dejvino on 14.01.2017.
|
||||||
*/
|
*/
|
||||||
public class GameWorldState {
|
public class GameWorldState {
|
||||||
private List<VehicleNode> vehicles = new LinkedList<>();
|
public List<VehicleNode> vehicles = new LinkedList<>();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user