Updated extra feature
This commit is contained in:
parent
b90faa13b8
commit
35d878fba7
@ -3,8 +3,8 @@ package it.cavallium.warppi.extra.tetris;
|
||||
public enum BlockType {
|
||||
RED,
|
||||
GREEN,
|
||||
YELLOW,
|
||||
BLUE,
|
||||
YELLOW,
|
||||
ORANGE,
|
||||
VIOLET
|
||||
}
|
||||
|
@ -2,9 +2,10 @@ package it.cavallium.warppi.extra.tetris;
|
||||
|
||||
public class TetrisGame {
|
||||
|
||||
private static final int WIDTH = 10, HEIGHT = 22;
|
||||
public static final int WIDTH = 10, HEIGHT = 22;
|
||||
private BlockType[] grid;
|
||||
private BlockType[] hovergrid;
|
||||
private BlockType[] renderedGrid;
|
||||
private GameStatus gameStatus = GameStatus.INITIAL;
|
||||
private int score = 0;
|
||||
private double currentTime = 0;
|
||||
@ -16,18 +17,33 @@ public class TetrisGame {
|
||||
void playAgain() {
|
||||
grid = new BlockType[WIDTH * HEIGHT];
|
||||
hovergrid = new BlockType[WIDTH * HEIGHT];
|
||||
renderedGrid = new BlockType[WIDTH * HEIGHT];
|
||||
score = 0;
|
||||
currentTime = 0;
|
||||
gameStatus = GameStatus.PLAYING;
|
||||
}
|
||||
|
||||
public void gameTick(float dt, boolean leftPressed, boolean rightPressed, boolean downPressed, boolean okPressed,
|
||||
boolean backPressed) {
|
||||
public void gameTick(float dt, boolean leftPressed, boolean rightPressed, boolean downPressed, boolean okPressed, boolean backPressed) {
|
||||
currentTime += dt;
|
||||
if (gameStatus == GameStatus.INITIAL) {
|
||||
playAgain();
|
||||
} else {
|
||||
|
||||
}
|
||||
renderGrid();
|
||||
}
|
||||
|
||||
public void renderGrid() {
|
||||
this.renderedGrid = new BlockType[WIDTH*HEIGHT];
|
||||
for (int y = 0; y < HEIGHT; y++) {
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
final int offset = x+y*WIDTH;
|
||||
renderedGrid[offset] = hovergrid[offset] != null ? hovergrid[offset] : grid[offset];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BlockType[] getRenderedGrid() {
|
||||
return renderedGrid;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package it.cavallium.warppi.extra.tetris;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.nevec.rjm.Wigner3j;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.StaticVars;
|
||||
import it.cavallium.warppi.device.Keyboard;
|
||||
@ -47,6 +49,7 @@ public class TetrisScreen extends Screen {
|
||||
if (TetrisScreen.skin == null) {
|
||||
TetrisScreen.skin = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("/tetrisskin.png");
|
||||
}
|
||||
StaticVars.windowZoom.onNext(1f);
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -68,6 +71,20 @@ public class TetrisScreen extends Screen {
|
||||
if (TetrisScreen.skin != null) {
|
||||
TetrisScreen.skin.use(e);
|
||||
}
|
||||
r.glColor3f(1, 1, 1);
|
||||
BlockType[] renderedGrid = g.getRenderedGrid();
|
||||
int centerScreen = StaticVars.screenSize[0]/2;
|
||||
int centerGrid = TetrisGame.WIDTH*5/2-1;
|
||||
final int leftOffset = centerScreen - centerGrid;
|
||||
final int topOffset = StaticVars.screenSize[1] - TetrisGame.HEIGHT*5-1;
|
||||
for (int y = 0; y < TetrisGame.HEIGHT; y++) {
|
||||
for (int x = 0; x < TetrisGame.WIDTH; x++) {
|
||||
final int offset = x+y*TetrisGame.WIDTH;
|
||||
final BlockType type = renderedGrid[offset];
|
||||
if (type != null) r.glFillRect(leftOffset + x * 4, y * 4, 4, 4, renderedGrid[offset].ordinal() * 4, 0, 4, 4);
|
||||
else r.glFillRect(leftOffset + x * 5, topOffset + y * 5, 4, 4, 2 * 4, 0, 4, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -132,16 +149,4 @@ public class TetrisScreen extends Screen {
|
||||
public String getSessionTitle() {
|
||||
return "Absolutely Not Tetris";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyPressed(KeyPressedEvent k) {
|
||||
System.out.println("pr:"+k.getKey());
|
||||
return super.onKeyPressed(k);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyReleased(KeyReleasedEvent k) {
|
||||
System.out.println("re:"+k.getKey());
|
||||
return super.onKeyReleased(k);
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
Loading…
Reference in New Issue
Block a user