Sails can be toggled on the visualiser and the rotate sails button rotates the sail visually. #story[1098]
This commit is contained in:
@@ -90,6 +90,10 @@ public class Boat {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private ZonedDateTime timeAtLastMark;
|
private ZonedDateTime timeAtLastMark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The state of the boats sails. True if sails are out.
|
||||||
|
*/
|
||||||
|
private boolean sailsOut = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a boat object with a given sourceID, name, country/team abbreviation, and polars table.
|
* Constructs a boat object with a given sourceID, name, country/team abbreviation, and polars table.
|
||||||
@@ -395,4 +399,11 @@ public class Boat {
|
|||||||
this.timeAtLastMark = timeAtLastMark;
|
this.timeAtLastMark = timeAtLastMark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSailsOut(boolean sailsOut) {
|
||||||
|
this.sailsOut = sailsOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSailsOut() {
|
||||||
|
return sailsOut;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package visualiser.gameController.Keys;
|
package visualiser.gameController.Keys;
|
||||||
|
|
||||||
|
import visualiser.model.ThisBoat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key to toggle the sails
|
* Key to toggle the sails
|
||||||
*/
|
*/
|
||||||
@@ -19,7 +21,16 @@ public class SailsToggleKey extends ControlKey {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onAction() {
|
public void onAction() {
|
||||||
protocolCode = protocolCode == 2? 3 : 2;
|
// 2 = Sails in
|
||||||
|
// 3 = Sails out
|
||||||
|
if (ThisBoat.getInstance().isSailsOut()) {
|
||||||
|
protocolCode = 3;
|
||||||
|
ThisBoat.getInstance().setSailsOut(false);
|
||||||
|
} else {
|
||||||
|
protocolCode = 2;
|
||||||
|
ThisBoat.getInstance().setSailsOut(true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -305,8 +305,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|||||||
gc.fillPolygon(x, y, 3);
|
gc.fillPolygon(x, y, 3);
|
||||||
gc.restore();
|
gc.restore();
|
||||||
|
|
||||||
// TODO: update with current players boat
|
if (boat.getSourceID() == ThisBoat.getInstance().getSourceID()) {
|
||||||
if (boat.getSourceID() == 125) {
|
|
||||||
drawSails(boat);
|
drawSails(boat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -333,7 +332,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|||||||
// right half of points of sail
|
// right half of points of sail
|
||||||
if (boatBearing < 180) {
|
if (boatBearing < 180) {
|
||||||
sailImage = sailsRight;
|
sailImage = sailsRight;
|
||||||
sailRotateAngle = boatBearing * 0.5; // math
|
sailRotateAngle = boatBearing; // math
|
||||||
xPos -= 1; // right align to boat edge on canvas
|
xPos -= 1; // right align to boat edge on canvas
|
||||||
// System.out.println("right side -- boat: " + boatBearing +
|
// System.out.println("right side -- boat: " + boatBearing +
|
||||||
// "|| rotate: " + sailRotateAngle);
|
// "|| rotate: " + sailRotateAngle);
|
||||||
@@ -341,12 +340,21 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|||||||
// left half of points of sail
|
// left half of points of sail
|
||||||
else {
|
else {
|
||||||
sailImage = sailsLeft;
|
sailImage = sailsLeft;
|
||||||
sailRotateAngle = -(360 - boatBearing) * 0.5; // math
|
sailRotateAngle = -(360 - boatBearing); // math
|
||||||
xPos -= 5; // left align to boat edge on canvas
|
xPos -= 5; // left align to boat edge on canvas
|
||||||
// System.out.println("left side -- boat: " + boatBearing +
|
// System.out.println("left side -- boat: " + boatBearing +
|
||||||
// "|| rotate: " + sailRotateAngle);
|
// "|| rotate: " + sailRotateAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change the angle of the sail if the sail is out
|
||||||
|
if (ThisBoat.getInstance().isSailsOut()) {
|
||||||
|
if (boatBearing < 180) {
|
||||||
|
sailRotateAngle -= 90;
|
||||||
|
} else {
|
||||||
|
sailRotateAngle += 90;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// rotate sails based on boats current heading
|
// rotate sails based on boats current heading
|
||||||
rotate(sailRotateAngle, boatPos.getX(), boatPos.getY());
|
rotate(sailRotateAngle, boatPos.getX(), boatPos.getY());
|
||||||
gc.drawImage(sailImage, xPos, yPos);
|
gc.drawImage(sailImage, xPos, yPos);
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package visualiser.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The properties of the boat currently being controlled by the player. Singleton.
|
||||||
|
*/
|
||||||
|
public class ThisBoat {
|
||||||
|
// TODO Initialise sourceID to the sourceID given by the network
|
||||||
|
private int sourceID = 125;
|
||||||
|
private boolean sailsOut = false;
|
||||||
|
private static ThisBoat instance = new ThisBoat();
|
||||||
|
|
||||||
|
private ThisBoat(){}
|
||||||
|
|
||||||
|
public static ThisBoat getInstance(){
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSailsOut(boolean sailsOut) {
|
||||||
|
this.sailsOut = sailsOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourceID(int sourceID) {
|
||||||
|
this.sourceID = sourceID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSailsOut() {
|
||||||
|
return sailsOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSourceID() {
|
||||||
|
return sourceID;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user