Merge branch 'master' into new_issue#19

# Conflicts:
#	racevisionGame/src/main/java/visualiser/Controllers/TitleController.java
This commit is contained in:
David Wu
2017-08-17 17:00:39 +12:00
48 changed files with 174 additions and 108 deletions
@@ -1,8 +1,5 @@
package visualiser.model;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
@@ -3,10 +3,6 @@ package visualiser.model;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
/**
* Connection for Races
*/
@@ -1,6 +1,7 @@
package visualiser.model;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Paint;
@@ -35,6 +36,10 @@ public class ResizableRaceCanvas extends ResizableCanvas {
*/
private RaceMap map;
private Image sailsRight = new Image("/images/sailsRight.png");
private Image sailsLeft = new Image("/images/sailsLeft.png");
private Image sailsLuff = new Image("/images/sailsLuff.gif", 25, 10, false, false);
/**
* The race we read data from and draw.
*/
@@ -336,8 +341,6 @@ public class ResizableRaceCanvas extends ResizableCanvas {
}
/**
* Draws a given boat on the canvas.
* @param boat The boat to draw.
@@ -375,7 +378,9 @@ public class ResizableRaceCanvas extends ResizableCanvas {
gc.fillPolygon(x, y, x.length);
gc.restore();
if (boat.getSourceID() == ThisBoat.getInstance().getSourceID()) {
drawSails(boat);
}
}
/**
@@ -413,6 +418,70 @@ public class ResizableRaceCanvas extends ResizableCanvas {
}
/**
* Draws sails for a given boat on the canvas. Sail position is
* determined by the boats heading and the current wind direction
* according to the "points of sail".
* @param boat boat to display sails for
*/
private void drawSails(VisualiserBoat boat) {
GraphCoordinate boatPos =
this.map.convertGPS(boat.getPosition());
double xPos = boatPos.getX(); // x pos of sail (on boat)
double yPos = boatPos.getY() - 6; // y pos of sail (on boat)
double boatBearing = boat.getBearing().degrees();
double windDirection = 0; //visualiserRace.getWindDirection().degrees();
double sailRotateAngle = 0; // rotation for correct sail display
Image sailImage = null;
Boolean rightSail = true;
// Getting the correct Points of Sail
if (ThisBoat.getInstance().isSailsOut()){
// correct sail and sailRotateAngle start depending on wind+bearing
if ((windDirection + 180) > 360) {
if ((boatBearing < windDirection) &&
(boatBearing > windDirection - 180)) {
rightSail = false;
} else {
if (boatBearing < 180) {
sailRotateAngle = -180;
}
}
} else {
if (!((boatBearing > windDirection) &&
(boatBearing < windDirection + 180))) {
rightSail = false;
if (boatBearing > 180) {
sailRotateAngle = -180;
}
}
}
if (rightSail) {
sailImage = sailsRight;
xPos -= 1; // right align sail to boat edge on canvas
} else {
sailImage = sailsLeft;
xPos -= 5; // left align sail to boat edge on canvas
}
sailRotateAngle += ((boatBearing + windDirection) * 0.5);
}
// Sails in = luffing sail
else {
xPos -= 6;
yPos += 1;
sailImage = sailsLuff;
sailRotateAngle = boatBearing + 90;
}
gc.save();
// rotate sails based on boats current heading
rotate(sailRotateAngle, boatPos.getX(), boatPos.getY());
gc.drawImage(sailImage, xPos, yPos);
gc.restore();
}
/**
* Draws the wake for a given boat.
@@ -756,4 +825,4 @@ public class ResizableRaceCanvas extends ResizableCanvas {
}
}
@@ -0,0 +1,31 @@
package visualiser.model;
/**
* The properties of the boat currently being controlled by the player. Singleton.
*/
public class ThisBoat {
private VisualiserBoat boat;
private static ThisBoat instance = new ThisBoat();
private ThisBoat(){}
public static ThisBoat getInstance(){
return instance;
}
public void setSailsOut(boolean sailsOut) {
this.boat.setSailsOut(sailsOut);
}
public boolean isSailsOut() {
return this.boat.isSailsOut();
}
public int getSourceID() {
return this.boat.getSourceID();
}
public void setBoat(VisualiserBoat boat) {
this.boat = boat;
}
}
@@ -205,6 +205,7 @@ public class VisualiserRaceState extends RaceState {
if (boat.getSourceID() == getPlayerBoatID()) {
boat.setClientBoat(true);
ThisBoat.getInstance().setBoat(boat);
}
}