summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/zproject
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk/zproject')
-rw-r--r--core/src/ch/asynk/zproject/GameBoard.java59
-rw-r--r--core/src/ch/asynk/zproject/GameHud.java53
-rw-r--r--core/src/ch/asynk/zproject/GameScreen.java37
3 files changed, 122 insertions, 27 deletions
diff --git a/core/src/ch/asynk/zproject/GameBoard.java b/core/src/ch/asynk/zproject/GameBoard.java
index 2b95f47..4d3f774 100644
--- a/core/src/ch/asynk/zproject/GameBoard.java
+++ b/core/src/ch/asynk/zproject/GameBoard.java
@@ -3,24 +3,30 @@ package ch.asynk.zproject;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.utils.Disposable;
+import com.badlogic.gdx.math.Vector2;
import ch.asynk.zproject.engine.Touchable;
+import ch.asynk.zproject.engine.Board;
+import ch.asynk.zproject.engine.board.BoardFactory;
public class GameBoard implements Disposable, Touchable
{
private final Texture map;
+ private Board board;
private int dx;
private int dy;
private int w;
private int h;
private float r;
- private boolean rotate = false;
+
+ private Vector2 v;
public GameBoard(final Assets assets)
{
this.map = assets.getTexture(assets.MAP_00);
- computeValues();
+ this.v = new Vector2();
+ setState(GameScreen.State.UI);
}
@Override public void dispose()
@@ -30,31 +36,44 @@ public class GameBoard implements Disposable, Touchable
@Override public boolean touch(float x, float y)
{
- ZProject.debug("GameBoard", String.format("touchDown : %f %f", x, y));
+ board.toBoard(x, y, v);
+ ZProject.debug("BoardGame", String.format("touchDown [%d;%d] => [%d;%d]", (int)x, (int)y, (int)v.x, (int)v.y));
+ board.centerOf((int)v.x, (int)v.y, v);
+ ZProject.debug("BoardGame", String.format(" => [%d;%d]", (int)v.x, (int)v.y));
return true;
}
- public void setRotate(boolean rotate)
+ public void setState(GameScreen.State state)
{
- this.rotate = rotate;
- computeValues();
+ switch (state) {
+ case UI:
+ case HEX_V:
+ setHEX_V();
+ break;
+ case HEX_H:
+ setHEX_H();
+ break;
+ }
}
- private void computeValues()
+ private void setHEX_V()
{
- if (rotate) {
- r = 90;
- dx = - ( map.getWidth() - map.getHeight() ) / 2;
- dy = - dx;
- w = map.getHeight();
- h = map.getWidth();
- } else {
- r = 0;
- dx = 0;
- dy = 0;
- w = map.getWidth();
- h = map.getHeight();
- }
+ r = 0;
+ dx = 0;
+ dy = 0;
+ w = map.getWidth();
+ h = map.getHeight();
+ this.board = BoardFactory.getBoard(BoardFactory.BoardType.HEX, 10, 9, 110, 50, 103, BoardFactory.BoardOrientation.VERTICAL);
+ }
+
+ private void setHEX_H()
+ {
+ r = 90;
+ dx = - ( map.getWidth() - map.getHeight() ) / 2;
+ dy = - dx;
+ w = map.getHeight();
+ h = map.getWidth();
+ this.board = BoardFactory.getBoard(BoardFactory.BoardType.HEX, 9, 10, 110, 103, 50, BoardFactory.BoardOrientation.HORIZONTAL);
}
public int getWidth()
diff --git a/core/src/ch/asynk/zproject/GameHud.java b/core/src/ch/asynk/zproject/GameHud.java
index 631a53c..38b2551 100644
--- a/core/src/ch/asynk/zproject/GameHud.java
+++ b/core/src/ch/asynk/zproject/GameHud.java
@@ -1,5 +1,7 @@
package ch.asynk.zproject;
+import java.util.function.Supplier;
+
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
@@ -16,9 +18,13 @@ public class GameHud implements Disposable, Touchable
private final Root root;
private final Button hello;
private final Button next;
+ private GameScreen.State state;
+ private final Supplier<GameScreen.State> nextState;
- public GameHud(final Assets assets)
+ public GameHud(final Assets assets, GameScreen.State state, Supplier<GameScreen.State> nextState)
{
+ this.state = state;
+ this.nextState = nextState;
this.corner = new Sprite(assets.getTexture(assets.CORNER));
this.root = new Root(2);
@@ -45,6 +51,8 @@ public class GameHud implements Disposable, Touchable
{
if (root.touch(x, y)) {
ZProject.debug("GameHud", String.format("touchDown : %f %f", x, y));
+ if (root.touched() == this.next)
+ onNext();
return true;
}
return false;
@@ -55,13 +63,50 @@ public class GameHud implements Disposable, Touchable
this.root.resize(width, height);
}
+ public void onNext()
+ {
+ this.state = nextState.get();
+ switch (this.state) {
+ case UI:
+ updateNext(50, Alignment.MIDDLE_CENTER);
+ this.root.add(this.hello);
+ break;
+ case HEX_V:
+ updateNext(0, Alignment.BOTTOM_RIGHT);
+ this.root.remove(this.hello);
+ break;
+ case HEX_H:
+ break;
+ }
+ }
+
+ private void updateNext(int p, Alignment a)
+ {
+ this.next.setPosition(p, p);
+ this.next.setAlignment(a);
+ this.next.update();
+ }
+
public void draw(Batch batch)
{
- drawButtons(batch);
- drawCorners(batch);
+ switch (this.state) {
+ case UI:
+ drawButtons(batch);
+ drawCorners(batch);
+ break;
+ case HEX_V:
+ case HEX_H:
+ drawRoot(batch);
+ break;
+ }
+ }
+
+ private void drawRoot(Batch batch)
+ {
+ root.draw(batch);
}
- public void drawCorners(Batch batch)
+ private void drawCorners(Batch batch)
{
float right = root.getX() + root.getWidth() - corner.getWidth();
float top = root.getY() + root.getHeight() - corner.getHeight();
diff --git a/core/src/ch/asynk/zproject/GameScreen.java b/core/src/ch/asynk/zproject/GameScreen.java
index 47c8e5e..02b7db5 100644
--- a/core/src/ch/asynk/zproject/GameScreen.java
+++ b/core/src/ch/asynk/zproject/GameScreen.java
@@ -38,10 +38,29 @@ public class GameScreen implements Screen
private float inputDelay;
private boolean inputBlocked;
+ public enum State
+ {
+ UI, HEX_V, HEX_H;
+ public State next()
+ {
+ switch(this) {
+ case UI:
+ return HEX_V;
+ case HEX_V:
+ return HEX_H;
+ case HEX_H:
+ return UI;
+ default:
+ return UI;
+ }
+ }
+ }
+ private State state;
+
public GameScreen(final ZProject zproject)
{
this.zproject = zproject;
- this.hud = new GameHud(zproject.assets);
+ this.hud = new GameHud(zproject.assets, State.UI, () -> nextState());
this.board = new GameBoard(zproject.assets);
this.batch = new SpriteBatch();
this.camera = new Camera(10, board.getWidth(), board.getHeight(), 1.0f, 0.3f, false);
@@ -49,9 +68,19 @@ public class GameScreen implements Screen
this.paused = false;
this.inputDelay = 0f;
this.inputBlocked = false;
+ this.state = State.UI;
if (DEBUG) this.debugShapes = new ShapeRenderer();
}
+ public State nextState()
+ {
+ this.state = this.state.next();
+ this.board.setState(this.state);
+ this.camera.setDimension(board.getWidth(), board.getHeight());
+ zoom(1);
+ return this.state;
+ }
+
@Override public void render(float delta)
{
if (paused) return;
@@ -150,8 +179,10 @@ public class GameScreen implements Screen
dragPos.set(x, y);
camera.unproject(x, y, boardTouch);
camera.unprojectHud(x, y, hudTouch);
- if(!hud.touch(hudTouch.x, hudTouch.y))
- board.touch(boardTouch.x, boardTouch.y);
+ if (!hud.touch(hudTouch.x, hudTouch.y)) {
+ if (state != State.UI)
+ board.touch(boardTouch.x, boardTouch.y);
+ }
}
return true;
}