mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Boat now changes color when it is bumped for a time
ClientYacht: Added ColorChangeListener from GameView3D to re paint the boat when the color attribute is changed #story[1293]
This commit is contained in:
@@ -60,7 +60,7 @@ public class GameState implements Runnable {
|
|||||||
//Powerup Constants
|
//Powerup Constants
|
||||||
private static final Integer VELOCITY_BOOST_MULTIPLIER = 2;
|
private static final Integer VELOCITY_BOOST_MULTIPLIER = 2;
|
||||||
private static final Integer HANDLING_BOOST_MULTIPLIER = 2;
|
private static final Integer HANDLING_BOOST_MULTIPLIER = 2;
|
||||||
private static final Long BUMPER_DISABLE_TIME = 5_000L;
|
public static final Long BUMPER_DISABLE_TIME = 5_000L;
|
||||||
|
|
||||||
private static Long previousUpdateTime;
|
private static Long previousUpdateTime;
|
||||||
public static Double windDirection;
|
public static Double windDirection;
|
||||||
@@ -359,8 +359,8 @@ public class GameState implements Runnable {
|
|||||||
|
|
||||||
//Get a random token location with random type
|
//Get a random token location with random type
|
||||||
Token token = allTokens.get(random.nextInt(allTokens.size()));
|
Token token = allTokens.get(random.nextInt(allTokens.size()));
|
||||||
// token.assignRandomType();
|
token.assignRandomType();
|
||||||
token.assignType(TokenType.BUMPER);
|
// token.assignType(TokenType.BUMPER);
|
||||||
|
|
||||||
logger.debug("Spawned token of type " + token.getTokenType());
|
logger.debug("Spawned token of type " + token.getTokenType());
|
||||||
|
|
||||||
@@ -386,8 +386,7 @@ public class GameState implements Runnable {
|
|||||||
updateVelocity(yacht);
|
updateVelocity(yacht);
|
||||||
yacht.runAutoPilot();
|
yacht.runAutoPilot();
|
||||||
yacht.updateLocation(timeInterval);
|
yacht.updateLocation(timeInterval);
|
||||||
preformTokenUpdates(
|
preformTokenUpdates(yacht); //This update must be done before collision. Sorta hacky
|
||||||
yacht); //This update must be done before collision. Sorry sorta hacky rn.
|
|
||||||
checkCollision(yacht);
|
checkCollision(yacht);
|
||||||
if (yacht.getBoatStatus() != BoatStatus.FINISHED) {
|
if (yacht.getBoatStatus() != BoatStatus.FINISHED) {
|
||||||
checkForLegProgression(yacht);
|
checkForLegProgression(yacht);
|
||||||
@@ -424,7 +423,7 @@ public class GameState implements Runnable {
|
|||||||
boatTempShutDown(collidedYacht);
|
boatTempShutDown(collidedYacht);
|
||||||
notifyMessageListeners(MessageFactory.makePowerDownMessage(yacht));
|
notifyMessageListeners(MessageFactory.makePowerDownMessage(yacht));
|
||||||
notifyMessageListeners(
|
notifyMessageListeners(
|
||||||
MessageFactory.makeStatusEffectMessage(yacht, powerUp));
|
MessageFactory.makeStatusEffectMessage(collidedYacht, powerUp));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,17 +39,21 @@ public class ClientYacht extends Observable {
|
|||||||
void notifyRounding(ClientYacht yacht, int legNumber);
|
void notifyRounding(ClientYacht yacht, int legNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface ColorChangeListener {
|
||||||
|
|
||||||
|
void notifyColorChange(ClientYacht yacht);
|
||||||
|
}
|
||||||
|
|
||||||
//This notifies RaceViewController so it can display icon - wmu16
|
//This notifies RaceViewController so it can display icon - wmu16
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface PowerUpListener {
|
public interface PowerUpListener {
|
||||||
|
|
||||||
void notifyPowerUp(ClientYacht yacht, TokenType tokenType);
|
void notifyPowerUp(ClientYacht yacht, TokenType tokenType);
|
||||||
}
|
}
|
||||||
|
|
||||||
//This notifies RaceViewController so it can remove token icon - wmu16
|
//This notifies RaceViewController so it can remove token icon - wmu16
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface PowerDownListener {
|
public interface PowerDownListener {
|
||||||
|
|
||||||
void notifyPowerDown(ClientYacht yacht);
|
void notifyPowerDown(ClientYacht yacht);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +86,7 @@ public class ClientYacht extends Observable {
|
|||||||
private List<MarkRoundingListener> markRoundingListeners = new ArrayList<>();
|
private List<MarkRoundingListener> markRoundingListeners = new ArrayList<>();
|
||||||
private List<PowerUpListener> powerUpListeners = new ArrayList<>();
|
private List<PowerUpListener> powerUpListeners = new ArrayList<>();
|
||||||
private List<PowerDownListener> powerDownListeners = new ArrayList<>();
|
private List<PowerDownListener> powerDownListeners = new ArrayList<>();
|
||||||
|
private List<ColorChangeListener> colorChangeListeners = new ArrayList<>();
|
||||||
|
|
||||||
private ReadOnlyDoubleWrapper velocityProperty = new ReadOnlyDoubleWrapper();
|
private ReadOnlyDoubleWrapper velocityProperty = new ReadOnlyDoubleWrapper();
|
||||||
private ReadOnlyLongWrapper timeTillNextProperty = new ReadOnlyLongWrapper();
|
private ReadOnlyLongWrapper timeTillNextProperty = new ReadOnlyLongWrapper();
|
||||||
@@ -224,6 +229,9 @@ public class ClientYacht extends Observable {
|
|||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Powers down the boat and notifies the raceViewController to display
|
||||||
|
*/
|
||||||
public void powerDown() {
|
public void powerDown() {
|
||||||
this.powerUp = null;
|
this.powerUp = null;
|
||||||
for (PowerDownListener listener : powerDownListeners) {
|
for (PowerDownListener listener : powerDownListeners) {
|
||||||
@@ -231,6 +239,11 @@ public class ClientYacht extends Observable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* powers up the boat and notifies the raceViewController to display
|
||||||
|
*
|
||||||
|
* @param tokenType The type of token that this boat is being powered up with
|
||||||
|
*/
|
||||||
public void setPowerUp(TokenType tokenType) {
|
public void setPowerUp(TokenType tokenType) {
|
||||||
this.powerUp = tokenType;
|
this.powerUp = tokenType;
|
||||||
for (PowerUpListener listener : powerUpListeners) {
|
for (PowerUpListener listener : powerUpListeners) {
|
||||||
@@ -290,6 +303,9 @@ public class ClientYacht extends Observable {
|
|||||||
|
|
||||||
public void setColour(Color colour) {
|
public void setColour(Color colour) {
|
||||||
this.colour = colour;
|
this.colour = colour;
|
||||||
|
for (ColorChangeListener listener : colorChangeListeners) {
|
||||||
|
listener.notifyColorChange(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -319,6 +335,10 @@ public class ClientYacht extends Observable {
|
|||||||
powerDownListeners.add(listener);
|
powerDownListeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addColorChangeListener(ColorChangeListener listener) {
|
||||||
|
colorChangeListeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
public void removeMarkRoundingListener(MarkRoundingListener listener) {
|
public void removeMarkRoundingListener(MarkRoundingListener listener) {
|
||||||
markRoundingListeners.remove(listener);
|
markRoundingListeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
@@ -19,6 +21,7 @@ import javafx.scene.control.Alert.AlertType;
|
|||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
import javafx.util.Pair;
|
import javafx.util.Pair;
|
||||||
import seng302.gameServer.GameStages;
|
import seng302.gameServer.GameStages;
|
||||||
import seng302.gameServer.GameState;
|
import seng302.gameServer.GameState;
|
||||||
@@ -413,12 +416,12 @@ public class GameClient {
|
|||||||
ClientYacht thisYacht = allBoatsMap.get(yachtEventData.getSubjectId().intValue());
|
ClientYacht thisYacht = allBoatsMap.get(yachtEventData.getSubjectId().intValue());
|
||||||
|
|
||||||
if (yachtEventData.getEventId() == YachtEventType.COLLISION.getCode()) {
|
if (yachtEventData.getEventId() == YachtEventType.COLLISION.getCode()) {
|
||||||
showCollisionAlert(yachtEventData);
|
showCollisionAlert(thisYacht);
|
||||||
} else if (yachtEventData.getEventId() == YachtEventType.POWER_DOWN.getCode()) {
|
} else if (yachtEventData.getEventId() == YachtEventType.POWER_DOWN.getCode()) {
|
||||||
thisYacht.powerDown();
|
thisYacht.powerDown();
|
||||||
Sounds.playTokenPickupSound(); // TODO: 23/09/17 This should be power down sound
|
Sounds.playTokenPickupSound(); // TODO: 23/09/17 This should be power down sound
|
||||||
} else if (yachtEventData.getEventId() == YachtEventType.BUMPER_CRASH.getCode()) {
|
} else if (yachtEventData.getEventId() == YachtEventType.BUMPER_CRASH.getCode()) {
|
||||||
// TODO: 23/09/17 notify the client that the yacht has been disabled
|
showDisableAlert(thisYacht);
|
||||||
} else {
|
} else {
|
||||||
TokenType tokenType = null;
|
TokenType tokenType = null;
|
||||||
if (yachtEventData.getEventId() == YachtEventType.TOKEN_VELOCITY.getCode()) {
|
if (yachtEventData.getEventId() == YachtEventType.TOKEN_VELOCITY.getCode()) {
|
||||||
@@ -438,16 +441,31 @@ public class GameClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns a disabled boat black until the bumper affect wears off
|
||||||
|
*
|
||||||
|
* @param yacht The yacht to show as disabled
|
||||||
|
*/
|
||||||
|
private void showDisableAlert(ClientYacht yacht) {
|
||||||
|
Color originalColor = yacht.getColour();
|
||||||
|
yacht.setColour(Color.BLACK);
|
||||||
|
|
||||||
|
Timer disableTimer = new Timer("Disable Timer");
|
||||||
|
disableTimer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
yacht.setColour(originalColor);
|
||||||
|
}
|
||||||
|
}, GameState.BUMPER_DISABLE_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells race view to show a collision animation.
|
* Tells race view to show a collision animation.
|
||||||
*/
|
*/
|
||||||
private void showCollisionAlert(YachtEventData yachtEventData) {
|
private void showCollisionAlert(ClientYacht yacht) {
|
||||||
Sounds.playCrashSound();
|
Sounds.playCrashSound();
|
||||||
raceState.storeCollision(
|
raceState.storeCollision(yacht);
|
||||||
allBoatsMap.get(
|
|
||||||
yachtEventData.getSubjectId().intValue()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: 11/09/17 wmu16 - Add in functionality to viually indicate a pickup to a user
|
// TODO: 11/09/17 wmu16 - Add in functionality to viually indicate a pickup to a user
|
||||||
|
|||||||
@@ -467,11 +467,8 @@ public class GameView3D {
|
|||||||
wakesGroup.getChildren().add(newBoat.getWake());
|
wakesGroup.getChildren().add(newBoat.getWake());
|
||||||
wakes.add(newBoat.getWake());
|
wakes.add(newBoat.getWake());
|
||||||
boatObjectGroup.getChildren().add(newBoat);
|
boatObjectGroup.getChildren().add(newBoat);
|
||||||
clientYacht.addLocationListener((boat, lat, lon, heading, sailIn, velocity) -> {
|
clientYacht.addLocationListener(this::updateBoatLocation);
|
||||||
BoatObject bo = boatObjects.get(boat);
|
clientYacht.addColorChangeListener(this::updateBoatColor);
|
||||||
Point2D p2d = findScaledXY(lat, lon);
|
|
||||||
bo.moveTo(p2d.getX(), p2d.getY(), heading, velocity, sailIn, windDir);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
gameObjects.getChildren().addAll(wakes);
|
gameObjects.getChildren().addAll(wakes);
|
||||||
@@ -483,6 +480,23 @@ public class GameView3D {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the boatObjects color with that of the clientYachts object. Used in notification from
|
||||||
|
* a listener on this attribute in clientYacht to re paint the boat mesh
|
||||||
|
*
|
||||||
|
* @param clientYacht The yacht to update the colour for
|
||||||
|
*/
|
||||||
|
private void updateBoatColor(ClientYacht clientYacht) {
|
||||||
|
boatObjects.get(clientYacht).setFill(clientYacht.getColour());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBoatLocation(ClientYacht boat, Double lat, Double lon, Double heading,
|
||||||
|
Boolean sailIn, Double velocity) {
|
||||||
|
BoatObject bo = boatObjects.get(boat);
|
||||||
|
Point2D p2d = findScaledXY(lat, lon);
|
||||||
|
bo.moveTo(p2d.getX(), p2d.getY(), heading, velocity, sailIn, windDir);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a border to the GameView and rescales to the size of the border, does not rescale if a
|
* Adds a border to the GameView and rescales to the size of the border, does not rescale if a
|
||||||
* border already exists. Assumes the border is larger than the course.
|
* border already exists. Assumes the border is larger than the course.
|
||||||
|
|||||||
Reference in New Issue
Block a user