summaryrefslogtreecommitdiffstats
path: root/core/src/ch
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-11-09 00:35:54 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-11-09 00:35:54 +0100
commit6f177b99a693a8468062c00d8bde0f6e2df98956 (patch)
tree196f7082ba1b8151bcf3a847af8f02bc2c1d63a8 /core/src/ch
parent8e81108c9374eddfdb01396e8b00b17dd709bb45 (diff)
downloadRustAndDust-6f177b99a693a8468062c00d8bde0f6e2df98956.zip
RustAndDust-6f177b99a693a8468062c00d8bde0f6e2df98956.tar.gz
add game/hud/Widget
Diffstat (limited to 'core/src/ch')
-rw-r--r--core/src/ch/asynk/tankontank/game/hud/Widget.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/game/hud/Widget.java b/core/src/ch/asynk/tankontank/game/hud/Widget.java
new file mode 100644
index 0000000..aa99607
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/game/hud/Widget.java
@@ -0,0 +1,55 @@
+package ch.asynk.tankontank.game.hud;
+
+import com.badlogic.gdx.utils.Disposable;
+import com.badlogic.gdx.math.Rectangle;
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
+
+import ch.asynk.tankontank.engine.gfx.Drawable;
+
+public abstract class Widget implements Disposable, Drawable
+{
+ public boolean blocked;
+ public boolean visible;
+ protected Rectangle rect;
+
+ protected Widget()
+ {
+ this.blocked = false;
+ this.visible = true;
+ this.rect = new Rectangle(0, 0, 0, 0);
+ }
+
+ public float getX() { return rect.x; }
+ public float getY() { return rect.y; }
+ public float getWidth() { return rect.width; }
+ public float getHeight() { return rect.height; }
+
+ public void set(Rectangle base)
+ {
+ rect.set(base);
+ }
+
+ public void set(float x, float y, float w, float h)
+ {
+ rect.set(x, y, w, h);
+ }
+
+ public void setPosition(float x, float y)
+ {
+ rect.x = x;
+ rect.y = y;
+ }
+
+ public boolean hit(float x, float y)
+ {
+ if (blocked || !visible) return false;
+ return rect.contains(x, y);
+ }
+
+ @Override
+ public void drawDebug(ShapeRenderer shapes)
+ {
+ if (!visible) return;
+ shapes.rect(rect.x, rect.y, rect.width, rect.height);
+ }
+}