Depleting tomato now watches player health
- [BUG] Tomato fills up instead of depleting #story[1291]
This commit is contained in:
@@ -12,6 +12,7 @@ import javafx.scene.AmbientLight;
|
|||||||
import javafx.scene.PointLight;
|
import javafx.scene.PointLight;
|
||||||
import javafx.scene.chart.LineChart;
|
import javafx.scene.chart.LineChart;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
@@ -41,6 +42,7 @@ import visualiser.model.VisualiserRaceState;
|
|||||||
import visualiser.utils.GPSConverter;
|
import visualiser.utils.GPSConverter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -222,6 +224,7 @@ public class RaceViewController extends Controller {
|
|||||||
initialiseFps();
|
initialiseFps();
|
||||||
initialiseInfoTable();
|
initialiseInfoTable();
|
||||||
initialiseView3D(this.visualiserRace);
|
initialiseView3D(this.visualiserRace);
|
||||||
|
initialiseHealthPane();
|
||||||
initialiseRaceClock();
|
initialiseRaceClock();
|
||||||
raceTimer(); // start the timer
|
raceTimer(); // start the timer
|
||||||
new Sparkline(this.raceState, this.sparklineChart);
|
new Sparkline(this.raceState, this.sparklineChart);
|
||||||
@@ -229,6 +232,21 @@ public class RaceViewController extends Controller {
|
|||||||
arrowController.setWindProperty(this.raceState.windProperty());
|
arrowController.setWindProperty(this.raceState.windProperty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initialiseHealthPane() {
|
||||||
|
InputStream tomato = this.getClass().getClassLoader().getResourceAsStream("visualiser/images/tomato.png");
|
||||||
|
HealthSlider healthSlider = new HealthSlider(new Image(tomato));
|
||||||
|
playerHealthContainer.add(healthSlider, 0, 0);
|
||||||
|
|
||||||
|
try {
|
||||||
|
VisualiserBoat player = raceState.getBoat(raceState.getPlayerBoatID());
|
||||||
|
player.healthProperty().addListener((o, prev, curr) -> {
|
||||||
|
healthSlider.setCrop((double)curr/100.0);
|
||||||
|
});
|
||||||
|
} catch (BoatNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void initialiseView3D(VisualiserRaceEvent race) {
|
private void initialiseView3D(VisualiserRaceEvent race) {
|
||||||
viewSubjects = FXCollections.observableArrayList();
|
viewSubjects = FXCollections.observableArrayList();
|
||||||
|
|
||||||
@@ -335,11 +353,6 @@ public class RaceViewController extends Controller {
|
|||||||
|
|
||||||
boat.legProperty().addListener((o, prev, curr) -> Platform.runLater(() -> swapColours(curr)));
|
boat.legProperty().addListener((o, prev, curr) -> Platform.runLater(() -> swapColours(curr)));
|
||||||
boat.hasCollidedProperty().addListener((o, prev, curr) -> Platform.runLater(() -> showCollision(boat, shockwave)));
|
boat.hasCollidedProperty().addListener((o, prev, curr) -> Platform.runLater(() -> showCollision(boat, shockwave)));
|
||||||
if(boat.getSourceID() == race.getVisualiserRaceState().getPlayerBoatID()) {
|
|
||||||
boat.healthProperty().addListener((o, prev, curr) -> {
|
|
||||||
System.out.println(curr);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Fix initial bird's-eye position
|
// Fix initial bird's-eye position
|
||||||
view3D.updatePivot(new Translate(250, 0, 210));
|
view3D.updatePivot(new Translate(250, 0, 210));
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package visualiser.layout;
|
||||||
|
|
||||||
|
import javafx.scene.image.Image;
|
||||||
|
import javafx.scene.image.WritableImage;
|
||||||
|
import javafx.scene.layout.*;
|
||||||
|
import javafx.scene.shape.Rectangle;
|
||||||
|
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by connortaylorbrown on 21/09/17.
|
||||||
|
*/
|
||||||
|
public class HealthSlider extends Pane {
|
||||||
|
/**
|
||||||
|
* Image used to fill health slider
|
||||||
|
*/
|
||||||
|
private Image fillImage;
|
||||||
|
/**
|
||||||
|
* Size of background for image configuration
|
||||||
|
*/
|
||||||
|
private BackgroundSize backgroundSize;
|
||||||
|
/**
|
||||||
|
* Percentage of image cropped out from top
|
||||||
|
*/
|
||||||
|
private double crop;
|
||||||
|
|
||||||
|
public HealthSlider(Image fillImage) {
|
||||||
|
this.fillImage = fillImage;
|
||||||
|
this.crop = 0;
|
||||||
|
this.backgroundSize = new BackgroundSize(
|
||||||
|
100,
|
||||||
|
100,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
false);
|
||||||
|
drawSlider();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCrop(double crop) {
|
||||||
|
this.crop = crop;
|
||||||
|
drawSlider();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawSlider() {
|
||||||
|
int top = (int)(crop * fillImage.getHeight());
|
||||||
|
|
||||||
|
WritableImage croppedImage = new WritableImage(
|
||||||
|
fillImage.getPixelReader(),
|
||||||
|
0,
|
||||||
|
top,
|
||||||
|
(int)fillImage.getWidth(),
|
||||||
|
(int)fillImage.getHeight() - top
|
||||||
|
);
|
||||||
|
|
||||||
|
BackgroundImage backgroundImage = new BackgroundImage(
|
||||||
|
croppedImage,
|
||||||
|
BackgroundRepeat.NO_REPEAT,
|
||||||
|
BackgroundRepeat.NO_REPEAT,
|
||||||
|
BackgroundPosition.CENTER,
|
||||||
|
backgroundSize
|
||||||
|
);
|
||||||
|
|
||||||
|
this.setBackground(new Background(backgroundImage));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -62,7 +62,7 @@ public class VisualiserBoat extends Boat {
|
|||||||
private ObjectProperty<GPSCoordinate> positionProperty;
|
private ObjectProperty<GPSCoordinate> positionProperty;
|
||||||
private ObjectProperty<Bearing> bearingProperty;
|
private ObjectProperty<Bearing> bearingProperty;
|
||||||
private BooleanProperty hasCollided;
|
private BooleanProperty hasCollided;
|
||||||
private IntegerProperty healthProperty;
|
private DoubleProperty healthProperty;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,7 +76,7 @@ public class VisualiserBoat extends Boat {
|
|||||||
|
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.hasCollided = new SimpleBooleanProperty(false);
|
this.hasCollided = new SimpleBooleanProperty(false);
|
||||||
this.healthProperty = new SimpleIntegerProperty(100);
|
this.healthProperty = new SimpleDoubleProperty(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -281,7 +281,7 @@ public class VisualiserBoat extends Boat {
|
|||||||
this.hasCollided.set(hasCollided);
|
this.hasCollided.set(hasCollided);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntegerProperty healthProperty() {
|
public DoubleProperty healthProperty() {
|
||||||
return healthProperty;
|
return healthProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user