feat: day 1 progress

This commit is contained in:
Martin Prokoph
2025-06-27 19:58:59 +02:00
commit 9e45ea3f37
29 changed files with 988 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
package eu.midnightdust.yaytris.game;
import eu.midnightdust.yaytris.util.Vec2i;
import java.awt.*;
public class Tetromino {
private final TetrominoShape shape;
private int[][] collision;
private Vec2i centerPos;
public Tetromino(TetrominoShape shape) {
this.shape = shape;
this.collision = shape.boundary;
this.centerPos = Vec2i.of(0, 0);
}
public void fall(int length) {
centerPos = centerPos.offset(Vec2i.of(0, length));
}
public void rotate() {
int[][] newCollision = new int[collision[0].length][collision.length];
for (int i = 0; i < collision.length; i++) {
for (int j = 0; j < collision[i].length; j++) {
newCollision[j][i] = collision[i][j];
}
}
this.collision = newCollision;
}
public Color[] getLine(int line) {
Color[] l = new Color[7];
for (int i = 0; i < l.length; i++) {
if (collision.length < line-centerPos.getX() && collision[line-centerPos.getX()][i] != 0)
l[i] = shape.color;
}
return l;
}
}