summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk/tankontank')
-rw-r--r--core/src/ch/asynk/tankontank/game/Hud.java109
-rw-r--r--core/src/ch/asynk/tankontank/game/hud/Button.java102
2 files changed, 108 insertions, 103 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java
index 1639f3f..701f2d3 100644
--- a/core/src/ch/asynk/tankontank/game/Hud.java
+++ b/core/src/ch/asynk/tankontank/game/Hud.java
@@ -6,106 +6,14 @@ import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
-import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Rectangle;
import ch.asynk.tankontank.engine.gfx.Image;
+import ch.asynk.tankontank.game.hud.Button;
import ch.asynk.tankontank.TankOnTank;
-class Button implements Disposable
-{
-
- public int idx;
- public boolean visible;
- private Image images [];
- private Image image;
- private Rectangle rect;
-
- private static final int OFF = 0;
- private static final int ON = 1;
- private static final int DOWN = 2;
-
- public Button(TextureAtlas atlas, String base)
- {
- this.idx = OFF;
- this.visible = false;
- this.images = new Image[3];
- this.images[OFF] = new Image(atlas.findRegion(base + "-off"));
- this.images[ON] = new Image(atlas.findRegion(base + "-on"));
- this.images[DOWN] = new Image(atlas.findRegion(base + "-down"));
-
- this.rect = new Rectangle(getX(), getY(), getWidth(), getHeight());
- }
-
- @Override
- public void dispose()
- {
- for (Image image : images)
- image.dispose();
- }
-
- public void hide()
- {
- idx = OFF;
- visible = false;
- }
-
- public void setOff()
- {
- idx = OFF;
- }
-
- public void setOn()
- {
- idx = ON;
- }
-
- public void setDown()
- {
- idx = DOWN;
- }
-
- public boolean isOn()
- {
- return (idx == ON);
- }
-
- public boolean isOff()
- {
- return (idx == OFF);
- }
-
- public boolean isDisabled()
- {
- return (idx == DOWN);
- }
-
- public Image getImage()
- {
- return images[idx];
- }
-
- public void setPosition(float x, float y)
- {
- for (Image image : images)
- image.setPosition(x, y);
- rect.set(x, y, getWidth(), getHeight());
- }
-
- public boolean hit(float x, float y)
- {
- if (!visible) return false;
- return rect.contains(x,y);
- }
-
- public float getX() { return images[0].getX(); }
- public float getY() { return images[0].getY(); }
- public float getWidth() { return images[0].getWidth(); }
- public float getHeight() { return images[0].getHeight(); }
-}
-
public class Hud implements Disposable
{
private static final float OFFSET = 15f;
@@ -117,11 +25,11 @@ public class Hud implements Disposable
private Image geFlag;
private Image flag;
- private Button moveBtn;
- private Button rotateBtn;
- private Button attackBtn;
- private Button checkBtn;
- private Button cancelBtn;
+ public Button moveBtn;
+ public Button rotateBtn;
+ public Button attackBtn;
+ public Button checkBtn;
+ public Button cancelBtn;
private Button btn;
@@ -227,11 +135,6 @@ public class Hud implements Disposable
cancelBtn.hide();
}
- public void setRotateOff()
- {
- rotateBtn.setOff();
- }
-
public boolean touchDown(float x, float y)
{
if (infoRect.contains(x,y)) return true;
diff --git a/core/src/ch/asynk/tankontank/game/hud/Button.java b/core/src/ch/asynk/tankontank/game/hud/Button.java
new file mode 100644
index 0000000..b42a9cf
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/game/hud/Button.java
@@ -0,0 +1,102 @@
+package ch.asynk.tankontank.game.hud;
+
+import com.badlogic.gdx.Gdx;
+
+import com.badlogic.gdx.utils.Disposable;
+
+import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+import com.badlogic.gdx.math.Rectangle;
+
+import ch.asynk.tankontank.engine.gfx.Image;
+
+public class Button implements Disposable
+{
+
+ public int idx;
+ public boolean visible;
+ private Image images [];
+ private Image image;
+ private Rectangle rect;
+
+ private static final int OFF = 0;
+ private static final int ON = 1;
+ private static final int DOWN = 2;
+
+ public Button(TextureAtlas atlas, String base)
+ {
+ this.idx = OFF;
+ this.visible = false;
+ this.images = new Image[3];
+ this.images[OFF] = new Image(atlas.findRegion(base + "-off"));
+ this.images[ON] = new Image(atlas.findRegion(base + "-on"));
+ this.images[DOWN] = new Image(atlas.findRegion(base + "-down"));
+
+ this.rect = new Rectangle(getX(), getY(), getWidth(), getHeight());
+ }
+
+ @Override
+ public void dispose()
+ {
+ for (Image image : images)
+ image.dispose();
+ }
+
+ public void hide()
+ {
+ idx = OFF;
+ visible = false;
+ }
+
+ public void setOff()
+ {
+ idx = OFF;
+ }
+
+ public void setOn()
+ {
+ idx = ON;
+ }
+
+ public void setDown()
+ {
+ idx = DOWN;
+ }
+
+ public boolean isOn()
+ {
+ return (idx == ON);
+ }
+
+ public boolean isOff()
+ {
+ return (idx == OFF);
+ }
+
+ public boolean isDisabled()
+ {
+ return (idx == DOWN);
+ }
+
+ public Image getImage()
+ {
+ return images[idx];
+ }
+
+ public void setPosition(float x, float y)
+ {
+ for (Image image : images)
+ image.setPosition(x, y);
+ rect.set(x, y, getWidth(), getHeight());
+ }
+
+ public boolean hit(float x, float y)
+ {
+ if (!visible) return false;
+ return rect.contains(x,y);
+ }
+
+ public float getX() { return images[0].getX(); }
+ public float getY() { return images[0].getY(); }
+ public float getWidth() { return images[0].getWidth(); }
+ public float getHeight() { return images[0].getHeight(); }
+}