mirror of
https://github.com/Dejvino/roadtrip
synced 2024-11-14 04:57:28 +00:00
UI: Enabled menu on ESC, Exit works.
This commit is contained in:
parent
48d2e1ea56
commit
255931a1aa
@ -63,6 +63,8 @@ public class RoadTrip extends GameApplication implements ActionListener {
|
|||||||
float inputTurning;
|
float inputTurning;
|
||||||
float inputAccel;
|
float inputAccel;
|
||||||
|
|
||||||
|
String[] menuEntries = { "New Game", "Load Game", "Settings", "Credits", "Exit" };
|
||||||
|
int menuEntryIndex = 0;
|
||||||
BitmapText uiText;
|
BitmapText uiText;
|
||||||
Node menuBook;
|
Node menuBook;
|
||||||
|
|
||||||
@ -139,14 +141,8 @@ public class RoadTrip extends GameApplication implements ActionListener {
|
|||||||
uiText.setAlignment(BitmapFont.Align.Left);
|
uiText.setAlignment(BitmapFont.Align.Left);
|
||||||
uiText.setQueueBucket(RenderQueue.Bucket.Transparent);
|
uiText.setQueueBucket(RenderQueue.Bucket.Transparent);
|
||||||
uiText.setSize(1.0f);
|
uiText.setSize(1.0f);
|
||||||
uiText.setText("~~~~~~~~~~~~~~~~~~~~\n Road Trip \n~~~~~~~~~~~~~~~~~~~~\n"
|
uiText.setText(getMenuText());
|
||||||
+ " New Game \n"
|
|
||||||
+ "$Load Game$\n"
|
|
||||||
+ " Settings \n"
|
|
||||||
+ " Credits \n"
|
|
||||||
+ " Exit\n");
|
|
||||||
menuBook.attachChild(uiText);
|
menuBook.attachChild(uiText);
|
||||||
rootNode.attachChild(menuBook);
|
|
||||||
|
|
||||||
chaseCam = new ChaseCamera(cam, player.node, inputManager);
|
chaseCam = new ChaseCamera(cam, player.node, inputManager);
|
||||||
chaseCam.setDefaultDistance(60f);
|
chaseCam.setDefaultDistance(60f);
|
||||||
@ -515,133 +511,207 @@ public class RoadTrip extends GameApplication implements ActionListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAction(String binding, boolean value, float tpf) {
|
public void onAction(String binding, boolean value, float tpf) {
|
||||||
if (player.vehicleNode == null) {
|
if (gamePaused) {
|
||||||
float walkSpeed = 1f;
|
|
||||||
float turnSpeed = 1f;
|
|
||||||
if (binding.equals("Lefts")) {
|
if (binding.equals("Lefts")) {
|
||||||
if (value) {
|
// meh
|
||||||
inputTurning += turnSpeed;
|
|
||||||
} else {
|
|
||||||
inputTurning -= turnSpeed;
|
|
||||||
}
|
|
||||||
} else if (binding.equals("Rights")) {
|
} else if (binding.equals("Rights")) {
|
||||||
if (value) {
|
// meh
|
||||||
inputTurning -= turnSpeed;
|
|
||||||
} else {
|
|
||||||
inputTurning += turnSpeed;
|
|
||||||
}
|
|
||||||
} else if (binding.equals("Ups")) {
|
} else if (binding.equals("Ups")) {
|
||||||
if (value) {
|
if (value) {
|
||||||
inputAccel += walkSpeed;
|
menuEntryIndex = (menuEntryIndex - 1 + menuEntries.length) % menuEntries.length;
|
||||||
} else {
|
uiText.setText(getMenuText());
|
||||||
inputAccel -= walkSpeed;
|
|
||||||
}
|
}
|
||||||
} else if (binding.equals("Downs")) {
|
} else if (binding.equals("Downs")) {
|
||||||
if (value) {
|
if (value) {
|
||||||
inputAccel -= walkSpeed;
|
menuEntryIndex = (menuEntryIndex + 1) % menuEntries.length;
|
||||||
} else {
|
uiText.setText(getMenuText());
|
||||||
inputAccel += walkSpeed;
|
|
||||||
}
|
}
|
||||||
} else if (binding.equals("Reset")) {
|
} else if (binding.equals("Reset")) {
|
||||||
if (value) {
|
if (value) {
|
||||||
System.out.println("Reset - to car");
|
switch (menuEntryIndex) {
|
||||||
Vector3f playerPos = player.node.getWorldTranslation();
|
case 0: // New
|
||||||
for (VehicleNode vehicle : gameWorldState.vehicles) {
|
|
||||||
Vector3f vehiclePos = vehicle.getWorldTranslation();
|
|
||||||
float dist = playerPos.distance(vehiclePos);
|
|
||||||
System.out.println(" .. dist: " + dist);
|
|
||||||
if (dist < 5f) {
|
|
||||||
player.vehicleNode = vehicle;
|
|
||||||
player.node.removeFromParent();
|
|
||||||
player.node.setLocalTranslation(0f, 0f, -1f);
|
|
||||||
player.node.setLocalRotation(Quaternion.DIRECTION_Z);
|
|
||||||
player.node.removeControl(player.characterControl);
|
|
||||||
player.vehicleNode.attachChild(player.node);
|
|
||||||
VehicleInstance playerVehicle = player.vehicleNode.vehicleInstance;
|
|
||||||
playerVehicle.accelerationValue = 0;
|
|
||||||
playerVehicle.steeringValue = 0;
|
|
||||||
player.walkDir = new Vector3f();
|
|
||||||
break;
|
break;
|
||||||
}
|
case 1: // Load
|
||||||
|
break;
|
||||||
|
case 2: // Settings
|
||||||
|
break;
|
||||||
|
case 3: // Credits
|
||||||
|
break;
|
||||||
|
case 4: // Exit
|
||||||
|
stop();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Unrecognized menu entry: " + menuEntryIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (binding.equals("Esc")) {
|
||||||
|
// TODO: hide menu
|
||||||
|
if (value) {
|
||||||
|
setGamePaused(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
VehicleInstance playerVehicle = player.vehicleNode.vehicleInstance;
|
if (player.vehicleNode == null) {
|
||||||
VehicleControl playerVehicleControl = player.vehicleNode.vehicleControl;
|
float walkSpeed = 1f;
|
||||||
int playerCarType = playerVehicle.carType;
|
float turnSpeed = 1f;
|
||||||
float steerMax = 0.5f;
|
if (binding.equals("Lefts")) {
|
||||||
if (playerCarType == VehicleInstance.TRUCK) {
|
if (value) {
|
||||||
steerMax = 0.7f;
|
inputTurning += turnSpeed;
|
||||||
}
|
} else {
|
||||||
if (binding.equals("Lefts")) {
|
inputTurning -= turnSpeed;
|
||||||
if (value) {
|
}
|
||||||
playerVehicle.steeringValue += steerMax;
|
} else if (binding.equals("Rights")) {
|
||||||
} else {
|
if (value) {
|
||||||
playerVehicle.steeringValue += -steerMax;
|
inputTurning -= turnSpeed;
|
||||||
|
} else {
|
||||||
|
inputTurning += turnSpeed;
|
||||||
|
}
|
||||||
|
} else if (binding.equals("Ups")) {
|
||||||
|
if (value) {
|
||||||
|
inputAccel += walkSpeed;
|
||||||
|
} else {
|
||||||
|
inputAccel -= walkSpeed;
|
||||||
|
}
|
||||||
|
} else if (binding.equals("Downs")) {
|
||||||
|
if (value) {
|
||||||
|
inputAccel -= walkSpeed;
|
||||||
|
} else {
|
||||||
|
inputAccel += walkSpeed;
|
||||||
|
}
|
||||||
|
} else if (binding.equals("Reset")) {
|
||||||
|
if (value) {
|
||||||
|
System.out.println("Reset - to car");
|
||||||
|
Vector3f playerPos = player.node.getWorldTranslation();
|
||||||
|
for (VehicleNode vehicle : gameWorldState.vehicles) {
|
||||||
|
Vector3f vehiclePos = vehicle.getWorldTranslation();
|
||||||
|
float dist = playerPos.distance(vehiclePos);
|
||||||
|
System.out.println(" .. dist: " + dist);
|
||||||
|
if (dist < 5f) {
|
||||||
|
player.vehicleNode = vehicle;
|
||||||
|
player.node.removeFromParent();
|
||||||
|
player.node.setLocalTranslation(0f, 0f, -1f);
|
||||||
|
player.node.setLocalRotation(Quaternion.DIRECTION_Z);
|
||||||
|
player.node.removeControl(player.characterControl);
|
||||||
|
player.vehicleNode.attachChild(player.node);
|
||||||
|
VehicleInstance playerVehicle = player.vehicleNode.vehicleInstance;
|
||||||
|
playerVehicle.accelerationValue = 0;
|
||||||
|
playerVehicle.steeringValue = 0;
|
||||||
|
player.walkDir = new Vector3f();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
playerVehicleControl.steer(playerVehicle.steeringValue);
|
} else {
|
||||||
} else if (binding.equals("Rights")) {
|
VehicleInstance playerVehicle = player.vehicleNode.vehicleInstance;
|
||||||
if (value) {
|
VehicleControl playerVehicleControl = player.vehicleNode.vehicleControl;
|
||||||
playerVehicle.steeringValue += -steerMax;
|
int playerCarType = playerVehicle.carType;
|
||||||
} else {
|
float steerMax = 0.5f;
|
||||||
playerVehicle.steeringValue += steerMax;
|
|
||||||
}
|
|
||||||
playerVehicleControl.steer(playerVehicle.steeringValue);
|
|
||||||
} else if (binding.equals("Ups")) {
|
|
||||||
if (value) {
|
|
||||||
playerVehicle.accelerationValue += playerVehicle.accelerationForce;
|
|
||||||
} else {
|
|
||||||
playerVehicle.accelerationValue -= playerVehicle.accelerationForce;
|
|
||||||
}
|
|
||||||
playerVehicleControl.accelerate(2, playerVehicle.accelerationValue);
|
|
||||||
playerVehicleControl.accelerate(3, playerVehicle.accelerationValue);
|
|
||||||
if (playerCarType == VehicleInstance.TRUCK) {
|
if (playerCarType == VehicleInstance.TRUCK) {
|
||||||
playerVehicleControl.accelerate(4, playerVehicle.accelerationValue);
|
steerMax = 0.7f;
|
||||||
playerVehicleControl.accelerate(5, playerVehicle.accelerationValue);
|
|
||||||
}
|
}
|
||||||
} else if (binding.equals("Downs")) {
|
if (binding.equals("Lefts")) {
|
||||||
float b;
|
if (value) {
|
||||||
if (value) {
|
playerVehicle.steeringValue += steerMax;
|
||||||
playerVehicle.brakeForce = playerVehicle.accelerationForce;
|
} else {
|
||||||
} else {
|
playerVehicle.steeringValue += -steerMax;
|
||||||
playerVehicle.brakeForce = 0f;
|
}
|
||||||
}
|
playerVehicleControl.steer(playerVehicle.steeringValue);
|
||||||
playerVehicleControl.brake(0, playerVehicle.brakeForce);
|
} else if (binding.equals("Rights")) {
|
||||||
playerVehicleControl.brake(1, playerVehicle.brakeForce);
|
if (value) {
|
||||||
} else if (binding.equals("Revs")) {
|
playerVehicle.steeringValue += -steerMax;
|
||||||
if (value) {
|
} else {
|
||||||
playerVehicle.accelerationValue += playerVehicle.accelerationForce;
|
playerVehicle.steeringValue += steerMax;
|
||||||
} else {
|
}
|
||||||
playerVehicle.accelerationValue -= playerVehicle.accelerationForce;
|
playerVehicleControl.steer(playerVehicle.steeringValue);
|
||||||
}
|
} else if (binding.equals("Ups")) {
|
||||||
playerVehicleControl.accelerate(2, -playerVehicle.accelerationValue);
|
if (value) {
|
||||||
playerVehicleControl.accelerate(3, -playerVehicle.accelerationValue);
|
playerVehicle.accelerationValue += playerVehicle.accelerationForce;
|
||||||
if (playerCarType == VehicleInstance.TRUCK) {
|
} else {
|
||||||
playerVehicleControl.accelerate(4, -playerVehicle.accelerationValue);
|
playerVehicle.accelerationValue -= playerVehicle.accelerationForce;
|
||||||
playerVehicleControl.accelerate(5, -playerVehicle.accelerationValue);
|
}
|
||||||
}
|
playerVehicleControl.accelerate(2, playerVehicle.accelerationValue);
|
||||||
} else if (binding.equals("Space")) {
|
playerVehicleControl.accelerate(3, playerVehicle.accelerationValue);
|
||||||
if (value) {
|
if (playerCarType == VehicleInstance.TRUCK) {
|
||||||
playerVehicleControl.applyImpulse(player.jumpForce, Vector3f.ZERO);
|
playerVehicleControl.accelerate(4, playerVehicle.accelerationValue);
|
||||||
}
|
playerVehicleControl.accelerate(5, playerVehicle.accelerationValue);
|
||||||
} else if (binding.equals("Reset")) {
|
}
|
||||||
if (value) {
|
} else if (binding.equals("Downs")) {
|
||||||
System.out.println("Reset - from car");
|
float b;
|
||||||
player.node.removeFromParent();
|
if (value) {
|
||||||
player.node.addControl(player.characterControl);
|
playerVehicle.brakeForce = playerVehicle.accelerationForce;
|
||||||
player.characterControl.warp(player.vehicleNode.getLocalTranslation());
|
} else {
|
||||||
rootNode.attachChild(player.node);
|
playerVehicle.brakeForce = 0f;
|
||||||
player.vehicleNode = null;
|
}
|
||||||
player.walkDir = new Vector3f();
|
playerVehicleControl.brake(0, playerVehicle.brakeForce);
|
||||||
} else {
|
playerVehicleControl.brake(1, playerVehicle.brakeForce);
|
||||||
|
} else if (binding.equals("Revs")) {
|
||||||
|
if (value) {
|
||||||
|
playerVehicle.accelerationValue += playerVehicle.accelerationForce;
|
||||||
|
} else {
|
||||||
|
playerVehicle.accelerationValue -= playerVehicle.accelerationForce;
|
||||||
|
}
|
||||||
|
playerVehicleControl.accelerate(2, -playerVehicle.accelerationValue);
|
||||||
|
playerVehicleControl.accelerate(3, -playerVehicle.accelerationValue);
|
||||||
|
if (playerCarType == VehicleInstance.TRUCK) {
|
||||||
|
playerVehicleControl.accelerate(4, -playerVehicle.accelerationValue);
|
||||||
|
playerVehicleControl.accelerate(5, -playerVehicle.accelerationValue);
|
||||||
|
}
|
||||||
|
} else if (binding.equals("Space")) {
|
||||||
|
if (value) {
|
||||||
|
playerVehicleControl.applyImpulse(player.jumpForce, Vector3f.ZERO);
|
||||||
|
}
|
||||||
|
} else if (binding.equals("Reset")) {
|
||||||
|
if (value) {
|
||||||
|
System.out.println("Reset - from car");
|
||||||
|
player.node.removeFromParent();
|
||||||
|
player.node.addControl(player.characterControl);
|
||||||
|
player.characterControl.warp(player.vehicleNode.getLocalTranslation());
|
||||||
|
rootNode.attachChild(player.node);
|
||||||
|
player.vehicleNode = null;
|
||||||
|
player.walkDir = new Vector3f();
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (binding.equals("Esc")) {
|
||||||
|
// TODO: open menu
|
||||||
|
if (value) {
|
||||||
|
setGamePaused(true);
|
||||||
|
}
|
||||||
|
} else if (binding.equals("Pause")) {
|
||||||
|
if (value) {
|
||||||
|
setGamePaused(!gamePaused);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (binding.equals("Esc")) {
|
|
||||||
stop();
|
|
||||||
} else if (binding.equals("Pause")) {
|
|
||||||
setGamePaused(value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onGamePause(boolean paused) {
|
||||||
|
super.onGamePause(paused);
|
||||||
|
|
||||||
|
if (paused) {
|
||||||
|
rootNode.attachChild(menuBook);
|
||||||
|
} else {
|
||||||
|
menuBook.removeFromParent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private CharSequence getMenuText()
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("~~~~~~~~~~~~~~~~~~~~\n Road Trip \n~~~~~~~~~~~~~~~~~~~~\n");
|
||||||
|
for (int i = 0; i < menuEntries.length; i++) {
|
||||||
|
String entry = menuEntries[i];
|
||||||
|
boolean selected = (i == menuEntryIndex);
|
||||||
|
sb.append(selected ? "]>" : " ");
|
||||||
|
sb.append(entry);
|
||||||
|
sb.append(selected ? "<[" : " ");
|
||||||
|
sb.append("\n");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user