diff --git a/nb-configuration.xml b/nb-configuration.xml new file mode 100644 index 0000000..974cb30 --- /dev/null +++ b/nb-configuration.xml @@ -0,0 +1,18 @@ + + + + + + JDK_17 + + diff --git a/nbactions.xml b/nbactions.xml new file mode 100644 index 0000000..b458851 --- /dev/null +++ b/nbactions.xml @@ -0,0 +1,55 @@ + + + + run + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:3.5.1:exec + + + + ${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs} + + com.mycompany.fuck.you.netbeans.BallControl + java + + + + debug + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:3.5.1:exec + + + -agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address} + ${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs} + + com.mycompany.fuck.you.netbeans.BallControl + java + true + + + + profile + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:3.5.1:exec + + + + ${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs} + com.mycompany.fuck.you.netbeans.BallControl + java + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..48e00ff --- /dev/null +++ b/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + org.chloefontenot + TennisGame + 1.0-SNAPSHOT + jar + + + + org.openjfx + javafx-maven-plugin + ${javafx.maven.plugin.version} + + org.chloefontenot.BallControl + + + + + + + org.openjfx + javafx-controls + ${javafx.version} + + + org.openjfx + javafx-media + ${javafx.version} + linux + + + + UTF-8 + 17 + 0.0.8 + UTF-8 + 8 + org.chloefontenot.BallControl + + diff --git a/sound/bgm/Chloe Fontenot - Blips.wav b/sound/bgm/Chloe Fontenot - Blips.wav new file mode 100644 index 0000000..a0c299c Binary files /dev/null and b/sound/bgm/Chloe Fontenot - Blips.wav differ diff --git a/sound/bgm/Chloe Fontenot - DEAL WITH IT.wav b/sound/bgm/Chloe Fontenot - DEAL WITH IT.wav new file mode 100644 index 0000000..ea93eb8 Binary files /dev/null and b/sound/bgm/Chloe Fontenot - DEAL WITH IT.wav differ diff --git a/sound/bgm/Chloe Fontenot - Tomodachi Moment.wav b/sound/bgm/Chloe Fontenot - Tomodachi Moment.wav new file mode 100644 index 0000000..bcf0cb5 Binary files /dev/null and b/sound/bgm/Chloe Fontenot - Tomodachi Moment.wav differ diff --git a/sound/sfx/Sample_0000.wav b/sound/sfx/Sample_0000.wav new file mode 100644 index 0000000..d888223 Binary files /dev/null and b/sound/sfx/Sample_0000.wav differ diff --git a/sound/sfx/Sample_0001.wav b/sound/sfx/Sample_0001.wav new file mode 100644 index 0000000..c718aae Binary files /dev/null and b/sound/sfx/Sample_0001.wav differ diff --git a/sound/sfx/Sample_0002.wav b/sound/sfx/Sample_0002.wav new file mode 100644 index 0000000..5f9e55e Binary files /dev/null and b/sound/sfx/Sample_0002.wav differ diff --git a/sound/sfx/Sample_0003.wav b/sound/sfx/Sample_0003.wav new file mode 100644 index 0000000..a9f6ffe Binary files /dev/null and b/sound/sfx/Sample_0003.wav differ diff --git a/sound/sfx/Sample_0004.wav b/sound/sfx/Sample_0004.wav new file mode 100644 index 0000000..e51b0bb Binary files /dev/null and b/sound/sfx/Sample_0004.wav differ diff --git a/sound/sfx/Sample_0005.wav b/sound/sfx/Sample_0005.wav new file mode 100644 index 0000000..9a4ac42 Binary files /dev/null and b/sound/sfx/Sample_0005.wav differ diff --git a/sound/sfx/Sample_0007.wav b/sound/sfx/Sample_0007.wav new file mode 100644 index 0000000..6a092d3 Binary files /dev/null and b/sound/sfx/Sample_0007.wav differ diff --git a/sound/sfx/Sample_0009.wav b/sound/sfx/Sample_0009.wav new file mode 100644 index 0000000..2ad13cd Binary files /dev/null and b/sound/sfx/Sample_0009.wav differ diff --git a/sound/sfx/Sample_0010.wav b/sound/sfx/Sample_0010.wav new file mode 100644 index 0000000..0c66f12 Binary files /dev/null and b/sound/sfx/Sample_0010.wav differ diff --git a/sound/sfx/Sample_0012.wav b/sound/sfx/Sample_0012.wav new file mode 100644 index 0000000..9b68ba4 Binary files /dev/null and b/sound/sfx/Sample_0012.wav differ diff --git a/sound/sfx/Sample_0014.wav b/sound/sfx/Sample_0014.wav new file mode 100644 index 0000000..3c7226d Binary files /dev/null and b/sound/sfx/Sample_0014.wav differ diff --git a/sound/sfx/Sample_0016.wav b/sound/sfx/Sample_0016.wav new file mode 100644 index 0000000..22742d6 Binary files /dev/null and b/sound/sfx/Sample_0016.wav differ diff --git a/sound/sfx/Sample_0017.wav b/sound/sfx/Sample_0017.wav new file mode 100644 index 0000000..6251b90 Binary files /dev/null and b/sound/sfx/Sample_0017.wav differ diff --git a/sound/sfx/Sample_0018.wav b/sound/sfx/Sample_0018.wav new file mode 100644 index 0000000..5388a13 Binary files /dev/null and b/sound/sfx/Sample_0018.wav differ diff --git a/sound/sfx/Sample_0019.wav b/sound/sfx/Sample_0019.wav new file mode 100644 index 0000000..85fb935 Binary files /dev/null and b/sound/sfx/Sample_0019.wav differ diff --git a/sound/sfx/Sample_0020.wav b/sound/sfx/Sample_0020.wav new file mode 100644 index 0000000..c3ec3c2 Binary files /dev/null and b/sound/sfx/Sample_0020.wav differ diff --git a/sound/sfx/Sample_0021.wav b/sound/sfx/Sample_0021.wav new file mode 100644 index 0000000..0803b10 Binary files /dev/null and b/sound/sfx/Sample_0021.wav differ diff --git a/sound/sfx/Sample_0022.wav b/sound/sfx/Sample_0022.wav new file mode 100644 index 0000000..fb69172 Binary files /dev/null and b/sound/sfx/Sample_0022.wav differ diff --git a/sound/sfx/Sample_0023.wav b/sound/sfx/Sample_0023.wav new file mode 100644 index 0000000..a2b2d6a Binary files /dev/null and b/sound/sfx/Sample_0023.wav differ diff --git a/sound/sfx/Sample_0024.wav b/sound/sfx/Sample_0024.wav new file mode 100644 index 0000000..9e7c30f Binary files /dev/null and b/sound/sfx/Sample_0024.wav differ diff --git a/sound/sfx/Sample_0025.wav b/sound/sfx/Sample_0025.wav new file mode 100644 index 0000000..6cfb8e4 Binary files /dev/null and b/sound/sfx/Sample_0025.wav differ diff --git a/sound/sfx/Sample_0026.wav b/sound/sfx/Sample_0026.wav new file mode 100644 index 0000000..4968470 Binary files /dev/null and b/sound/sfx/Sample_0026.wav differ diff --git a/sound/sfx/Sample_0027.wav b/sound/sfx/Sample_0027.wav new file mode 100644 index 0000000..294843f Binary files /dev/null and b/sound/sfx/Sample_0027.wav differ diff --git a/sound/sfx/Sample_0028.wav b/sound/sfx/Sample_0028.wav new file mode 100644 index 0000000..702d016 Binary files /dev/null and b/sound/sfx/Sample_0028.wav differ diff --git a/sound/sfx/Sample_0029.wav b/sound/sfx/Sample_0029.wav new file mode 100644 index 0000000..cddc2f7 Binary files /dev/null and b/sound/sfx/Sample_0029.wav differ diff --git a/sound/sfx/Sample_0030.wav b/sound/sfx/Sample_0030.wav new file mode 100644 index 0000000..58dc8a4 Binary files /dev/null and b/sound/sfx/Sample_0030.wav differ diff --git a/sound/sfx/Sample_0031.wav b/sound/sfx/Sample_0031.wav new file mode 100644 index 0000000..89ee426 Binary files /dev/null and b/sound/sfx/Sample_0031.wav differ diff --git a/sound/sfx/Sample_0032.wav b/sound/sfx/Sample_0032.wav new file mode 100644 index 0000000..ed8586d Binary files /dev/null and b/sound/sfx/Sample_0032.wav differ diff --git a/src/main/java/org/chloefontenot/BallControl.java b/src/main/java/org/chloefontenot/BallControl.java new file mode 100644 index 0000000..fb25dd2 --- /dev/null +++ b/src/main/java/org/chloefontenot/BallControl.java @@ -0,0 +1,87 @@ +/* + * 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 org.chloefontenot; + +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 chloe + */ +public class BallControl extends Application { + + private boolean mouseFocus = false; + private int racketPosition = 0; + + @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.showInfoLabel(); + + bouncingBall.setOnMouseEntered(e + -> { + mouseFocus = true; + bouncingBall.hideInfoLabel(); + bouncingBall.play(); + }); + + bouncingBall.setOnMouseExited(e -> { + mouseFocus = false; + }); + 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.LEFT && mouseFocus == false) { + bouncingBall.hideInfoLabel(); + if (racketPosition > 0) { + racketPosition = racketPosition - 30; + } + bouncingBall.moveRacket(racketPosition); + } + if (e.getCode() == KeyCode.RIGHT && mouseFocus == false) { + bouncingBall.hideInfoLabel(); + if (racketPosition < bouncingBall.getWidth()) { + racketPosition = racketPosition + 30; + } + bouncingBall.moveRacket(racketPosition); + } + 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/src/main/java/org/chloefontenot/BouncingBall.java b/src/main/java/org/chloefontenot/BouncingBall.java new file mode 100644 index 0000000..0c92836 --- /dev/null +++ b/src/main/java/org/chloefontenot/BouncingBall.java @@ -0,0 +1,255 @@ +/* + * 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 org.chloefontenot; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import javafx.animation.KeyFrame; +import javafx.animation.Timeline; +import javafx.beans.property.DoubleProperty; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.scene.control.Button; +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 chloe + */ +public class BouncingBall extends Pane { + + private List mediaPlayers = new ArrayList<>(); + GridPane textPane = new GridPane(); + private String currentlyPlaying; + private final int COLLISION_COOLDOWN = 20; + 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 Label nowPlaying = new Label(); + private Button restartBgm = new Button("Restart BGM"); + + private Timeline animation; + + private int computerScore, playerScore = 0; + + public BouncingBall() { + restartBgm.setOnMouseClicked(e -> { + playSound("bgm"); + }); + 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); + textPane.add(nowPlaying, 0, 4); + textPane.add(restartBgm, 0, 5); + getChildren().addAll(circle, racket, textPane); // Place a ball into this pane + racket.relocate(0, 580); + playSound("bgm"); + // 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(); + // Process collisions + if (y >= (getHeight() - 20) && (timeSinceLastCollisionEvent > COLLISION_COOLDOWN)) { + timeSinceLastCollisionEvent = 0; + playSound("collision"); + incrementComputerScore(); + } + if ((x <= 20 && (timeSinceLastCollisionEvent > COLLISION_COOLDOWN)) || ((x >= getWidth() - 20) && (timeSinceLastCollisionEvent > COLLISION_COOLDOWN))) { + timeSinceLastCollisionEvent = 0; + playSound("collision"); + } + if (y <= 20 && (timeSinceLastCollisionEvent > COLLISION_COOLDOWN)) { + timeSinceLastCollisionEvent = 0; + playSound("collision"); + } + } + }) + ); + animation.setRate(animation.getRate() * .5); + animation.setCycleCount(Timeline.INDEFINITE); + + } + + private boolean processRacketCollision() { + boolean racketCollision = racket.getBoundsInParent().intersects(circle.getBoundsInParent()); + + if (racketCollision && (timeSinceLastCollisionEvent > COLLISION_COOLDOWN)) { // 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(); + playSound("racket"); + 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); + } + + private void incrementComputerScore() { + computerScoreLabel.setText("Computer score: " + ++computerScore); + + } + + private void ballCoordsToLabel() { + ballCords.setText("Ball coords: " + x + ", " + y); + } + + private void playSound(String sampleType) { + boolean isSfx = true; + String sample = "sound/sfx/Sample_00"; + int randInt = (int) (Math.random() * 2); + switch (sampleType) { + case "collision": + randInt = (int) (Math.random() * 2); + isSfx = true; + switch (randInt) { + case 0: + sample += "05"; + break; + case 1: + sample += "07"; + break; + } + break; + case "racket": + randInt = (int) (Math.random() * 2); + isSfx = true; + switch (randInt) { + case 0: + sample += "10"; + break; + case 1: + sample += "12"; + break; + } + break; + case "bgm": + sample = "sound/bgm/"; + randInt = (int) (Math.random() * 3); + isSfx = false; + switch (randInt) { + case 0: + currentlyPlaying = "Chloe Fontenot - Blips"; + nowPlaying.setText("Now playing: " + currentlyPlaying); + break; + case 1: + currentlyPlaying = "Chloe Fontenot - DEAL WITH IT"; + nowPlaying.setText("Now playing: " + currentlyPlaying); + break; + case 2: + currentlyPlaying = "Chloe Fontenot - Tomodachi Moment"; + nowPlaying.setText("Now playing: " + currentlyPlaying); + break; + } + sample += currentlyPlaying; + break; + } + Media sound = new Media(new File(sample + ".wav").toURI().toString()); + MediaPlayer mediaPlayer = new MediaPlayer(sound); + mediaPlayer.setStartTime(Duration.ZERO); + mediaPlayer.setAutoPlay(true); + // If we're playing BGM, lower the volume a little + if (!isSfx) { + mediaPlayer.setVolume(0.6); + mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE); + } + mediaPlayer.play(); + mediaPlayers.add(mediaPlayer); // Prevent the JVM's GC from deleting our media player if there's already one running + // Free the media player when it has finished playing a sound. + mediaPlayer.setOnEndOfMedia(new Runnable() { + @Override + public void run() { + //System.out.println("I'm done playing sound! Please take me to the ether, Java GC!"); + mediaPlayer.stop(); + mediaPlayer.dispose(); + mediaPlayers.remove(mediaPlayer); + } + }); + } +} diff --git a/src/main/java/org/chloefontenot/MediaType.java b/src/main/java/org/chloefontenot/MediaType.java new file mode 100644 index 0000000..b2f7093 --- /dev/null +++ b/src/main/java/org/chloefontenot/MediaType.java @@ -0,0 +1,26 @@ +/* + * 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 org.chloefontenot; + +import javafx.scene.media.MediaPlayer; + +/** + * + * @author chloe + */ +public class MediaType { + private MediaPlayer mediaPlayer; + private boolean isBgm; + + public MediaType(MediaPlayer mediaPlayer, boolean isBgm) { + this.mediaPlayer = mediaPlayer; + this.isBgm = isBgm; + } + + public boolean isIsBgm() { + return isBgm; + } + +} diff --git a/target/classes/org/chloefontenot/BallControl$1.class b/target/classes/org/chloefontenot/BallControl$1.class new file mode 100644 index 0000000..241720e Binary files /dev/null and b/target/classes/org/chloefontenot/BallControl$1.class differ diff --git a/target/classes/org/chloefontenot/BallControl.class b/target/classes/org/chloefontenot/BallControl.class new file mode 100644 index 0000000..9a40e1c Binary files /dev/null and b/target/classes/org/chloefontenot/BallControl.class differ diff --git a/target/classes/org/chloefontenot/BouncingBall$1.class b/target/classes/org/chloefontenot/BouncingBall$1.class new file mode 100644 index 0000000..8f9bf66 Binary files /dev/null and b/target/classes/org/chloefontenot/BouncingBall$1.class differ diff --git a/target/classes/org/chloefontenot/BouncingBall$2.class b/target/classes/org/chloefontenot/BouncingBall$2.class new file mode 100644 index 0000000..f8a31ae Binary files /dev/null and b/target/classes/org/chloefontenot/BouncingBall$2.class differ diff --git a/target/classes/org/chloefontenot/BouncingBall.class b/target/classes/org/chloefontenot/BouncingBall.class new file mode 100644 index 0000000..aaaf2e0 Binary files /dev/null and b/target/classes/org/chloefontenot/BouncingBall.class differ diff --git a/target/classes/org/chloefontenot/MediaType.class b/target/classes/org/chloefontenot/MediaType.class new file mode 100644 index 0000000..d6b581b Binary files /dev/null and b/target/classes/org/chloefontenot/MediaType.class differ diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..200a80a --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,6 @@ +org/chloefontenot/MediaType.class +org/chloefontenot/BallControl.class +org/chloefontenot/BallControl$1.class +org/chloefontenot/BouncingBall.class +org/chloefontenot/BouncingBall$1.class +org/chloefontenot/BouncingBall$2.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..263b98a --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,3 @@ +/home/chloe/NetBeansProjects/fuck-you-netbeans/src/main/java/org/chloefontenot/BallControl.java +/home/chloe/NetBeansProjects/fuck-you-netbeans/src/main/java/org/chloefontenot/BouncingBall.java +/home/chloe/NetBeansProjects/fuck-you-netbeans/src/main/java/org/chloefontenot/MediaType.java