summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-15 17:24:18 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-15 17:24:18 +0200
commita043f7be9a33ec9f5aa57e18b1ae26878496720c (patch)
tree41f3fcc7c5c82d2ab68d01850031e84f82c7ecb3 /core/src/ch/asynk
parent68de02c5a844c260be3223541f19ba3c2e5c46d3 (diff)
downloadRustAndDust-a043f7be9a33ec9f5aa57e18b1ae26878496720c.zip
RustAndDust-a043f7be9a33ec9f5aa57e18b1ae26878496720c.tar.gz
Bg: rect is protected
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/tankontank/game/Hud.java16
-rw-r--r--core/src/ch/asynk/tankontank/game/hud/Bg.java51
2 files changed, 61 insertions, 6 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java
index 278643e..e50396d 100644
--- a/core/src/ch/asynk/tankontank/game/Hud.java
+++ b/core/src/ch/asynk/tankontank/game/Hud.java
@@ -11,6 +11,7 @@ import com.badlogic.gdx.math.Rectangle;
import ch.asynk.tankontank.engine.gfx.Image;
import ch.asynk.tankontank.game.hud.Button;
+import ch.asynk.tankontank.game.hud.Bg;
import ch.asynk.tankontank.TankOnTank;
@@ -23,6 +24,7 @@ public class Hud implements Disposable
private Image flag;
+ private Bg bg;
public Button moveBtn;
public Button rotateBtn;
public Button promoteBtn;
@@ -33,7 +35,6 @@ public class Hud implements Disposable
private Button btn;
private Rectangle infoRect;
- private Rectangle buttonsRect;
private float elapsed;
private Vector2 bottomLeft;
@@ -52,6 +53,8 @@ public class Hud implements Disposable
checkBtn = new Button(atlas, "btn-check");
cancelBtn = new Button(atlas, "btn-cancel");
+ bg = new Bg(atlas.findRegion("disabled"));
+
updatePlayer();
flag.setPosition(OFFSET, (Gdx.graphics.getHeight() - flag.getHeight() - OFFSET));
@@ -60,7 +63,6 @@ public class Hud implements Disposable
// - Turn
infoRect = new Rectangle(flag.getX(), flag.getY(), flag.getWidth(), flag.getHeight());
- buttonsRect = new Rectangle(0, 0, 0, 0);
elapsed = 0f;
}
@@ -74,6 +76,7 @@ public class Hud implements Disposable
attackBtn.dispose();
checkBtn.dispose();
cancelBtn.dispose();
+ bg.dispose();
}
public void animate(float delta)
@@ -83,6 +86,7 @@ public class Hud implements Disposable
public void draw(Batch batch)
{
flag.draw(batch);
+ bg.draw(batch);
if (moveBtn.visible) moveBtn.getImage().draw(batch);
if (rotateBtn.visible) rotateBtn.getImage().draw(batch);
if (promoteBtn.visible) promoteBtn.getImage().draw(batch);
@@ -123,7 +127,7 @@ public class Hud implements Disposable
if (check) y = setButton(checkBtn, x, y);
else checkBtn.hide();
- buttonsRect.set(x, bottomLeft.y, checkBtn.getWidth(), (y - bottomLeft.y));
+ bg.set(x, bottomLeft.y, checkBtn.getWidth(), (y - bottomLeft.y));
}
public void hide()
@@ -134,13 +138,13 @@ public class Hud implements Disposable
attackBtn.hide();
checkBtn.hide();
cancelBtn.hide();
- buttonsRect.set(0, 0, 0, 0);
+ bg.set(0, 0, 0, 0);
}
public boolean touchDown(float x, float y)
{
if (infoRect.contains(x,y)) return true;
- if (!buttonsRect.contains(x,y)) return false;
+ if (!bg.contains(x,y)) return false;
btn = null;
@@ -172,7 +176,7 @@ public class Hud implements Disposable
ctrl.endTurn();
return true;
}
- if (!buttonsRect.contains(x,y)) return false;
+ if (!bg.contains(x,y)) return false;
if (btn == moveBtn)
ctrl.setState(State.StateType.MOVE);
diff --git a/core/src/ch/asynk/tankontank/game/hud/Bg.java b/core/src/ch/asynk/tankontank/game/hud/Bg.java
new file mode 100644
index 0000000..f862088
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/game/hud/Bg.java
@@ -0,0 +1,51 @@
+package ch.asynk.tankontank.game.hud;
+
+import com.badlogic.gdx.utils.Disposable;
+import com.badlogic.gdx.graphics.g2d.Batch;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
+import com.badlogic.gdx.math.Rectangle;
+
+import ch.asynk.tankontank.engine.gfx.Drawable;
+
+public class Bg implements Drawable, Disposable
+{
+ private TextureRegion region;
+ protected Rectangle rect;
+
+ public Bg(TextureRegion region)
+ {
+ this.region = region;
+ this.rect = new Rectangle(0, 0, 0, 0);
+ }
+
+ public void set(float x, float y, float w, float h)
+ {
+ rect.x = x;
+ rect.y = y;
+ rect.width = w;
+ rect.height = h;
+ }
+
+ public boolean contains(float x, float y)
+ {
+ return rect.contains(x, y);
+ }
+
+ @Override
+ public void dispose()
+ {
+ }
+
+ @Override
+ public void draw(Batch batch)
+ {
+ batch.draw(region, rect.x, rect.y, rect.width, rect.height);
+ }
+
+ @Override
+ public void drawDebug(ShapeRenderer shapes)
+ {
+ shapes.rect(rect.x, rect.y, rect.width, rect.height);
+ }
+}