Skip to content
Snippets Groups Projects
Commit 3326b379 authored by b23022363's avatar b23022363
Browse files

Sonor Motor

parent 07109f5b
No related branches found
No related tags found
No related merge requests found
Pipeline #23646 failed
package engine.Sonor;
import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
public class PongSoundEngine {
private Clip paddleHitClip;
private Clip wallHitClip;
private Clip pointScoredClip;
public PongSoundEngine() {
try {
// Charger les fichiers audio
paddleHitClip = AudioSystem.getClip();
AudioInputStream paddleHitStream = AudioSystem.getAudioInputStream(new File("C:\\Users\\pc\\Downloads\\paddle-fan-drum-40347.wav"));
paddleHitClip.open(paddleHitStream);
wallHitClip = AudioSystem.getClip();
AudioInputStream wallHitStream = AudioSystem.getAudioInputStream(new File("C:\\Users\\pc\\Downloads\\hitting-the-wall-with-a-stick-100777.wav"));
wallHitClip.open(wallHitStream);
pointScoredClip = AudioSystem.getClip();
AudioInputStream pointScoredStream = AudioSystem.getAudioInputStream(new File("C:\\Users\\pc\\Downloads\\epic-hybrid-logo-157092.wav"));
pointScoredClip.open(pointScoredStream);
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
e.printStackTrace();
}
}
public void playPaddleHitSound() {
playSound(paddleHitClip);
}
public void playWallHitSound() {
playSound(wallHitClip);
}
public void playPointScoredSound() {
playSound(pointScoredClip);
}
private void playSound(Clip clip) {
if (clip.isRunning()) {
clip.stop();
}
clip.setFramePosition(0);
clip.start();
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package pong;
import engine.physic.Coordinates2D;
import engine.Kernel;
import engine.Sonor.PongSoundEngine;
import java.io.IOException;
import java.util.ArrayList;
......@@ -11,8 +12,11 @@ public class PongApp {
public static ArrayList<PongObject> components = new ArrayList<PongObject>();
public static int width = 850;
public static int height = 500;
public static PongSoundEngine soundEngine;
public PongApp() throws IOException {
soundEngine = new PongSoundEngine();
}
public static void main(String[] args) throws IOException {
......@@ -34,6 +38,14 @@ public class PongApp {
while(true){
try {
kernel.update();
if (leftRacket.getPosition() == pongBall.getPosition()|| rightRacket.getPosition() == pongBall.getPosition()) {
soundEngine.playPaddleHitSound();
} else if (pongBall.getHeight() <= 0 || pongBall.getWidth() + pongBall.getWidth() >= width) {
soundEngine.playWallHitSound();
} else if (pongBall.getHeight() < 0 || pongBall.getWidth() + pongBall.getWidth() > width) {
soundEngine.playPointScoredSound();
}
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment