aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2024-10-15 02:09:12 -0400
committersowgro <tpoke.ferrari@gmail.com>2024-10-15 02:09:12 -0400
commit70d3f3a9d45fdb12d1eaf937b4c7ab90df6a8545 (patch)
treef5e7a02f4273bb8d4dd02e77067d2c433def4ca2
parent84b072a945bb5b0b541c9ca6c30af56dc39ff631 (diff)
downloadNPEhero-70d3f3a9d45fdb12d1eaf937b4c7ab90df6a8545.tar.gz
NPEhero-70d3f3a9d45fdb12d1eaf937b4c7ab90df6a8545.tar.bz2
NPEhero-70d3f3a9d45fdb12d1eaf937b4c7ab90df6a8545.zip
Improve GameOver and other fixes
-rwxr-xr-xREADME.md8
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/editor/DiffEditor.java2
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/gui/GameOver.java65
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/levelapi/Difficulty.java2
-rw-r--r--src/main/java/net/sowgro/npehero/levelapi/Leaderboard.java24
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/levelapi/Level.java2
-rw-r--r--src/main/java/net/sowgro/npehero/main/Control.java2
-rwxr-xr-xsrc/main/java/net/sowgro/npehero/main/Settings.java2
8 files changed, 68 insertions, 39 deletions
diff --git a/README.md b/README.md
index 271ea47..a208b7b 100755
--- a/README.md
+++ b/README.md
@@ -5,19 +5,17 @@ Goals:
- [x] New integrated level editor
- [X] Custom keybindings
- [X] Accept mp3 song files
-- [ ] UI improvements
-- [ ] Code cleanup
+- [ ] UI improvements (- 2)
+- [ ] Code cleanup (- 3)
- [X] Installer / Linux package
Todo - needs design:
- Improve errorList and error handling
-- tweak game end screen
- Improve aesthetic of songplayer
- overhaul noteseditor2
-- improve songplayer and noteseditor2 resizing
+- improve resizing (songplayer and noteseditor2)
Todo - bugs:
--
- fix reliance on local font
- Properly center background image
- fix or remove noteseditor1
diff --git a/src/main/java/net/sowgro/npehero/editor/DiffEditor.java b/src/main/java/net/sowgro/npehero/editor/DiffEditor.java
index c08350d..0ae8f5f 100755
--- a/src/main/java/net/sowgro/npehero/editor/DiffEditor.java
+++ b/src/main/java/net/sowgro/npehero/editor/DiffEditor.java
@@ -42,7 +42,7 @@ public class DiffEditor extends Page
Sound.playSfx(Sound.FORWARD);
diff.leaderboard.entries.clear();
try {
- diff.leaderboard.save();
+ diff.leaderboard.write();
} catch (IOException e) {
Driver.setMenu(new ErrorDisplay("Failed to clear the leaderboard:\n"+e, this));
}
diff --git a/src/main/java/net/sowgro/npehero/gui/GameOver.java b/src/main/java/net/sowgro/npehero/gui/GameOver.java
index bcdd25e..417c6cf 100755
--- a/src/main/java/net/sowgro/npehero/gui/GameOver.java
+++ b/src/main/java/net/sowgro/npehero/gui/GameOver.java
@@ -1,5 +1,7 @@
package net.sowgro.npehero.gui;
+import javafx.animation.KeyFrame;
+import javafx.animation.Timeline;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
@@ -10,6 +12,7 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
+import javafx.util.Duration;
import net.sowgro.npehero.Driver;
import net.sowgro.npehero.gameplay.ScoreController;
import net.sowgro.npehero.main.ErrorDisplay;
@@ -22,47 +25,52 @@ import java.io.IOException;
public class GameOver extends Page
{
+ private final Label yourScore;
HBox content = new HBox();
+ ScoreController score2;
public GameOver(Level level, Difficulty diff, Page prev, ScoreController score2)
{
- Text topText = new Text();
- topText.setText("Level Complete");
+ this.score2 = score2;
+
+ Label topText = new Label();
+ topText.setText("LEVEL COMPLETE");
topText.getStyleClass().add("t11");
- Text levelName = new Text();
+ Label levelName = new Label();
levelName.setText(level.title);
levelName.getStyleClass().add("t2");
- Text levelArtist = new Text();
+ Label levelArtist = new Label();
levelArtist.setText(level.artist+" - "+diff.title);
levelArtist.getStyleClass().add("t3");
VBox levelDetailsBox = new VBox();
levelDetailsBox.getChildren().addAll(levelName,levelArtist);
levelDetailsBox.getStyleClass().add("box");
- levelDetailsBox.setPadding(new Insets(5));
+ levelDetailsBox.setPadding(new Insets(10));
+
+ var scoreLabel = new BorderPane();
+ scoreLabel.setLeft(new Label("Final Score"));
+ scoreLabel.setRight(new Label("Max Score"));
- Text scoreLabel = new Text();
- scoreLabel.setText("Final score");
- scoreLabel.getStyleClass().add("t3");
- Label maxScoreLabel = new Label("Max possible score");
ScoreController maxScoreController = new ScoreController();
for (int i = 0; i < diff.notes.list.size(); i++) {
maxScoreController.perfect();
}
- Label maxScore = new Label(maxScoreController.score.get() + "");
- Text score = new Text();
- score.setText(score2.score.get()+"");
- score.getStyleClass().add("t2");
+ var score = new BorderPane(new Label("/"));
+ yourScore = new Label("0");
+ score.setLeft(yourScore);
+ score.setRight( new Label(maxScoreController.score.get() + ""));
+// score.getStyleClass().add("t2");
score.setStyle("-fx-font-size: 30;");
VBox scoreBox = new VBox();
scoreBox.getStyleClass().add("box");
- scoreBox.getChildren().addAll(scoreLabel,score, maxScoreLabel, maxScore);
- scoreBox.setPadding(new Insets(5));
+ scoreBox.getChildren().addAll(scoreLabel,score);
+ scoreBox.setPadding(new Insets(10));
Text nameLabel = new Text();
@@ -92,20 +100,20 @@ public class GameOver extends Page
VBox nameBox = new VBox();
nameBox.getChildren().addAll(nameLabel,b);
nameBox.getStyleClass().add("box");
- nameBox.setSpacing(5);
- nameBox.setPadding(new Insets(5));
+ nameBox.setSpacing(10);
+ nameBox.setPadding(new Insets(10));
Button exit = new Button();
exit.setText("Back");
- exit.setOnAction(e -> {
+ exit.setOnAction(_ -> {
Sound.playSfx(Sound.BACKWARD);
Driver.setMenu(prev);
});
Button replay = new Button();
replay.setText("Replay");
- replay.setOnAction(e -> {
+ replay.setOnAction(_ -> {
Sound.playSfx(Sound.FORWARD);
Driver.setMenu(new LevelSurround(diff, prev));
});
@@ -118,13 +126,30 @@ public class GameOver extends Page
centerBox.getChildren().addAll(topText,levelDetailsBox,scoreBox,nameBox,buttonBox);
centerBox.setSpacing(10);
centerBox.setAlignment(Pos.CENTER);
- centerBox.setMaxWidth(300);
+ centerBox.setPrefWidth(450);
+ centerBox.setMaxWidth(450);
content.getChildren().add(centerBox);
content.setAlignment(Pos.CENTER);
}
@Override
+ public void onView() {
+ // score count up animation
+ Timeline tl = new Timeline();
+ int stepSize = score2.score.get() / 20;
+ for (int i = 1; i <= 20; i++) {
+ int i1 = i;
+ tl.getKeyFrames().add(new KeyFrame(
+ Duration.seconds(i / 20.0 + 0.5),
+ _ -> yourScore.setText(i1 * stepSize + "")
+ ));
+ }
+ tl.play();
+
+ }
+
+ @Override
public Pane getContent() {
return content;
}
diff --git a/src/main/java/net/sowgro/npehero/levelapi/Difficulty.java b/src/main/java/net/sowgro/npehero/levelapi/Difficulty.java
index 27f025a..94517cf 100755
--- a/src/main/java/net/sowgro/npehero/levelapi/Difficulty.java
+++ b/src/main/java/net/sowgro/npehero/levelapi/Difficulty.java
@@ -53,7 +53,7 @@ public class Difficulty implements Comparable<Difficulty>
@SuppressWarnings("unchecked")
Map<String, Object> data = jsonParser.fromJson(new FileReader(jsonFile), Map.class);
if (data == null) {
- data = new HashMap<>();
+ return;
}
title = (String) data.getOrDefault("title", title);
diff --git a/src/main/java/net/sowgro/npehero/levelapi/Leaderboard.java b/src/main/java/net/sowgro/npehero/levelapi/Leaderboard.java
index 82f9aed..395e2c1 100644
--- a/src/main/java/net/sowgro/npehero/levelapi/Leaderboard.java
+++ b/src/main/java/net/sowgro/npehero/levelapi/Leaderboard.java
@@ -10,6 +10,7 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDate;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -18,10 +19,10 @@ public class Leaderboard {
public final ObservableList<LeaderboardEntry> entries = FXCollections.observableArrayList();
private final Gson json = new GsonBuilder().serializeNulls().setPrettyPrinting().create();
- private final File file;
+ private final File jsonFile;
public Leaderboard(File file) throws IOException{
- this.file = file;
+ this.jsonFile = file;
read();
}
@@ -33,17 +34,22 @@ public class Leaderboard {
*/
public void add(String name, int score) throws IOException {
entries.add(new LeaderboardEntry(name, score, LocalDate.now().toString()));
- save();
+ write();
}
/**
* Writes leaderboard to json file
* @throws IOException If there are problems writing to the file.
*/
- public void save() throws IOException {
- file.createNewFile();
+ public void write() throws IOException {
+ if (!jsonFile.exists() && !jsonFile.createNewFile()) {
+ throw new IOException("Could not create file " + jsonFile.getAbsolutePath());
+ }
@SuppressWarnings("unchecked")
- List<Map<String, Object>> data = json.fromJson(new FileReader(file), List.class);
+ List<Map<String, Object>> data = json.fromJson(new FileReader(jsonFile), List.class);
+ if (data == null) {
+ data = new ArrayList<>();
+ }
for (LeaderboardEntry cur : entries) {
Map<String, Object> obj = new HashMap<>();
obj.put("name", cur.name);
@@ -51,7 +57,7 @@ public class Leaderboard {
obj.put("date", cur.date);
data.add(obj);
}
- FileWriter fileWriter = new FileWriter(file);
+ FileWriter fileWriter = new FileWriter(jsonFile);
json.toJson(data, fileWriter);
fileWriter.close();
}
@@ -61,11 +67,11 @@ public class Leaderboard {
* @throws IOException If there are problems reading the file
*/
public void read() throws IOException {
- if (!file.exists()) {
+ if (!jsonFile.exists()) {
return;
}
@SuppressWarnings("unchecked")
- List<Map<String, Object>> data = json.fromJson(new FileReader(file), List.class);
+ List<Map<String, Object>> data = json.fromJson(new FileReader(jsonFile), List.class);
if (data == null) {
return;
}
diff --git a/src/main/java/net/sowgro/npehero/levelapi/Level.java b/src/main/java/net/sowgro/npehero/levelapi/Level.java
index c9d9c41..0e25445 100755
--- a/src/main/java/net/sowgro/npehero/levelapi/Level.java
+++ b/src/main/java/net/sowgro/npehero/levelapi/Level.java
@@ -96,7 +96,7 @@ public class Level implements Comparable<Level>{
@SuppressWarnings("unchecked")
Map<String, Object> data = jsonParser.fromJson(new FileReader(jsonFile), Map.class);
if (data == null) {
- data = new HashMap<>();
+ return;
}
title = (String) data.getOrDefault("title", title);
artist = (String) data.getOrDefault("artist", artist);
diff --git a/src/main/java/net/sowgro/npehero/main/Control.java b/src/main/java/net/sowgro/npehero/main/Control.java
index 0051090..1220806 100644
--- a/src/main/java/net/sowgro/npehero/main/Control.java
+++ b/src/main/java/net/sowgro/npehero/main/Control.java
@@ -64,7 +64,7 @@ public enum Control {
@SuppressWarnings("unchecked")
Map<String, Object> data = jsonParser.fromJson(new FileReader(file), Map.class);
if (data == null) {
- data = new HashMap<>();
+ return;
}
for (Control control : Control.values()) {
if (data.containsKey(control.toString())) {
diff --git a/src/main/java/net/sowgro/npehero/main/Settings.java b/src/main/java/net/sowgro/npehero/main/Settings.java
index 6cd1888..c79f90f 100755
--- a/src/main/java/net/sowgro/npehero/main/Settings.java
+++ b/src/main/java/net/sowgro/npehero/main/Settings.java
@@ -30,7 +30,7 @@ public class Settings
@SuppressWarnings("unchecked")
Map<String, Object> data = jsonParser.fromJson(new FileReader(jsonFile), Map.class);
if (data == null) {
- data = new HashMap<>();
+ return;
}
effectsVol.set((Double) data.getOrDefault("effectsVol", 1.0));
musicVol.set((Double) data.getOrDefault("musicVol", 1.0));