feat: day 1 progress
This commit is contained in:
40
src/main/java/eu/midnightdust/yaytris/game/Tetromino.java
Normal file
40
src/main/java/eu/midnightdust/yaytris/game/Tetromino.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user