Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move particule motor to car

  • Loading branch information...
commit a6bd995945a69650a59cf49b3c31255991f1a06e 1 parent 100b69e
@geenux authored
View
34 src/game/AbstractGameScreenState.java
@@ -93,7 +93,6 @@
protected boolean needReset;
- protected ParticuleMotor particule_motor;
private long timerRedZone = 0;
protected boolean playerFinish;
protected long timerStopPlayer = 0;
@@ -200,9 +199,6 @@ protected void initGame() {
// Init audio
audio_motor = new AudioRender(assetManager, player.getNode());
- // Init particule motor
- particule_motor = new ParticuleMotor(assetManager);
-
LinkedHashMap<Integer, String> channels = new LinkedHashMap<Integer, String>();
channels.put(1000, "Models/Default/1052_P.wav");
// channels.put(1126, "Models/Default/1126_P.wav");
@@ -413,7 +409,7 @@ public void update(float tpf) {
// Traiter le cas du sur-régime
if (playerRpm > (playerCarProperties.getRedline() - 500)) {
- if (!particule_motor.getBurstEnabled()) {
+ if (!player.getBurstEnabled()) {
// Déclencher le timer s'il n'est pas activé
if (timerRedZone == 0) {
timerRedZone = System.currentTimeMillis();
@@ -430,13 +426,12 @@ public void update(float tpf) {
// Update audio
if (soudIsActive) {
- System.out.println("RPM " + playerRpm);
audio_motor.setRPM(playerRpm);
app.getListener().setLocation(
player.getNode().getWorldTranslation());
}
- particule_motor.controlBurst();
+ //particule_motor.controlBurst();
digitalTachometer.setText(((Integer) playerRpm).toString());
digitalSpeed.setText(((Integer) playerSpeed).toString());
@@ -504,8 +499,8 @@ private void countDown() {
* @param vehicule
*/
public void triggerBurst(Car vehicule) {
+ vehicule.explode();
audio_motor.playBurst();
- particule_motor.addExplosion(vehicule.getNode());
audio_motor.mute();
playerFinish = true;
timePlayer = 0;
@@ -526,8 +521,8 @@ protected void reset() {
playerEnginePhysics.setSpeed(0);
playerEnginePhysics.setRpm(1000);
- if (particule_motor.getBurstEnabled()) {
- particule_motor.removeExplosion(player.getNode());
+ if (player.getBurstEnabled()) {
+ player.removeExplosion();
}
timerRedZone = 0;
@@ -592,7 +587,7 @@ public void onAction(String binding, boolean value, float tpf) {
@Override
public void onAnalog(String binding, float value, float tpf) {
if (binding.equals("Throttle")) {
- if (!particule_motor.getBurstEnabled()) {
+ if (!player.getBurstEnabled()) {
// Start countdown
if (countDown == 0) {
countDown = System.currentTimeMillis();
@@ -639,7 +634,7 @@ public void collision(PhysicsCollisionEvent event) {
// Impact, reduce friction
float damageForce = (appliedImpulse - event.getCombinedFriction() / 10) / 10000;
- System.out.println("Collision between " + car1.getType() + " "
+ /*System.out.println("Collision between " + car1.getType() + " "
+ car1.getDriverName() + " and " + car2.getType() + " "
+ car2.getDriverName());
System.out.println("Lateral 1 impulse "
@@ -648,7 +643,7 @@ public void collision(PhysicsCollisionEvent event) {
+ event.getAppliedImpulseLateral2());
System.out.println("Combined friction "
+ event.getCombinedFriction());
- System.out.println("Force " + appliedImpulse);
+ System.out.println("Force " + appliedImpulse);*/
Vector3f forward1 = new Vector3f(0, 0, 0).subtract(
car1.getForwardVector(null)).normalize();
@@ -662,12 +657,13 @@ public void collision(PhysicsCollisionEvent event) {
Vector2f pos1 = new Vector2f(position1.x, position1.z);
Vector2f pos2 = new Vector2f(position2.x, position2.z);
- System.out.println("Position A: " + pos1);
+
+ /*System.out.println("Position A: " + pos1);
System.out.println("Position B: " + pos2);
-
- System.out.println("Forward " + f1 + " " + f2);
+ System.out.println("Forward " + f1 + " " + f2);*/
+
float angle = Math.abs(MathTools.orientedAngle(f1, f2));
- System.out.println("Angle " + angle);
+ //System.out.println("Angle " + angle);
// Frontal collision
if (angle >= Math.PI - Math.PI / 4
@@ -681,9 +677,9 @@ public void collision(PhysicsCollisionEvent event) {
// back collision if (angle <= Math.PI / 4)
// the car in front will have 75% of the damages
// 25% for the car in back
- System.out.println("Back collision " + speed1 + " " + speed2
+ /*System.out.println("Back collision " + speed1 + " " + speed2
+ " at force " + appliedImpulse);
- System.out.println("Distance 1" + event.getDistance1());
+ System.out.println("Distance 1" + event.getDistance1()); */
double speedDifferenceDamage = Math.abs(speed2 - speed1)
* damageForce / 2;
if (car1.inFront(car2)) {
View
25 src/game/Car.java
@@ -37,6 +37,8 @@
public enum CarType { BOT, PLAYER };
private CarType type;
+ protected ParticuleMotor particule_motor;
+
public Car(AssetManager assetManager, CarProperties properties) {
super();
this.assetManager = assetManager;
@@ -48,6 +50,12 @@ public Car(AssetManager assetManager, CarProperties properties) {
this.type = CarType.BOT;
buildPlayer();
+ buildParticuleMotor();
+ }
+
+ private void buildParticuleMotor() {
+ // Init particule motor
+ particule_motor = new ParticuleMotor(assetManager);
}
private void buildPlayer() {
@@ -178,6 +186,10 @@ public void increaseLife(double value) {
public void decreaseLife(double value) {
life -= value;
if(life < 0) life = 0;
+ if(life == 0) {
+ if(!particule_motor.getBurstEnabled())
+ explode();
+ }
}
public int getLife() {
@@ -213,4 +225,17 @@ public boolean inFront(Car c) {
else
return false;
}
+
+ public boolean getBurstEnabled() {
+ return particule_motor.getBurstEnabled();
+ }
+
+ public void explode() {
+ particule_motor.addExplosion(carNode);
+ enginePhysics.setBreaking(true);
+ }
+
+ public void removeExplosion() {
+ particule_motor.removeExplosion(carNode);
+ }
}
View
4 src/game/FreeForAllScreenState.java
@@ -39,8 +39,8 @@ protected void initGame() {
addBot(new Vector3f(new Vector3f(10, 27, 700)), new BMWM3Properties());
addBot(new Vector3f(new Vector3f(20, 27, 800)), new BMWM3Properties());
addBot(new Vector3f(new Vector3f(30, 27, 500)), new BMWM3Properties());
- addBot(new Vector3f(new Vector3f(40, 27, 600)), new BMWM3Properties());
- addBot(new Vector3f(new Vector3f(40, 27, 600)), new BMWM3Properties());
+ //addBot(new Vector3f(new Vector3f(40, 27, 600)), new BMWM3Properties());
+ //addBot(new Vector3f(new Vector3f(40, 27, 600)), new BMWM3Properties());
/*
* addBot(new Vector3f(new Vector3f(300, 27, 800)), new
View
2  src/game/GameScreenState.java
@@ -98,7 +98,7 @@ public void update(float tpf) {
if (playerFinish && botFinish && !runFinish) {
String text = "";
- if (timePlayer < timeBot && !particule_motor.getBurstEnabled()) {
+ if (timePlayer < timeBot && !player.getBurstEnabled()) {
text = "Gagne !\n ";
audio_motor.playWin();
} else {
View
10 src/physics/EnginePhysics.java
@@ -24,6 +24,8 @@
* Used to know whether the rpm is over the redline.
*/
private boolean isBreaking = false;
+
+ private boolean engineBroken = false;
public EnginePhysics(CarProperties prop) {
this.p = prop;
@@ -182,4 +184,12 @@ public CarProperties getCarProperties() {
public void setBreaking(boolean b) {
isBreaking = b;
}
+
+ public void setEngineBroken(boolean state) {
+ engineBroken = state;
+ }
+
+ public boolean getEngineBroken() {
+ return engineBroken;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.