From a9f54e6e2d503f5f07c427a9fb928fca61f5d194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sat, 1 Nov 2014 11:33:45 +0100 Subject: add game/hud/Position --- .../src/ch/asynk/tankontank/game/hud/Position.java | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 core/src/ch/asynk/tankontank/game/hud/Position.java diff --git a/core/src/ch/asynk/tankontank/game/hud/Position.java b/core/src/ch/asynk/tankontank/game/hud/Position.java new file mode 100644 index 0000000..219d4ed --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/hud/Position.java @@ -0,0 +1,69 @@ +package ch.asynk.tankontank.game.hud; + +import com.badlogic.gdx.Gdx; + +public enum Position +{ + TOP_LEFT, + TOP_RIGHT, + TOP_CENTER, + MIDDLE_LEFT, + MIDDLE_RIGHT, + MIDDLE_CENTER, + BOTTOM_LEFT, + BOTTOM_RIGHT, + BOTTOM_CENTER; + private float offset = 40f; + + public float getX(float width) + { + float x; + switch(this) { + case TOP_LEFT: + case MIDDLE_LEFT: + case BOTTOM_LEFT: + x = offset; + break; + case TOP_CENTER: + case MIDDLE_CENTER: + case BOTTOM_CENTER: + x = ((Gdx.graphics.getWidth() - width) / 2); + break; + case TOP_RIGHT: + case MIDDLE_RIGHT: + case BOTTOM_RIGHT: + x = (Gdx.graphics.getWidth() - width - offset); + break; + default: + x = ((Gdx.graphics.getWidth() - width) / 2); + break; + } + return x; + } + + public float getY(float height) + { + float y; + switch(this) { + case TOP_LEFT: + case TOP_CENTER: + case TOP_RIGHT: + y = (Gdx.graphics.getHeight() - height - offset); + break; + case MIDDLE_LEFT: + case MIDDLE_CENTER: + case MIDDLE_RIGHT: + y = ((Gdx.graphics.getHeight() - height) / 2); + break; + case BOTTOM_LEFT: + case BOTTOM_CENTER: + case BOTTOM_RIGHT: + y = offset; + break; + default: + y = ((Gdx.graphics.getHeight() - height) / 2); + break; + } + return y; + } +} -- cgit v1.1-2-g2b99