mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Display team name and speed beside boat
- Also slowed down the AnimationTimer - Removed the need to scale the canvas Tags: #implement #story[18] #story[19]
This commit is contained in:
@@ -10,6 +10,8 @@ import javafx.scene.canvas.GraphicsContext;
|
|||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.scene.text.Font;
|
||||||
|
import javafx.scene.text.FontSmoothingType;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
import seng302.models.Boat;
|
import seng302.models.Boat;
|
||||||
@@ -53,6 +55,8 @@ public class CanvasController {
|
|||||||
|
|
||||||
private Animation.Status raceStatus = Animation.Status.PAUSED;
|
private Animation.Status raceStatus = Animation.Status.PAUSED;
|
||||||
|
|
||||||
|
private final int SCALE = 16000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the list of boats in the order they finished the race
|
* Display the list of boats in the order they finished the race
|
||||||
*/
|
*/
|
||||||
@@ -125,7 +129,7 @@ public class CanvasController {
|
|||||||
*/
|
*/
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
gc = canvas.getGraphicsContext2D();
|
gc = canvas.getGraphicsContext2D();
|
||||||
gc.scale(15, 15);
|
//gc.scale(1, 1);
|
||||||
RaceController raceController = new RaceController();
|
RaceController raceController = new RaceController();
|
||||||
raceController.initializeRace();
|
raceController.initializeRace();
|
||||||
race = raceController.getRace();
|
race = raceController.getRace();
|
||||||
@@ -133,9 +137,12 @@ public class CanvasController {
|
|||||||
|
|
||||||
// overriding the handle so that it can clean canvas and redraw boats and course marks
|
// overriding the handle so that it can clean canvas and redraw boats and course marks
|
||||||
AnimationTimer timer = new AnimationTimer() {
|
AnimationTimer timer = new AnimationTimer() {
|
||||||
|
private long lastUpdate = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(long now) {
|
public void handle(long now) {
|
||||||
gc.clearRect(0, 0, 760, 360);
|
if (now - lastUpdate >= 16000000){
|
||||||
|
gc.clearRect(0, 0, 19200, 10800);
|
||||||
drawCourse();
|
drawCourse();
|
||||||
drawBoats();
|
drawBoats();
|
||||||
|
|
||||||
@@ -149,6 +156,9 @@ public class CanvasController {
|
|||||||
pauseTimelines();
|
pauseTimelines();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastUpdate = now;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -232,7 +242,7 @@ public class CanvasController {
|
|||||||
private void drawBoats() {
|
private void drawBoats() {
|
||||||
for (Boat boat : timelineInfos.keySet()) {
|
for (Boat boat : timelineInfos.keySet()) {
|
||||||
TimelineInfo timelineInfo = timelineInfos.get(boat);
|
TimelineInfo timelineInfo = timelineInfos.get(boat);
|
||||||
drawBoat(timelineInfo.getX().doubleValue(), timelineInfo.getY().doubleValue(), boat.getColor());
|
drawBoat(timelineInfo.getX().doubleValue(), timelineInfo.getY().doubleValue(), boat.getColor(), boat.getTeamName(), boat.getSpeedInKnots());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,14 +253,20 @@ public class CanvasController {
|
|||||||
* @param lon
|
* @param lon
|
||||||
* @param color
|
* @param color
|
||||||
*/
|
*/
|
||||||
private void drawBoat(double lat, double lon, Color color) {
|
private void drawBoat(double lat, double lon, Color color, String name, double speed) {
|
||||||
// Latitude
|
// Latitude
|
||||||
double x = (lon - ORIGIN_LON) * 1000;
|
double x = (lon - ORIGIN_LON) * SCALE;
|
||||||
double y = (ORIGIN_LAT - lat) * 1000;
|
double y = (ORIGIN_LAT - lat) * SCALE;
|
||||||
|
|
||||||
double diameter = 0.5;
|
double diameter = 9;
|
||||||
|
|
||||||
|
// Set boat text
|
||||||
|
gc.setFont(new Font(14));
|
||||||
gc.setFill(color);
|
gc.setFill(color);
|
||||||
|
gc.setLineWidth(3);
|
||||||
|
gc.setFontSmoothingType(FontSmoothingType.GRAY);
|
||||||
|
gc.fillText(name + ", " + speed + " knots",x+15,y+15);
|
||||||
|
|
||||||
gc.fillOval(x, y, diameter, diameter);
|
gc.fillOval(x, y, diameter, diameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,11 +289,11 @@ public class CanvasController {
|
|||||||
* @param singleMark
|
* @param singleMark
|
||||||
*/
|
*/
|
||||||
private void drawSingleMark(SingleMark singleMark, Color color) {
|
private void drawSingleMark(SingleMark singleMark, Color color) {
|
||||||
double x = (singleMark.getLongitude() - ORIGIN_LON) * 1000;
|
double x = (singleMark.getLongitude() - ORIGIN_LON) * SCALE;
|
||||||
double y = (ORIGIN_LAT - singleMark.getLatitude()) * 1000;
|
double y = (ORIGIN_LAT - singleMark.getLatitude()) * SCALE;
|
||||||
|
|
||||||
gc.setFill(color);
|
gc.setFill(color);
|
||||||
gc.fillRect(x,y,0.5,0.5);
|
gc.fillRect(x,y,5.5,5.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -304,13 +320,13 @@ public class CanvasController {
|
|||||||
gc.setStroke(color);
|
gc.setStroke(color);
|
||||||
|
|
||||||
// Convert lat/lon to x,y
|
// Convert lat/lon to x,y
|
||||||
double x1 = (gateMark.getSingleMark1().getLongitude()- ORIGIN_LON) * 1000;
|
double x1 = (gateMark.getSingleMark1().getLongitude()- ORIGIN_LON) * SCALE;
|
||||||
double y1 = (ORIGIN_LAT - gateMark.getSingleMark1().getLatitude()) * 1000;
|
double y1 = (ORIGIN_LAT - gateMark.getSingleMark1().getLatitude()) * SCALE;
|
||||||
|
|
||||||
double x2 = (gateMark.getSingleMark2().getLongitude() - ORIGIN_LON) * 1000;
|
double x2 = (gateMark.getSingleMark2().getLongitude() - ORIGIN_LON) * SCALE;
|
||||||
double y2 = (ORIGIN_LAT - gateMark.getSingleMark2().getLatitude()) * 1000;
|
double y2 = (ORIGIN_LAT - gateMark.getSingleMark2().getLatitude()) * SCALE;
|
||||||
|
|
||||||
gc.setLineWidth(0.07);
|
gc.setLineWidth(1);
|
||||||
gc.strokeLine(x1, y1, x2, y2);
|
gc.strokeLine(x1, y1, x2, y2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,4 +97,8 @@ public class Boat {
|
|||||||
public Color getColor() {
|
public Color getColor() {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getSpeedInKnots(){
|
||||||
|
return Math.round((this.velocity * 1.94384) * 100d) / 100d;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@ public class Race {
|
|||||||
private long startTime = 0;
|
private long startTime = 0;
|
||||||
private double timeScale = 1;
|
private double timeScale = 1;
|
||||||
private boolean raceFinished = false; // Race is finished
|
private boolean raceFinished = false; // Race is finished
|
||||||
private int raceTime = -10; // Current time in the race
|
private int raceTime = -2; // Current time in the race
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Race class containing the boats and legs in the race
|
* Race class containing the boats and legs in the race
|
||||||
|
|||||||
Reference in New Issue
Block a user