2018-10-05 16:00:15 +02:00
|
|
|
package it.cavallium.warppi.extra.tetris;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import it.cavallium.warppi.Engine;
|
|
|
|
import it.cavallium.warppi.StaticVars;
|
|
|
|
import it.cavallium.warppi.device.Keyboard;
|
2018-10-06 16:37:44 +02:00
|
|
|
import it.cavallium.warppi.event.KeyPressedEvent;
|
|
|
|
import it.cavallium.warppi.event.KeyReleasedEvent;
|
2018-10-05 16:00:15 +02:00
|
|
|
import it.cavallium.warppi.gui.HistoryBehavior;
|
|
|
|
import it.cavallium.warppi.gui.graphicengine.BinaryFont;
|
2018-10-06 16:37:44 +02:00
|
|
|
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
|
|
|
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
2018-10-05 16:00:15 +02:00
|
|
|
import it.cavallium.warppi.gui.graphicengine.Skin;
|
|
|
|
import it.cavallium.warppi.gui.screens.Screen;
|
|
|
|
|
|
|
|
public class TetrisScreen extends Screen {
|
|
|
|
|
|
|
|
private TetrisGame g;
|
|
|
|
|
2018-10-09 17:45:20 +02:00
|
|
|
private boolean leftPressed;
|
|
|
|
|
|
|
|
private boolean rightPressed;
|
|
|
|
|
|
|
|
private boolean downPressed;
|
|
|
|
|
|
|
|
private boolean okPressed;
|
|
|
|
|
|
|
|
private boolean backPressed;
|
|
|
|
|
2018-10-06 16:37:44 +02:00
|
|
|
private GraphicEngine e;
|
|
|
|
|
|
|
|
private Renderer r;
|
|
|
|
|
2018-10-05 16:00:15 +02:00
|
|
|
private static Skin skin;
|
|
|
|
|
|
|
|
public TetrisScreen() {
|
|
|
|
super();
|
|
|
|
historyBehavior = HistoryBehavior.ALWAYS_KEEP_IN_HISTORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initialized() {
|
2018-10-06 16:37:44 +02:00
|
|
|
try {
|
|
|
|
e = d.engine;
|
|
|
|
r = d.renderer;
|
|
|
|
if (TetrisScreen.skin == null) {
|
|
|
|
TetrisScreen.skin = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("/tetrisskin.png");
|
|
|
|
}
|
|
|
|
} catch (final IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2018-10-05 16:00:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void created() throws InterruptedException {
|
2018-10-06 16:37:44 +02:00
|
|
|
g = new TetrisGame();
|
2018-10-05 16:00:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void beforeRender(final float dt) {
|
2018-10-06 16:37:44 +02:00
|
|
|
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glClearColor(0xff000000);
|
2018-10-09 17:45:20 +02:00
|
|
|
g.gameTick(dt, leftPressed, rightPressed, downPressed, okPressed, backPressed);
|
2018-10-05 16:00:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void render() {
|
2018-10-06 16:37:44 +02:00
|
|
|
if (TetrisScreen.skin != null) {
|
|
|
|
TetrisScreen.skin.use(e);
|
|
|
|
}
|
2018-10-05 16:00:15 +02:00
|
|
|
}
|
2018-10-09 17:45:20 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyPressed(KeyPressedEvent k) {
|
|
|
|
switch (k.getKey()) {
|
|
|
|
case LEFT: {
|
|
|
|
leftPressed = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case RIGHT: {
|
|
|
|
rightPressed = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case DOWN: {
|
|
|
|
downPressed = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case OK: {
|
|
|
|
okPressed = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case BACK: {
|
|
|
|
backPressed = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyReleased(KeyReleasedEvent k) {
|
|
|
|
switch (k.getKey()) {
|
|
|
|
case LEFT: {
|
|
|
|
leftPressed = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case RIGHT: {
|
|
|
|
rightPressed = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case DOWN: {
|
|
|
|
downPressed = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case OK: {
|
|
|
|
okPressed = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case BACK: {
|
|
|
|
backPressed = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
2018-10-05 16:00:15 +02:00
|
|
|
@Override
|
|
|
|
public boolean mustBeRefreshed() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getSessionTitle() {
|
2018-10-06 16:37:44 +02:00
|
|
|
return "Absolutely Not Tetris";
|
2018-10-05 16:00:15 +02:00
|
|
|
}
|
|
|
|
|
2018-10-06 16:37:44 +02:00
|
|
|
@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);
|
|
|
|
}
|
2018-10-05 16:00:15 +02:00
|
|
|
}
|