Extra
This commit is contained in:
parent
1a51ae5698
commit
38c8710929
@ -50,7 +50,7 @@ public class TetrisGame {
|
||||
}
|
||||
}
|
||||
if (downPressed) {
|
||||
move(this.currentTetromino, 0, -1, 0);
|
||||
move(this.currentTetromino, 0, 1, 0);
|
||||
}
|
||||
if (upPressed) {
|
||||
move(this.currentTetromino, 0, 0, 1);
|
||||
@ -68,7 +68,7 @@ public class TetrisGame {
|
||||
}
|
||||
|
||||
public void gameTick(boolean leftPressed, boolean rightPressed, boolean downPressed, boolean okPressed, boolean backPressed) {
|
||||
if (move(this.currentTetromino, 0, -1, 0)) {
|
||||
if (move(this.currentTetromino, 0, 1, 0)) {
|
||||
|
||||
} else {
|
||||
// Spawn new tetromino and write the old to the permanent grid
|
||||
@ -83,21 +83,23 @@ public class TetrisGame {
|
||||
}
|
||||
|
||||
private void checkLines() {
|
||||
for(int i = 0; i < HEIGHT; i++) {
|
||||
for(int i = HEIGHT - 1; i >= 0; i--) {
|
||||
boolean scored = true;
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
if (this.grid[x + i * WIDTH] == null) {
|
||||
scored = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (scored) {
|
||||
this.score += WIDTH;
|
||||
while (scored) {
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
int y = 1;
|
||||
while (i + y < HEIGHT) {
|
||||
this.grid[x + (i + y - 1) * WIDTH] = this.grid[x + (i + y) * WIDTH];
|
||||
y++;
|
||||
if (this.grid[x + i * WIDTH] == null) {
|
||||
scored = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (scored) {
|
||||
this.score += WIDTH;
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
int y = HEIGHT - i - 2;
|
||||
while (i + y > 0) {
|
||||
this.grid[x + (i + y + 1) * WIDTH] = this.grid[x + (i + y) * WIDTH];
|
||||
y--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -153,7 +155,7 @@ public class TetrisGame {
|
||||
|
||||
private Tetromino generateRandomTetromino() {
|
||||
int s = (int) (Math.random() * 7);
|
||||
final byte middleX = (byte)((WIDTH - 1)/2), middleY = (byte)(HEIGHT - 1), rotation = (byte) (Math.random() * 4);
|
||||
final byte middleX = (byte)((WIDTH - 1)/2), middleY = 0, rotation = (byte) (Math.random() * 4);
|
||||
switch (s) {
|
||||
case 0:
|
||||
return new TetrominoICyan(middleX, middleY, rotation);
|
||||
|
@ -83,9 +83,9 @@ public class TetrisScreen extends Screen {
|
||||
final int offset = x+y*TetrisGame.WIDTH;
|
||||
final BlockColor type = renderedGrid[offset];
|
||||
if (type != null) {
|
||||
r.glFillRect(leftOffset + x * 5, topOffset + (TetrisGame.HEIGHT+3-y) * 5, 5, 5, renderedGrid[offset].ordinal() * 5, 0, 5, 5);
|
||||
r.glFillRect(leftOffset + x * 5, topOffset + (y+3) * 5, 5, 5, renderedGrid[offset].ordinal() * 5, 0, 5, 5);
|
||||
} else {
|
||||
//r.glFillRect(leftOffset + x * 5, topOffset + (TetrisGame.HEIGHT+3-y) * 5, 5, 5, 1 * 5, 0, 2, 2);
|
||||
r.glFillRect(leftOffset + x * 5, topOffset + (y+3) * 5, 5, 5, 1 * 5, 0, 2, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ public abstract class Tetromino {
|
||||
}
|
||||
|
||||
public void fixInitialPosition() {
|
||||
this.y -= (byte) (this.getTetrominoGridSize()/2);
|
||||
this.y += (byte) (this.getTetrominoGridSize()/2);
|
||||
}
|
||||
|
||||
public abstract int getTetrominoGridSize();
|
||||
|
Loading…
x
Reference in New Issue
Block a user