Packets are sent out when collision happens and receiver is able to interpret and display as visual alert. Updated visual alert to looks better.

- Created yacht event code message to be sent out as packet.
- Added observers to main server thread on yacht so when collision detected, main server thread will send out yacht event message to all server to client threads.
- Updated collision visual alert using circle and animation timer.

#story[1117]
This commit is contained in:
Zhi You Tan
2017-08-10 19:50:30 +12:00
parent 07386ed2db
commit 7e1686a980
6 changed files with 119 additions and 25 deletions
@@ -342,8 +342,8 @@ public class GameClient {
* Tells race view to show a collision animation.
*/
private void showCollisionAlert(YachtEventData yachtEventData) {
// 1 is used by team 28 to show collision
if (yachtEventData.getEventId() == 1) {
// 33 is the agreed code to show collision
if (yachtEventData.getEventId() == 33) {
raceView.showCollision(yachtEventData.getSubjectId());
}
}
+27 -17
View File
@@ -6,13 +6,16 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import javafx.animation.Animation;
import javafx.animation.AnimationTimer;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Point2D;
import javafx.scene.Group;
@@ -24,6 +27,7 @@ import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.StrokeType;
import javafx.scene.text.Text;
import javafx.util.Duration;
import seng302.model.Colors;
@@ -616,26 +620,32 @@ public class GameView extends Pane {
*/
public void drawCollision(GeoPoint collisionPoint) {
System.out.println("ran");
Point2D point = findScaledXY(collisionPoint);
Circle circle = new Circle(point.getX(), point.getY(), 10.0, Color.RED);
gameObjects.add(circle);
Platform.runLater(() -> {
Point2D point = findScaledXY(collisionPoint);
double circleRadius = 0.0;
Circle circle = new Circle(point.getX(), point.getY(), circleRadius, Color.RED);
gameObjects.add(circle);
Timeline timeline = new Timeline();
timeline.setCycleCount(1);
EventHandler<ActionEvent> blink = (ActionEvent event) -> {
if (circle.getFill() == Color.RED) {
circle.setFill(Color.TRANSPARENT);
} else {
circle.setFill(Color.RED);
}
System.out.println("beep boop");
};
circle.setFill(Color.TRANSPARENT);
circle.setStroke(Color.RED);
circle.setStrokeWidth(3);
KeyFrame keyframe = new KeyFrame(Duration.millis(200), blink);
Timeline timeline = new Timeline();
timeline.setCycleCount(1);
timeline.getKeyFrames().add(keyframe);
timeline.play();
KeyFrame keyframe1 = new KeyFrame(Duration.ZERO,
new KeyValue(circle.radiusProperty(), 0),
new KeyValue(circle.strokeProperty(), Color.TRANSPARENT));
KeyFrame keyFrame2 = new KeyFrame(new Duration(1000),
new KeyValue(circle.radiusProperty(), 50),
new KeyValue(circle.strokeProperty(), Color.RED));
KeyFrame keyFrame3 = new KeyFrame(new Duration(1500),
new KeyValue(circle.strokeProperty(), Color.TRANSPARENT));
// gameObjects.remove(circle);
timeline.getKeyFrames().addAll(keyframe1, keyFrame2, keyFrame3);
timeline.play();
timeline.setOnFinished(event -> gameObjects.remove(circle));
});
}
}