From b90faa13b8589bfda1a2693a35cee8c68bba4fe0 Mon Sep 17 00:00:00 2001 From: Cavallium Date: Tue, 9 Oct 2018 17:45:20 +0200 Subject: [PATCH] Updated extra feature --- .../warppi/extra/tetris/TetrisGame.java | 22 +++++-- .../warppi/extra/tetris/TetrisScreen.java | 66 ++++++++++++++++++- .../graphicengine/impl/common/RFTFont.java | 2 +- 3 files changed, 83 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/it/cavallium/warppi/extra/tetris/TetrisGame.java b/core/src/main/java/it/cavallium/warppi/extra/tetris/TetrisGame.java index 151a74b8..220c30f8 100644 --- a/core/src/main/java/it/cavallium/warppi/extra/tetris/TetrisGame.java +++ b/core/src/main/java/it/cavallium/warppi/extra/tetris/TetrisGame.java @@ -2,11 +2,12 @@ package it.cavallium.warppi.extra.tetris; public class TetrisGame { - static final int WIDTH = 10, HEIGHT = 22; - BlockType[] grid; - BlockType[] hovergrid; - GameStatus gameStatus = GameStatus.INITIAL; - int score = 0; + private static final int WIDTH = 10, HEIGHT = 22; + private BlockType[] grid; + private BlockType[] hovergrid; + private GameStatus gameStatus = GameStatus.INITIAL; + private int score = 0; + private double currentTime = 0; public TetrisGame() { @@ -16,6 +17,17 @@ public class TetrisGame { grid = new BlockType[WIDTH * HEIGHT]; hovergrid = 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) { + currentTime += dt; + if (gameStatus == GameStatus.INITIAL) { + playAgain(); + } else { + + } + } } diff --git a/core/src/main/java/it/cavallium/warppi/extra/tetris/TetrisScreen.java b/core/src/main/java/it/cavallium/warppi/extra/tetris/TetrisScreen.java index 76ba5e4f..24a79ea2 100644 --- a/core/src/main/java/it/cavallium/warppi/extra/tetris/TetrisScreen.java +++ b/core/src/main/java/it/cavallium/warppi/extra/tetris/TetrisScreen.java @@ -18,6 +18,16 @@ public class TetrisScreen extends Screen { private TetrisGame g; + private boolean leftPressed; + + private boolean rightPressed; + + private boolean downPressed; + + private boolean okPressed; + + private boolean backPressed; + private GraphicEngine e; private Renderer r; @@ -50,6 +60,7 @@ public class TetrisScreen extends Screen { @Override public void beforeRender(final float dt) { Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glClearColor(0xff000000); + g.gameTick(dt, leftPressed, rightPressed, downPressed, okPressed, backPressed); } @Override @@ -58,7 +69,60 @@ public class TetrisScreen extends Screen { TetrisScreen.skin.use(e); } } - + + @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; + } + } @Override public boolean mustBeRefreshed() { return true; diff --git a/core/src/main/java/it/cavallium/warppi/gui/graphicengine/impl/common/RFTFont.java b/core/src/main/java/it/cavallium/warppi/gui/graphicengine/impl/common/RFTFont.java index 1e7ea476..af68f9cd 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/graphicengine/impl/common/RFTFont.java +++ b/core/src/main/java/it/cavallium/warppi/gui/graphicengine/impl/common/RFTFont.java @@ -19,7 +19,7 @@ import it.cavallium.warppi.gui.graphicengine.GraphicEngine; import it.cavallium.warppi.util.Utils; public abstract class RFTFont implements BinaryFont { - + public boolean[][] rawchars; public int[] chars32; public int minBound = 10;