diff --git a/.gitignore b/.gitignore index b02048b..e20c7de 100644 --- a/.gitignore +++ b/.gitignore @@ -147,3 +147,6 @@ /Semester 3/Assignments/RecursionDemo/target/ /Semester 3/Assignments/lab5-recursion2_CalebFontenot/target/ +/Semester 3/Assignments/MP2-chapter4_CalebFontenot/build/ +/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/private/ +/Semester 3/Assignments/MP2-chapter4_CalebFontenot/dist/ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/.~lock.mp2.doc# b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/.~lock.mp2.doc# new file mode 100644 index 0000000..9e58b51 --- /dev/null +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/.~lock.mp2.doc# @@ -0,0 +1 @@ +,caleb,caleb-ryzen-archlinux,05.09.2023 14:05,file:///home/caleb/.config/libreoffice/4; \ No newline at end of file diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/PrintedHTMLs/BallControl.html b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/PrintedHTMLs/BallControl.html new file mode 100644 index 0000000..cfd18d4 --- /dev/null +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/PrintedHTMLs/BallControl.html @@ -0,0 +1,95 @@ + + + +BallControl.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BallControl.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package MP2_chapter4_CalebFontenot;
+
+import javafx.application.Application;
+import javafx.event.EventHandler;
+import javafx.scene.Scene;
+import javafx.scene.input.KeyCode;
+import javafx.scene.input.MouseEvent;
+import javafx.stage.Stage;
+
+/**
+ *
+ * @author caleb
+ */
+public class BallControl extends Application {
+
+    @Override
+    public void start(Stage primaryStage) throws Exception {
+
+        BouncingBall bouncingBall = new BouncingBall();
+        // Create a scene and place it in the stage
+        Scene scene = new Scene(bouncingBall, 800, 600);
+        primaryStage.setTitle("Bouncing Ball Control");
+        primaryStage.setScene(scene);
+        primaryStage.show();
+        bouncingBall.requestFocus();
+        bouncingBall.setOnMouseEntered(e
+                -> {
+            bouncingBall.hideInfoLabel();
+            bouncingBall.play();
+        });
+
+        bouncingBall.setOnMouseExited(e -> {
+                bouncingBall.showInfoLabel();
+                bouncingBall.pause();
+        });
+        bouncingBall.setOnMouseMoved(new EventHandler<MouseEvent>() {
+            @Override
+            public void handle(MouseEvent event) {
+                double mouseX = event.getSceneX() - (bouncingBall.RACKET_LENGTH / 2); // set relative to center of racket
+                bouncingBall.moveRacket(mouseX);
+            }
+
+        });
+
+        // Increase and decrease animation
+        bouncingBall.setOnKeyPressed(e
+                -> {
+            if (e.getCode() == KeyCode.UP) {
+                bouncingBall.increaseSpeed();
+            } else if (e.getCode() == KeyCode.DOWN) {
+                bouncingBall.decreaseSpeed();
+            }
+
+        }
+        );
+    }
+
+    public static void main(String[] args) {
+        launch(args);
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/PrintedHTMLs/BouncingBall.html b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/PrintedHTMLs/BouncingBall.html new file mode 100644 index 0000000..3231397 --- /dev/null +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/PrintedHTMLs/BouncingBall.html @@ -0,0 +1,204 @@ + + + +BouncingBall.java + + + + +
/home/caleb/ASDV-Java/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BouncingBall.java
+
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package MP2_chapter4_CalebFontenot;
+
+import java.io.File;
+import javafx.animation.KeyFrame;
+import javafx.animation.Timeline;
+import javafx.beans.property.DoubleProperty;
+import javafx.event.ActionEvent;
+import javafx.event.EventHandler;
+import javafx.geometry.Pos;
+import javafx.scene.control.Label;
+import javafx.scene.layout.GridPane;
+import javafx.scene.layout.Pane;
+import javafx.scene.media.Media;
+import javafx.scene.media.MediaPlayer;
+import javafx.scene.paint.Color;
+import javafx.scene.shape.Circle;
+import javafx.scene.shape.Rectangle;
+import javafx.util.Duration;
+
+/**
+ *
+ * @author caleb
+ */
+public class BouncingBall extends Pane {
+
+    GridPane textPane = new GridPane();
+    private long timeSinceLastCollisionEvent = 0;
+    final double RACKET_LENGTH = 100;
+    final double radius = 20;
+    private double x = radius, y = radius;
+    private double dx = 1, dy = 1;
+    private Circle circle = new Circle(x, y, radius);
+    private Rectangle racket = new Rectangle(RACKET_LENGTH, 20);
+    private Label infoLabel = new Label("Your mouse cursor must be inside the bounds of the window to play!");
+    private Label racketTime = new Label();
+    private Label ballCords = new Label();
+    private Label playerScoreLabel = new Label("Player Score: 0");
+    private Label computerScoreLabel = new Label("Computer Score: 0");
+
+
+
+    private Timeline animation;
+
+    private int computerScore, playerScore = 0;
+
+    public BouncingBall() {
+        circle.setFill(Color.RED); // Set ball color
+        racket.setFill(Color.BLUE);
+        textPane.add(racketTime, 0, 0);
+        textPane.add(ballCords, 0, 1);
+        textPane.add(playerScoreLabel, 0, 2);
+        textPane.add(computerScoreLabel, 0, 3);
+        getChildren().addAll(circle, racket, textPane, infoLabel); // Place a ball into this pane
+        racket.relocate(0, 580);
+        infoLabel.relocate(getHeight() / 4.0, getWidth() / 2.0);
+        // Create an animation for moving the ball
+        animation = new Timeline(new KeyFrame(Duration.millis(1), new EventHandler<ActionEvent>() {
+            @Override
+            public void handle(ActionEvent t) {
+                timeSinceLastCollisionEvent++;
+                racketTime.setText("Frames since last collision: " + timeSinceLastCollisionEvent);
+                moveBall();
+                if (y >= (getHeight() - 20) && (timeSinceLastCollisionEvent > 500)) {
+                    timeSinceLastCollisionEvent = 0;
+                    incrementComputerScore();
+                }
+            }
+        })
+        );
+        animation.setRate(animation.getRate() * .5);
+        animation.setCycleCount(Timeline.INDEFINITE);
+
+    }
+
+    private boolean processRacketCollision() {
+        boolean racketCollision = racket.getBoundsInParent().intersects(circle.getBoundsInParent());
+
+        if (racketCollision && (timeSinceLastCollisionEvent > 500)) { // This is second condition is a cooldown. It prevents odd behavior happening with the ball and the racket if the racket hits the ball at certain angles.
+            System.out.println("Racket collision detected!");
+            timeSinceLastCollisionEvent = 0;
+            incrementPlayerScore();
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private void moveBall() {
+
+        // Check boundaries
+        if (x < radius || x > getWidth() - radius) {
+            dx *= -1; // Change ball move direction
+        }
+        if (y < radius || y > getHeight() - radius || processRacketCollision()) {
+            dy *= -1; // Change ball move direction
+        }
+
+        // Adjust ball position by 1 or -1
+        x += dx;
+        y += dy;
+        circle.setCenterX(x);
+        circle.setCenterY(y);
+        ballCoordsToLabel();
+    }
+
+    public void play() {
+        animation.play();
+    }
+
+    public void pause() {
+        animation.pause();
+    }
+
+    public void increaseSpeed() {
+        animation.setRate(animation.getRate() * 1.5);
+        System.out.println(animation.getRate());
+    }
+
+    public void decreaseSpeed() {
+        animation.setRate(animation.getRate() * 1.5 > 0 ? animation.getRate() / 1.5 : 0);
+        System.out.println(animation.getRate());
+    }
+
+    public DoubleProperty rateProperty() {
+        return animation.rateProperty();
+    }
+
+    public void moveRacket(double x) {
+        racket.relocate(x, 580);
+    }
+
+    public void showInfoLabel() {
+        double paneHeight = getHeight();
+        double paneWidth = getWidth();
+        getChildren().add(infoLabel);
+        // Center Text
+        infoLabel.relocate(paneWidth / 4.0, paneHeight / 2.0);
+    }
+
+    public void hideInfoLabel() {
+        getChildren().remove(infoLabel);
+    }
+
+    private void incrementPlayerScore() {
+        playerScoreLabel.setText("Player score: " + ++playerScore);
+        playSound();
+    }
+
+    private void incrementComputerScore() {
+        computerScoreLabel.setText("Computer score: " + ++computerScore);
+        //playSound();
+    }
+
+    private void ballCoordsToLabel() {
+        ballCords.setText("Ball coords: " + x + ", " + y);
+    }
+    private void playSound() {
+        int randInt = (int) (Math.random() * 2);
+        String sample;
+        if (randInt == 0) {
+            sample = "5";
+        } else  {
+            sample = "7";
+        }
+        Media sound = new Media(new File("sound/Sample_000"+sample+".wav").toURI().toString());
+        MediaPlayer mediaPlayer = new MediaPlayer(sound);
+        mediaPlayer.setStartTime(Duration.ZERO);
+        mediaPlayer.play();
+        //mediaPlayer.setOnEndOfMedia();
+    }
+}
+
+
+ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/build.xml b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/build.xml new file mode 100644 index 0000000..be2040d --- /dev/null +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/build.xml @@ -0,0 +1,53 @@ + + Builds, tests, and runs the project lab3_CalebFontenot. + + + diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/manifest.mf b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/mp2.doc b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/mp2.doc new file mode 100644 index 0000000..59cc831 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/mp2.doc differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/build-impl.xml b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/build-impl.xml new file mode 100644 index 0000000..19de470 --- /dev/null +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/build-impl.xml @@ -0,0 +1,1800 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set platform.home + Must set platform.bootcp + Must set platform.java + Must set platform.javac + + The J2SE Platform is not correctly set up. + Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files. + Either open the project in the IDE and setup the Platform with the same name or add it manually. + For example like this: + ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file) + or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + ${platform.java} -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/configs/Run_as_WebStart.properties b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/configs/Run_as_WebStart.properties new file mode 100644 index 0000000..670fff0 --- /dev/null +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/configs/Run_as_WebStart.properties @@ -0,0 +1,2 @@ +# Do not modify this property in this configuration. It can be re-generated. +$label=Run as WebStart diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/configs/Run_in_Browser.properties b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/configs/Run_in_Browser.properties new file mode 100644 index 0000000..f2a5a65 --- /dev/null +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/configs/Run_in_Browser.properties @@ -0,0 +1,2 @@ +# Do not modify this property in this configuration. It can be re-generated. +$label=Run in Browser diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/genfiles.properties b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/genfiles.properties new file mode 100644 index 0000000..030ec63 --- /dev/null +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=7c5d606e +build.xml.script.CRC32=f4beac8b +build.xml.stylesheet.CRC32=f85dc8f2@1.107.0.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=1d3703fe +nbproject/build-impl.xml.script.CRC32=4d538bea +nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.107.0.48 diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/jfx-impl.xml b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/jfx-impl.xml new file mode 100644 index 0000000..6aeb313 --- /dev/null +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/jfx-impl.xml @@ -0,0 +1,4197 @@ + + + + + JavaFX-specific Ant calls + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${cssfileslist} + + + + + + + + + + + + + + + + + + + + + + + + self.addMappedName( + (source.indexOf("jfxrt.jar") >= 0) || + (source.indexOf("deploy.jar") >= 0) || + (source.indexOf("javaws.jar") >= 0) || + (source.indexOf("plugin.jar") >= 0) + ? "" : source + ); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/project.properties b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/project.properties new file mode 100644 index 0000000..dbc5a47 --- /dev/null +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/project.properties @@ -0,0 +1,124 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=MP2-chapter4_CalebFontenot +application.vendor=caleb +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +compile.on.save=true +compile.on.save.unsupported.javafx=true +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/MP2-chapter4_CalebFontenot.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +# Non-JavaFX jar file creation is deactivated in JavaFX 2.0+ projects +jar.archive.disabled=true +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=false +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +javafx.application.implementation.version=1.0 +javafx.binarycss=false +javafx.deploy.allowoffline=true +# If true, application update mode is set to 'background', if false, update mode is set to 'eager' +javafx.deploy.backgroundupdate=false +javafx.deploy.embedJNLP=true +javafx.deploy.includeDT=true +# Set true to prevent creation of temporary copy of deployment artifacts before each run (disables concurrent runs) +javafx.disable.concurrent.runs=false +# Set true to enable multiple concurrent runs of the same WebStart or Run-in-Browser project +javafx.enable.concurrent.external.runs=false +# This is a JavaFX project +javafx.enabled=true +javafx.fallback.class=com.javafx.main.NoJavaFXFallback +# Main class for JavaFX +javafx.main.class=MP2_chapter4_CalebFontenot.BallControl +javafx.preloader.class= +# This project does not use Preloader +javafx.preloader.enabled=false +javafx.preloader.jar.filename= +javafx.preloader.jar.path= +javafx.preloader.project.path= +javafx.preloader.type=none +# Set true for GlassFish only. Rebases manifest classpaths of JARs in lib dir. Not usable with signed JARs. +javafx.rebase.libs=false +javafx.run.height=600 +javafx.run.width=800 +jlink.launcher=false +jlink.launcher.name=MP2-chapter4_CalebFontenot +# Pre-JavaFX 2.0 WebStart is deactivated in JavaFX 2.0+ projects +jnlp.enabled=false +# Main class for Java launcher +main.class=com.javafx.main.Main +# For improved security specify narrower Codebase manifest attribute to prevent RIAs from being repurposed +manifest.custom.codebase=* +# Specify Permissions manifest attribute to override default (choices: sandbox, all-permissions) +manifest.custom.permissions= +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=JDK_8__System_ +run.classpath=\ + ${dist.jar}:\ + ${javac.classpath}:\ + ${build.classes.dir} +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/project.xml b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/project.xml new file mode 100644 index 0000000..67bdf69 --- /dev/null +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/project.xml @@ -0,0 +1,26 @@ + + + org.netbeans.modules.java.j2seproject + + + + + + + + + + + + + MP2-chapter4_CalebFontenot + + + + + + + + + + diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0005.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0005.wav new file mode 100644 index 0000000..9a4ac42 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0005.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0007.wav b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0007.wav new file mode 100644 index 0000000..6a092d3 Binary files /dev/null and b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/sound/Sample_0007.wav differ diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BallControl.java b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BallControl.java new file mode 100644 index 0000000..24cfe5a --- /dev/null +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BallControl.java @@ -0,0 +1,65 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package MP2_chapter4_CalebFontenot; + +import javafx.application.Application; +import javafx.event.EventHandler; +import javafx.scene.Scene; +import javafx.scene.input.KeyCode; +import javafx.scene.input.MouseEvent; +import javafx.stage.Stage; + +/** + * + * @author caleb + */ +public class BallControl extends Application { + + @Override + public void start(Stage primaryStage) throws Exception { + + BouncingBall bouncingBall = new BouncingBall(); + // Create a scene and place it in the stage + Scene scene = new Scene(bouncingBall, 800, 600); + primaryStage.setTitle("Bouncing Ball Control"); + primaryStage.setScene(scene); + primaryStage.show(); + bouncingBall.requestFocus(); + bouncingBall.setOnMouseEntered(e + -> { + bouncingBall.hideInfoLabel(); + bouncingBall.play(); + }); + + bouncingBall.setOnMouseExited(e -> { + bouncingBall.showInfoLabel(); + bouncingBall.pause(); + }); + bouncingBall.setOnMouseMoved(new EventHandler() { + @Override + public void handle(MouseEvent event) { + double mouseX = event.getSceneX() - (bouncingBall.RACKET_LENGTH / 2); // set relative to center of racket + bouncingBall.moveRacket(mouseX); + } + + }); + + // Increase and decrease animation + bouncingBall.setOnKeyPressed(e + -> { + if (e.getCode() == KeyCode.UP) { + bouncingBall.increaseSpeed(); + } else if (e.getCode() == KeyCode.DOWN) { + bouncingBall.decreaseSpeed(); + } + + } + ); + } + + public static void main(String[] args) { + launch(args); + } +} diff --git a/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BouncingBall.java b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BouncingBall.java new file mode 100644 index 0000000..b9c125f --- /dev/null +++ b/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BouncingBall.java @@ -0,0 +1,175 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package MP2_chapter4_CalebFontenot; + +import java.io.File; +import javafx.animation.KeyFrame; +import javafx.animation.Timeline; +import javafx.beans.property.DoubleProperty; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.geometry.Pos; +import javafx.scene.control.Label; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.Pane; +import javafx.scene.media.Media; +import javafx.scene.media.MediaPlayer; +import javafx.scene.paint.Color; +import javafx.scene.shape.Circle; +import javafx.scene.shape.Rectangle; +import javafx.util.Duration; + +/** + * + * @author caleb + */ +public class BouncingBall extends Pane { + + GridPane textPane = new GridPane(); + private long timeSinceLastCollisionEvent = 0; + final double RACKET_LENGTH = 100; + final double radius = 20; + private double x = radius, y = radius; + private double dx = 1, dy = 1; + private Circle circle = new Circle(x, y, radius); + private Rectangle racket = new Rectangle(RACKET_LENGTH, 20); + private Label infoLabel = new Label("Your mouse cursor must be inside the bounds of the window to play!"); + private Label racketTime = new Label(); + private Label ballCords = new Label(); + private Label playerScoreLabel = new Label("Player Score: 0"); + private Label computerScoreLabel = new Label("Computer Score: 0"); + + + + private Timeline animation; + + private int computerScore, playerScore = 0; + + public BouncingBall() { + circle.setFill(Color.RED); // Set ball color + racket.setFill(Color.BLUE); + textPane.add(racketTime, 0, 0); + textPane.add(ballCords, 0, 1); + textPane.add(playerScoreLabel, 0, 2); + textPane.add(computerScoreLabel, 0, 3); + getChildren().addAll(circle, racket, textPane, infoLabel); // Place a ball into this pane + racket.relocate(0, 580); + infoLabel.relocate(getHeight() / 4.0, getWidth() / 2.0); + // Create an animation for moving the ball + animation = new Timeline(new KeyFrame(Duration.millis(1), new EventHandler() { + @Override + public void handle(ActionEvent t) { + timeSinceLastCollisionEvent++; + racketTime.setText("Frames since last collision: " + timeSinceLastCollisionEvent); + moveBall(); + if (y >= (getHeight() - 20) && (timeSinceLastCollisionEvent > 500)) { + timeSinceLastCollisionEvent = 0; + incrementComputerScore(); + } + } + }) + ); + animation.setRate(animation.getRate() * .5); + animation.setCycleCount(Timeline.INDEFINITE); + + } + + private boolean processRacketCollision() { + boolean racketCollision = racket.getBoundsInParent().intersects(circle.getBoundsInParent()); + + if (racketCollision && (timeSinceLastCollisionEvent > 500)) { // This is second condition is a cooldown. It prevents odd behavior happening with the ball and the racket if the racket hits the ball at certain angles. + System.out.println("Racket collision detected!"); + timeSinceLastCollisionEvent = 0; + incrementPlayerScore(); + return true; + } else { + return false; + } + } + + private void moveBall() { + + // Check boundaries + if (x < radius || x > getWidth() - radius) { + dx *= -1; // Change ball move direction + } + if (y < radius || y > getHeight() - radius || processRacketCollision()) { + dy *= -1; // Change ball move direction + } + + // Adjust ball position by 1 or -1 + x += dx; + y += dy; + circle.setCenterX(x); + circle.setCenterY(y); + ballCoordsToLabel(); + } + + public void play() { + animation.play(); + } + + public void pause() { + animation.pause(); + } + + public void increaseSpeed() { + animation.setRate(animation.getRate() * 1.5); + System.out.println(animation.getRate()); + } + + public void decreaseSpeed() { + animation.setRate(animation.getRate() * 1.5 > 0 ? animation.getRate() / 1.5 : 0); + System.out.println(animation.getRate()); + } + + public DoubleProperty rateProperty() { + return animation.rateProperty(); + } + + public void moveRacket(double x) { + racket.relocate(x, 580); + } + + public void showInfoLabel() { + double paneHeight = getHeight(); + double paneWidth = getWidth(); + getChildren().add(infoLabel); + // Center Text + infoLabel.relocate(paneWidth / 4.0, paneHeight / 2.0); + } + + public void hideInfoLabel() { + getChildren().remove(infoLabel); + } + + private void incrementPlayerScore() { + playerScoreLabel.setText("Player score: " + ++playerScore); + playSound(); + } + + private void incrementComputerScore() { + computerScoreLabel.setText("Computer score: " + ++computerScore); + //playSound(); + } + + private void ballCoordsToLabel() { + ballCords.setText("Ball coords: " + x + ", " + y); + } + private void playSound() { + int randInt = (int) (Math.random() * 2); + String sample; + if (randInt == 0) { + sample = "5"; + } else { + sample = "7"; + } + Media sound = new Media(new File("sound/Sample_000"+sample+".wav").toURI().toString()); + MediaPlayer mediaPlayer = new MediaPlayer(sound); + mediaPlayer.setStartTime(Duration.ZERO); + mediaPlayer.play(); + //mediaPlayer.setOnEndOfMedia(); + } +} diff --git a/Semester 3/ZIPs/MP2-Chapter4_CalebFontenot.zip b/Semester 3/ZIPs/MP2-Chapter4_CalebFontenot.zip new file mode 100644 index 0000000..1c2ec32 Binary files /dev/null and b/Semester 3/ZIPs/MP2-Chapter4_CalebFontenot.zip differ