feat: preview of next shape

This commit is contained in:
Martin Prokoph
2025-07-09 13:00:48 +02:00
parent 7671bdec04
commit 7ef6e246ff
9 changed files with 99 additions and 13 deletions

View File

@@ -1,14 +1,26 @@
package eu.midnightdust.yaytris.util;
public enum Difficulty {
NOOB(2000), EASY(1200), NORMAL(1000), HARD(500), EXTREME(100), WTF(30);
NOOB(2000), EASY(1200), NORMAL(1000), HARD(500), EXTREME(100), WTF(30, "WTF");
private final int timerPeriod;
private final String name;
Difficulty(int timerPeriod) {
this.timerPeriod = timerPeriod;
this.name = this.name().charAt(0) + this.name().substring(1).toLowerCase();
}
Difficulty(int timerPeriod, String name) {
this.timerPeriod = timerPeriod;
this.name = name;
}
public int getTimerPeriod() {
return timerPeriod;
}
@Override
public String toString() {
return this.name;
}
}

View File

@@ -4,6 +4,7 @@ import eu.midnightdust.yaytris.Settings;
import javax.sound.sampled.*;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
@@ -23,7 +24,7 @@ public class SoundUtil {
// Adapted from: https://www.baeldung.com/java-play-sound
public static void playSoundClip(String fileLocation) {
try (AudioInputStream stream = AudioSystem.getAudioInputStream(SoundUtil.class.getResource(fileLocation))) { // FIXME: Support audio files from JAR. File streams won't work here for some reason.
try (AudioInputStream stream = AudioSystem.getAudioInputStream(getResource(fileLocation))) { // FIXME: Support audio files from JAR. File streams won't work here for some reason.
AudioFormat format = stream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
@@ -37,6 +38,10 @@ public class SoundUtil {
}
}
private static URL getResource(String fileLocation) {
return SoundUtil.class.getResource(fileLocation);
}
// Adapted from: https://stackoverflow.com/a/40698149
private static void setVolume(Line line, int volume) {
if (volume < 0 || volume > 100)
@@ -68,7 +73,7 @@ public class SoundUtil {
// Adapted from: https://www.baeldung.com/java-play-sound
private void playMusic(String fileLocation) {
try (AudioInputStream stream = AudioSystem.getAudioInputStream(SoundUtil.class.getResource(fileLocation))) {
try (AudioInputStream stream = AudioSystem.getAudioInputStream(getResource(fileLocation))) {
AudioFormat format = stream.getFormat();
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);