Compare commits

...

3 Commits

Author SHA1 Message Date
Martin Prokoph
223c3356b9 feat: final game space sizing
Also fixes logo after changing ui scale
2025-09-06 22:20:47 +02:00
Martin Prokoph
5077f1c2ad fix: normalize music volume 2025-09-06 22:04:54 +02:00
Martin Prokoph
f05d0a9f45 fix(NightJson): correctly save empty maps 2025-09-06 21:38:48 +02:00
4 changed files with 13 additions and 11 deletions

View File

@@ -19,7 +19,7 @@ public class Space {
* Space saves the current state of the game map
*/
public Space() {
gameMap = new Color[20][12];
gameMap = new Color[19][10];
nextShape = generateNextShape();
score = 0;
}

View File

@@ -12,6 +12,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.IOException;
import java.io.InputStream;
import static eu.midnightdust.yaytris.Settings.guiScale;
import static eu.midnightdust.yaytris.Translation.t;
@@ -20,6 +21,7 @@ public class TetrisUI extends JFrame implements KeyListener {
JLabel titleLabel;
GameCanvas gamePanel;
JPanel menuPanel;
Image titleImage;
/**
* Initialize the main Tetris GUI based on Swing
@@ -35,14 +37,13 @@ public class TetrisUI extends JFrame implements KeyListener {
titleLabel = new JLabel("Tetris");
titleLabel.setForeground(Color.WHITE);
Image titleImage;
try {
titleImage = ImageIO.read(this.getClass().getResourceAsStream("/textures/logo.png"));
try (InputStream stream = this.getClass().getResourceAsStream("/textures/logo.png")) {
assert stream != null;
titleImage = ImageIO.read(stream);
} catch (IOException | NullPointerException ex) {
throw new RuntimeException(ex);
}
titleLabel = new JLabel();
titleLabel.setIcon(new ImageIcon(new ImageIcon(titleImage).getImage().getScaledInstance(scale(110), scale(30), Image.SCALE_DEFAULT)));
this.add(titleLabel);
gamePanel = new GameCanvas(this);
@@ -63,7 +64,8 @@ public class TetrisUI extends JFrame implements KeyListener {
private void rescale() {
this.setSize((int) (400 * guiScale), (int) (300 * guiScale));
titleLabel.setBounds(scale(225), scale(7), scale(110), scale(30));
gamePanel.setBounds(scale(10), scale(10), scale(150), scale(256));
titleLabel.setIcon(new ImageIcon(new ImageIcon(titleImage).getImage().getScaledInstance(scale(110), scale(30), Image.SCALE_DEFAULT)));
gamePanel.setBounds(scale(10), scale(10), scale(150), scale(282));
for (Component comp : this.getComponents()){
if (comp instanceof JComponent) setFontScale((JComponent) comp);
}
@@ -110,7 +112,7 @@ public class TetrisUI extends JFrame implements KeyListener {
if (this.menuPanel != null) this.remove(menuPanel);
Tetris.resetSpace();
rescale();
menuPanel = new MainMenu(scale(170), scale(40), scale(220), scale(226), this);
menuPanel = new MainMenu(scale(170), scale(40), scale(220), scale(252), this);
menuPanel.setBackground(CatppuccinColor.BASE.getColor());
menuPanel.setBorder(new LineBorder(CatppuccinColor.SURFACE0.getColor(), scale(2)));
this.add(menuPanel);
@@ -126,7 +128,7 @@ public class TetrisUI extends JFrame implements KeyListener {
*/
public void openSettings(ActionEvent actionEvent) {
if (this.menuPanel != null) this.remove(menuPanel);
menuPanel = new SettingsMenu(scale(170), scale(40), scale(220), scale(226), this);
menuPanel = new SettingsMenu(scale(170), scale(40), scale(220), scale(252), this);
menuPanel.setBackground(CatppuccinColor.BASE.getColor());
menuPanel.setBorder(new LineBorder(CatppuccinColor.SURFACE0.getColor(), scale(2)));
this.add(menuPanel);
@@ -140,7 +142,7 @@ public class TetrisUI extends JFrame implements KeyListener {
*/
public void openScoreMenu(ActionEvent actionEvent) {
if (this.menuPanel != null) this.remove(menuPanel);
menuPanel = new ScoreMenu(scale(170), scale(40), scale(220), scale(226), this);
menuPanel = new ScoreMenu(scale(170), scale(40), scale(220), scale(252), this);
menuPanel.setBackground(CatppuccinColor.BASE.getColor());
menuPanel.setBorder(new LineBorder(CatppuccinColor.SURFACE0.getColor(), scale(2)));
this.add(menuPanel);
@@ -154,7 +156,7 @@ public class TetrisUI extends JFrame implements KeyListener {
*/
public void openHighscores(ActionEvent actionEvent) {
if (this.menuPanel != null) this.remove(menuPanel);
menuPanel = new HighScoreMenu(scale(170), scale(40), scale(220), scale(226), this);
menuPanel = new HighScoreMenu(scale(170), scale(40), scale(220), scale(252), this);
menuPanel.setBackground(CatppuccinColor.BASE.getColor());
menuPanel.setBorder(new LineBorder(CatppuccinColor.SURFACE0.getColor(), scale(2)));
this.add(menuPanel);

View File

@@ -90,7 +90,7 @@ public class NightJson {
StringBuilder mapPairs = new StringBuilder();
Map<?, ?> map = (Map<?, ?>) value;
Iterator<?> it = map.keySet().iterator();
if (it.hasNext()) mapPairs.append("{");
mapPairs.append(it.hasNext() ? "{" : "{}");
while (it.hasNext()) {
Object key = it.next();
Object val = map.get(key);

Binary file not shown.