feat: music & sound!!!
This commit is contained in:
@@ -24,6 +24,10 @@ public class Space {
|
||||
nextShape = getNextShape();
|
||||
}
|
||||
|
||||
public Tetromino getCurrentTetromino() {
|
||||
return currentTetromino;
|
||||
}
|
||||
|
||||
public TetrominoShape getNextShape() {
|
||||
return TetrominoShape.values()[random.nextInt(TetrominoShape.values().length)];
|
||||
}
|
||||
@@ -60,14 +64,14 @@ public class Space {
|
||||
int combo = 0;
|
||||
Set<Integer> completedLines = new TreeSet<>();
|
||||
for (int line : lines) {
|
||||
if (line > getMapHeight()) continue;
|
||||
if (line >= getMapHeight()) continue;
|
||||
Color[] newBlobs = tetromino.getLine(line);
|
||||
for (int i = 0; i < newBlobs.length; i++) {
|
||||
if (newBlobs[i] == null) continue;
|
||||
gameMap[line][i] = newBlobs[i];
|
||||
}
|
||||
if (Arrays.stream(gameMap[line]).noneMatch(Objects::isNull)) { // Line completed
|
||||
combo += 1;
|
||||
combo += 10;
|
||||
completedLines.add(line);
|
||||
combo *= completedLines.size();
|
||||
}
|
||||
@@ -78,11 +82,11 @@ public class Space {
|
||||
gameMap[i] = (i-1 < 0) ? new Color[gameMap[i].length] : gameMap[i-1];
|
||||
}
|
||||
}
|
||||
this.score += combo;
|
||||
Tetris.updateScore(this.score);
|
||||
increaseScore(combo);
|
||||
}
|
||||
|
||||
public Tetromino getCurrentTetromino() {
|
||||
return currentTetromino;
|
||||
public void increaseScore(int amount) {
|
||||
this.score += amount;
|
||||
Tetris.updateScore(this.score);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package eu.midnightdust.yaytris.game;
|
||||
|
||||
import eu.midnightdust.yaytris.Tetris;
|
||||
import eu.midnightdust.yaytris.util.SoundEffect;
|
||||
import eu.midnightdust.yaytris.util.Vec2i;
|
||||
|
||||
import java.awt.*;
|
||||
@@ -20,6 +21,7 @@ public class Tetromino {
|
||||
public void fall(int length) {
|
||||
Vec2i newPos = centerPos.offset(Vec2i.of(0, length));
|
||||
if (collidesVertically(newPos)) {
|
||||
SoundEffect.BEEP.play();
|
||||
int[] affectedLines = new int[this.collision.length];
|
||||
int line = centerPos.getY();
|
||||
for (int i = 0; i < this.collision.length; i++) {
|
||||
@@ -27,6 +29,7 @@ public class Tetromino {
|
||||
line++;
|
||||
}
|
||||
Tetris.getSpace().onLinesChanged(this, affectedLines);
|
||||
Tetris.getSpace().increaseScore(20-fallLength);
|
||||
if (fallLength >= 1) Tetris.getSpace().spawnTetromino();
|
||||
else Tetris.stopGame();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user