mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -17,8 +17,6 @@ import javafx.scene.image.ImageView;
|
|||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.scene.media.Media;
|
|
||||||
import javafx.scene.media.MediaPlayer;
|
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
import seng302.client.ClientState;
|
import seng302.client.ClientState;
|
||||||
import seng302.client.ClientStateQueryingRunnable;
|
import seng302.client.ClientStateQueryingRunnable;
|
||||||
@@ -198,29 +196,29 @@ public class LobbyController implements Initializable, Observer{
|
|||||||
@FXML
|
@FXML
|
||||||
public void readyButtonPressed() {
|
public void readyButtonPressed() {
|
||||||
// setContentPane("/views/RaceView.fxml");
|
// setContentPane("/views/RaceView.fxml");
|
||||||
playTheme();
|
// playTheme();
|
||||||
GameState.setCurrentStage(GameStages.RACING);
|
GameState.setCurrentStage(GameStages.RACING);
|
||||||
mainServerThread.startGame();
|
mainServerThread.startGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static MediaPlayer mediaPlayer;
|
// private static MediaPlayer mediaPlayer;
|
||||||
|
//
|
||||||
private void playTheme() {
|
// private void playTheme() {
|
||||||
Random random = new Random(System.currentTimeMillis());
|
// Random random = new Random(System.currentTimeMillis());
|
||||||
Integer rand = random.nextInt();
|
// Integer rand = random.nextInt();
|
||||||
if(rand == 10) {
|
// if(rand == 10) {
|
||||||
URL file = getClass().getResource("/music/Disturbed - down with the sickness.mp3");
|
// URL file = getClass().getResource("/music/Disturbed - down with the sickness.mp3");
|
||||||
Media hit = new Media(file.toString());
|
// Media hit = new Media(file.toString());
|
||||||
mediaPlayer = new MediaPlayer(hit);
|
// mediaPlayer = new MediaPlayer(hit);
|
||||||
mediaPlayer.play();
|
// mediaPlayer.play();
|
||||||
} else if(rand == 9) {
|
// } else if(rand == 9) {
|
||||||
URL file = getClass().getResource("/music/Owl City - Fireflies.mp3");
|
// URL file = getClass().getResource("/music/Owl City - Fireflies.mp3");
|
||||||
Media hit = new Media(file.toString());
|
// Media hit = new Media(file.toString());
|
||||||
mediaPlayer = new MediaPlayer(hit);
|
// mediaPlayer = new MediaPlayer(hit);
|
||||||
mediaPlayer.play();
|
// mediaPlayer.play();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
private void switchToRaceView() {
|
private void switchToRaceView() {
|
||||||
if (!switchedPane) {
|
if (!switchedPane) {
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public class BoatAnnotations extends Group{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void update () {
|
void update () {
|
||||||
velocityObject.setText(String.format(String.format("%.2f m/s", boat.getVelocity())));
|
velocityObject.setText(String.format(String.format("%.2f m/s", boat.getVelocityMMS())));
|
||||||
|
|
||||||
if (boat.getTimeTillNext() != null) {
|
if (boat.getTimeTillNext() != null) {
|
||||||
DateFormat format = new SimpleDateFormat("mm:ss");
|
DateFormat format = new SimpleDateFormat("mm:ss");
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package seng302.gameServer;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import seng302.client.ClientPacketParser;
|
||||||
import seng302.models.Player;
|
import seng302.models.Player;
|
||||||
|
|
||||||
import seng302.models.Yacht;
|
import seng302.models.Yacht;
|
||||||
@@ -80,10 +81,14 @@ public class GameState {
|
|||||||
return windDirection;
|
return windDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Double getWindSpeed() {
|
public static Double getWindSpeedMMS() {
|
||||||
return windSpeed;
|
return windSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Double getWindSpeedKnots() {
|
||||||
|
return windSpeed / 1000 * ClientPacketParser.MS_TO_KNOTS;
|
||||||
|
}
|
||||||
|
|
||||||
public static Map<Integer, Yacht> getYachts() {
|
public static Map<Integer, Yacht> getYachts() {
|
||||||
return yachts;
|
return yachts;
|
||||||
}
|
}
|
||||||
@@ -93,6 +98,7 @@ public class GameState {
|
|||||||
// System.out.println("-----------------------");
|
// System.out.println("-----------------------");
|
||||||
switch (actionType) {
|
switch (actionType) {
|
||||||
case VMG:
|
case VMG:
|
||||||
|
playerYacht.turnToVMG();
|
||||||
// System.out.println("Snapping to VMG");
|
// System.out.println("Snapping to VMG");
|
||||||
// TODO: 22/07/17 wmu16 - Add in the vmg calculation code here
|
// TODO: 22/07/17 wmu16 - Add in the vmg calculation code here
|
||||||
break;
|
break;
|
||||||
@@ -118,12 +124,13 @@ public class GameState {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// System.out.println("-----------------------");
|
System.out.println("-----------------------");
|
||||||
// System.out.println("Heading: " + playerYacht.getHeading());
|
System.out.println("Sails are in: " + playerYacht.getSailIn());
|
||||||
// System.out.println("Sails are in: " + playerYacht.getSailIn());
|
System.out.println("Heading: " + playerYacht.getHeading());
|
||||||
// System.out.println("Lat: " + playerYacht.getLocation().getLat());
|
System.out.println("Velocity: " + playerYacht.getVelocityMMS() / 1000);
|
||||||
// System.out.println("Lng: " + playerYacht.getLocation().getLng());
|
System.out.println("Lat: " + playerYacht.getLocation().getLat());
|
||||||
// System.out.println("-----------------------\n");
|
System.out.println("Lng: " + playerYacht.getLocation().getLng());
|
||||||
|
System.out.println("-----------------------\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void update() {
|
public static void update() {
|
||||||
|
|||||||
@@ -12,10 +12,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
import java.util.Observer;
|
import java.util.Observer;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.zip.CRC32;
|
import java.util.zip.CRC32;
|
||||||
import java.util.zip.Checksum;
|
import java.util.zip.Checksum;
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import seng302.models.Player;
|
import seng302.models.Player;
|
||||||
import seng302.models.Yacht;
|
import seng302.models.Yacht;
|
||||||
import seng302.models.stream.packets.PacketType;
|
import seng302.models.stream.packets.PacketType;
|
||||||
@@ -29,18 +28,11 @@ import seng302.server.messages.BoatStatus;
|
|||||||
import seng302.server.messages.BoatSubMessage;
|
import seng302.server.messages.BoatSubMessage;
|
||||||
import seng302.server.messages.Message;
|
import seng302.server.messages.Message;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.util.zip.CRC32;
|
|
||||||
import java.util.zip.Checksum;
|
|
||||||
import seng302.server.messages.RaceStatus;
|
import seng302.server.messages.RaceStatus;
|
||||||
import seng302.server.messages.RaceStatusMessage;
|
import seng302.server.messages.RaceStatusMessage;
|
||||||
import seng302.server.messages.RaceType;
|
import seng302.server.messages.RaceType;
|
||||||
import seng302.server.messages.XMLMessage;
|
import seng302.server.messages.XMLMessage;
|
||||||
import seng302.server.messages.XMLMessageSubType;
|
import seng302.server.messages.XMLMessageSubType;
|
||||||
import seng302.server.messages.XMLMessage;
|
|
||||||
import seng302.server.messages.XMLMessageSubType;
|
|
||||||
import seng302.utilities.GeoPoint;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class describing a single connection to a Client for the purposes of sending and receiving on
|
* A class describing a single connection to a Client for the purposes of sending and receiving on
|
||||||
@@ -306,7 +298,7 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
yacht.getLocation().getLat(),
|
yacht.getLocation().getLat(),
|
||||||
yacht.getLocation().getLng(),
|
yacht.getLocation().getLng(),
|
||||||
yacht.getHeading(),
|
yacht.getHeading(),
|
||||||
(long) yacht.getVelocity());
|
(long) yacht.getVelocityMMS());
|
||||||
|
|
||||||
sendMessage(boatLocationMessage);
|
sendMessage(boatLocationMessage);
|
||||||
}
|
}
|
||||||
@@ -348,7 +340,7 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(new RaceStatusMessage(1, raceStatus, startTime, GameState.getWindDirection(),
|
sendMessage(new RaceStatusMessage(1, raceStatus, startTime, GameState.getWindDirection(),
|
||||||
GameState.getWindSpeed().longValue(), GameState.getPlayers().size(),
|
GameState.getWindSpeedMMS().longValue(), GameState.getPlayers().size(),
|
||||||
RaceType.MATCH_RACE, 1, boatSubMessages));
|
RaceType.MATCH_RACE, 1, boatSubMessages));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import static seng302.utilities.GeoUtility.getGeoCoordinate;
|
|||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import seng302.client.ClientPacketParser;
|
import seng302.client.ClientPacketParser;
|
||||||
@@ -110,8 +111,8 @@ public class Yacht {
|
|||||||
this.position = "-";
|
this.position = "-";
|
||||||
this.sailIn = false;
|
this.sailIn = false;
|
||||||
this.location = new GeoPoint(57.670341, 11.826856);
|
this.location = new GeoPoint(57.670341, 11.826856);
|
||||||
this.heading = 120.0;
|
this.heading = 120.0; //In degrees
|
||||||
this.velocity = 50000.0;
|
this.velocity = 0d; //in mms-1
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,13 +121,14 @@ public class Yacht {
|
|||||||
public void update(Long timeInterval) {
|
public void update(Long timeInterval) {
|
||||||
if (sailIn) {
|
if (sailIn) {
|
||||||
Double secondsElapsed = timeInterval / 1000000.0;
|
Double secondsElapsed = timeInterval / 1000000.0;
|
||||||
Double thisHeading = ((double) Math.floorMod(heading.longValue(), 360L));
|
Double windSpeedKnots = GameState.getWindSpeedKnots();
|
||||||
Double windSpeedKnots = 0d;
|
Double trueWindAngle = Math.abs(GameState.getWindDirection() - heading);
|
||||||
Double boatSpeedInKnots = PolarTable.getBoatSpeed(windSpeedKnots, thisHeading);
|
Double boatSpeedInKnots = PolarTable.getBoatSpeed(windSpeedKnots, trueWindAngle);
|
||||||
velocity = boatSpeedInKnots / ClientPacketParser.MS_TO_KNOTS * 3000;
|
velocity = boatSpeedInKnots / ClientPacketParser.MS_TO_KNOTS * 1000;
|
||||||
//System.out.println("velocity = " + velocity);
|
|
||||||
Double metersCovered = velocity * secondsElapsed;
|
Double metersCovered = velocity * secondsElapsed;
|
||||||
location = getGeoCoordinate(location, heading, metersCovered);
|
location = getGeoCoordinate(location, heading, metersCovered);
|
||||||
|
} else {
|
||||||
|
velocity = 0d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,13 +138,16 @@ public class Yacht {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void adjustHeading(Double amount) {
|
public void adjustHeading(Double amount) {
|
||||||
|
Double newVal = heading + amount;
|
||||||
lastHeading = heading;
|
lastHeading = heading;
|
||||||
// TODO: 24/07/17 wmu16 - '%' in java does remainder, we need modulo. All this must be changed here, this is why we have neg values!
|
// TODO: 24/07/17 wmu16 - '%' in java does remainder, we need modulo. All this must be changed here, this is why we have neg values!
|
||||||
heading = (heading + amount) % 360.0;
|
heading = (double) Math.floorMod(newVal.longValue(), 360L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tackGybe(Double windDirection) {
|
public void tackGybe(Double windDirection) {
|
||||||
adjustHeading(-2 * ((heading - windDirection) % 360));
|
Double normalizedHeading = heading - GameState.windDirection;
|
||||||
|
normalizedHeading = (double) Math.floorMod(normalizedHeading.longValue(), 360);
|
||||||
|
adjustHeading(-2 * normalizedHeading);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleSailIn() {
|
public void toggleSailIn() {
|
||||||
@@ -150,7 +155,8 @@ public class Yacht {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void turnUpwind() {
|
public void turnUpwind() {
|
||||||
Double normalizedHeading = (heading - GameState.windDirection) % 360;
|
Double normalizedHeading = heading - GameState.windDirection;
|
||||||
|
normalizedHeading = (double) Math.floorMod(normalizedHeading.longValue(), 360);
|
||||||
if (normalizedHeading == 0) {
|
if (normalizedHeading == 0) {
|
||||||
if (lastHeading < 180) {
|
if (lastHeading < 180) {
|
||||||
adjustHeading(-TURN_STEP);
|
adjustHeading(-TURN_STEP);
|
||||||
@@ -171,7 +177,8 @@ public class Yacht {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void turnDownwind() {
|
public void turnDownwind() {
|
||||||
Double normalizedHeading = (heading - GameState.windDirection) % 360;
|
Double normalizedHeading = heading - GameState.windDirection;
|
||||||
|
normalizedHeading = (double) Math.floorMod(normalizedHeading.longValue(), 360);
|
||||||
if (normalizedHeading == 0) {
|
if (normalizedHeading == 0) {
|
||||||
if (lastHeading < 180) {
|
if (lastHeading < 180) {
|
||||||
adjustHeading(TURN_STEP);
|
adjustHeading(TURN_STEP);
|
||||||
@@ -191,6 +198,11 @@ public class Yacht {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void turnToVMG() {
|
||||||
|
// TODO: 25/07/17 wmu16 - Fix this so it grabs the optimal value from the optimal Polar
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String getBoatType() {
|
public String getBoatType() {
|
||||||
return boatType;
|
return boatType;
|
||||||
@@ -294,10 +306,14 @@ public class Yacht {
|
|||||||
this.markRoundTime = markRoundingTime;
|
this.markRoundTime = markRoundingTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getVelocity() {
|
public double getVelocityMMS() {
|
||||||
return velocity;
|
return velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Double getVelocityKnots() {
|
||||||
|
return velocity / 1000 * ClientPacketParser.MS_TO_KNOTS;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getTimeTillNext() {
|
public Long getTimeTillNext() {
|
||||||
return timeTillNext;
|
return timeTillNext;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ public class BoatLocationMessage extends Message {
|
|||||||
* @param boatSpeed The boats speed
|
* @param boatSpeed The boats speed
|
||||||
*/
|
*/
|
||||||
public BoatLocationMessage(int sourceId, int sequenceNum, double latitude, double longitude, double heading, long boatSpeed){
|
public BoatLocationMessage(int sourceId, int sequenceNum, double latitude, double longitude, double heading, long boatSpeed){
|
||||||
boatSpeed /= 10;
|
|
||||||
messageVersionNumber = 1;
|
messageVersionNumber = 1;
|
||||||
time = System.currentTimeMillis();
|
time = System.currentTimeMillis();
|
||||||
this.sourceId = sourceId;
|
this.sourceId = sourceId;
|
||||||
|
|||||||
Reference in New Issue
Block a user