package levelGen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Animation.PlayMode;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.utils.Array;
import com.ld50.game.HF;

import Global.Global;

public class Glass extends Sprite {
	public enum State {
		UP, UPPERRIGHT, RIGHT, BOTTOMRIGHT, BOTTOMLEFT, LEFT, UPPERLEFT, DOWN, SHATTERUP, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, SHATTERUPPERRIGHT, UR1, UR2,
		UR3, UR4, UR5, UR6, UR7, UR8, UR9, UR10, SHATTERRIGHT, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, SHATTERBOTTOMRIGHT, BR1, BR2, BR3, BR4, BR5, BR6, BR7,
		BR8, BR9, BR10, SHATTERBOTTOM, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, SHATTERBOTTOMLEFT, BL1, BL2, BL3, BL4, BL5, BL6, BL7, BL8, BL9, BL10,
		SHATTERLEFT, L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, SHATTERUPPERLEFT, UL1, UL2, UL3, UL4, UL5, UL6, UL7, UL8, UL9, UL10
	};

	public State currentState;
	public State previousState;
	// private Animation<TextureRegion> main; this is for animated ones
	// private float _animBreakingTimer;
	private TextureAtlas atlas;
	private Animation<TextureRegion> shatterUp;
	private Animation<TextureRegion> shatterDown;
	private Animation<TextureRegion> shatterLeft;
	private Animation<TextureRegion> shatterRight;
	private Animation<TextureRegion> shatterUpperRight;
	private Animation<TextureRegion> shatterUpperLeft;
	private Animation<TextureRegion> shatterBottomLeft;
	private Animation<TextureRegion> shatterBottomRight;
	private TextureRegion up;
	private TextureRegion right;
	private TextureRegion left;
	private TextureRegion down;
	private TextureRegion upperLeft;
	private TextureRegion upperRight;
	private TextureRegion bottomLeft;
	private TextureRegion bottomRight;
	private TextureRegion crackUp;
	private TextureRegion crackUp2;
	private TextureRegion crackUp3;
	private TextureRegion crackUp4;
	private TextureRegion crackUp5;
	private TextureRegion crackUp6;
	private TextureRegion crackUp7;
	private TextureRegion crackUp8;
	private TextureRegion crackUp9;
	private TextureRegion crackUp10;
	private TextureRegion crackDown;
	private TextureRegion crackDown2;
	private TextureRegion crackDown3;
	private TextureRegion crackDown4;
	private TextureRegion crackDown5;
	private TextureRegion crackDown6;
	private TextureRegion crackDown7;
	private TextureRegion crackDown8;
	private TextureRegion crackDown9;
	private TextureRegion crackDown10;
	private TextureRegion crackRight;
	private TextureRegion crackRight2;
	private TextureRegion crackRight3;
	private TextureRegion crackRight4;
	private TextureRegion crackRight5;
	private TextureRegion crackRight6;
	private TextureRegion crackRight7;
	private TextureRegion crackRight8;
	private TextureRegion crackRight9;
	private TextureRegion crackRight10;
	private TextureRegion crackLeft;
	private TextureRegion crackLeft2;
	private TextureRegion crackLeft3;
	private TextureRegion crackLeft4;
	private TextureRegion crackLeft5;
	private TextureRegion crackLeft6;
	private TextureRegion crackLeft7;
	private TextureRegion crackLeft8;
	private TextureRegion crackLeft9;
	private TextureRegion crackLeft10;
	private TextureRegion crackUpperLeft;
	private TextureRegion crackUpperLeft2;
	private TextureRegion crackUpperLeft3;
	private TextureRegion crackUpperLeft4;
	private TextureRegion crackUpperLeft5;
	private TextureRegion crackUpperLeft6;
	private TextureRegion crackUpperLeft7;
	private TextureRegion crackUpperLeft8;
	private TextureRegion crackUpperLeft9;
	private TextureRegion crackUpperLeft10;
	private TextureRegion crackUpperRight;
	private TextureRegion crackUpperRight2;
	private TextureRegion crackUpperRight3;
	private TextureRegion crackUpperRight4;
	private TextureRegion crackUpperRight5;
	private TextureRegion crackUpperRight6;
	private TextureRegion crackUpperRight7;
	private TextureRegion crackUpperRight8;
	private TextureRegion crackUpperRight9;
	private TextureRegion crackUpperRight10;
	private TextureRegion crackBottomLeft;
	private TextureRegion crackBottomLeft2;
	private TextureRegion crackBottomLeft3;
	private TextureRegion crackBottomLeft4;
	private TextureRegion crackBottomLeft5;
	private TextureRegion crackBottomLeft6;
	private TextureRegion crackBottomLeft7;
	private TextureRegion crackBottomLeft8;
	private TextureRegion crackBottomLeft9;
	private TextureRegion crackBottomLeft10;
	private TextureRegion crackBottomRight;
	private TextureRegion crackBottomRight2;
	private TextureRegion crackBottomRight3;
	private TextureRegion crackBottomRight4;
	private TextureRegion crackBottomRight5;
	private TextureRegion crackBottomRight6;
	private TextureRegion crackBottomRight7;
	private TextureRegion crackBottomRight8;
	private TextureRegion crackBottomRight9;
	private TextureRegion crackBottomRight10;
	private Boolean isUp = false;
	private Boolean isRight = false;
	private Boolean isLeft = false;
	private Boolean isDown = false;
	private Boolean isUpperLeft = false;
	private Boolean isUpperRight = false;
	private Boolean isBottomLeft = false;
	private Boolean isBottomRight = false;
	public Color color;
	public int health = 11;
	public float speed;
	public Rectangle rect;
	private float _stateTimer;
	private int _sw;// sprite width
	private int _sh;// sprite height
	// sfx
	private float aSpd = .2f;
	private boolean isAnimationOver;
	private boolean oneSound;
	private Sound glassBreak;
	private Sound glassBreak2;
	private Sound glassBreak3;
	private Sound glassBreak4;
	private Sound glassBreak5;

	public Glass(float _x, float _y, State _state) {
		rect = new Rectangle();
		rect.x = (int) _x;
		rect.y = (int) _y;
		rect.width = 64;
		rect.height = 128;

		_sw = 64;
		_sh = 128;
		// this is for the animations
		currentState = _state;
		previousState = _state;

		glassBreak = Gdx.audio.newSound(Gdx.files.internal("sfx/glassBreak.ogg"));
		glassBreak2 = Gdx.audio.newSound(Gdx.files.internal("sfx/glassBreak2.ogg"));
		glassBreak3 = Gdx.audio.newSound(Gdx.files.internal("sfx/glassBreak3.ogg"));
		glassBreak4 = Gdx.audio.newSound(Gdx.files.internal("sfx/glassBreak4.ogg"));
		glassBreak5 = Gdx.audio.newSound(Gdx.files.internal("sfx/glassBreak5.ogg"));

		// get Tile atlas
		atlas = new TextureAtlas(Gdx.files.internal("glass.txt"));
		// still frames
		up = new TextureRegion(atlas.findRegion("glass"), 0, 0, _sw, _sh);
		down = new TextureRegion(atlas.findRegion("glass"), 0, 0, _sw, _sh);
		upperLeft = new TextureRegion(atlas.findRegion("glass"), 1 * _sw, 0, _sw, _sh);
		upperRight = new TextureRegion(atlas.findRegion("glass"), 1 * _sw, 0, _sw, _sh);
		upperRight.flip(true, false);
		left = new TextureRegion(atlas.findRegion("glass"), 2 * _sw, 0, _sw, _sh);
		right = new TextureRegion(atlas.findRegion("glass"), 2 * _sw, 0, _sw, _sh);
		right.flip(true, false);
		bottomLeft = new TextureRegion(atlas.findRegion("glass"), 3 * _sw, 0, _sw, _sh);
		bottomRight = new TextureRegion(atlas.findRegion("glass"), 3 * _sw, 0, _sw, _sh);
		bottomRight.flip(true, false);
		crackBottomLeft = new TextureRegion(atlas.findRegion("glass"), 4 * _sw, 0, _sw, _sh);
		crackBottomLeft2 = new TextureRegion(atlas.findRegion("glass"), 5 * _sw, 0, _sw, _sh);
		crackBottomLeft3 = new TextureRegion(atlas.findRegion("glass"), 6 * _sw, 0, _sw, _sh);
		crackBottomLeft4 = new TextureRegion(atlas.findRegion("glass"), 7 * _sw, 0, _sw, _sh);
		crackBottomLeft5 = new TextureRegion(atlas.findRegion("glass"), 8 * _sw, 0, _sw, _sh);
		crackBottomLeft6 = new TextureRegion(atlas.findRegion("glass"), 9 * _sw, 0, _sw, _sh);
		crackBottomLeft7 = new TextureRegion(atlas.findRegion("glass"), 10 * _sw, 0, _sw, _sh);
		crackBottomLeft8 = new TextureRegion(atlas.findRegion("glass"), 11 * _sw, 0, _sw, _sh);
		crackBottomLeft9 = new TextureRegion(atlas.findRegion("glass"), 0 * _sw, 1 * _sh, _sw, _sh);
		crackBottomLeft10 = new TextureRegion(atlas.findRegion("glass"), 1 * _sw, 1 * _sh, _sw, _sh);
		crackBottomRight = new TextureRegion(atlas.findRegion("glass"), 4 * _sw, 0, _sw, _sh);
		crackBottomRight.flip(true, false);
		crackBottomRight2 = new TextureRegion(atlas.findRegion("glass"), 5 * _sw, 0, _sw, _sh);
		crackBottomRight2.flip(true, false);
		crackBottomRight3 = new TextureRegion(atlas.findRegion("glass"), 6 * _sw, 0, _sw, _sh);
		crackBottomRight3.flip(true, false);
		crackBottomRight4 = new TextureRegion(atlas.findRegion("glass"), 7 * _sw, 0, _sw, _sh);
		crackBottomRight4.flip(true, false);
		crackBottomRight5 = new TextureRegion(atlas.findRegion("glass"), 8 * _sw, 0, _sw, _sh);
		crackBottomRight5.flip(true, false);
		crackBottomRight6 = new TextureRegion(atlas.findRegion("glass"), 9 * _sw, 0, _sw, _sh);
		crackBottomRight6.flip(true, false);
		crackBottomRight7 = new TextureRegion(atlas.findRegion("glass"), 10 * _sw, 0, _sw, _sh);
		crackBottomRight7.flip(true, false);
		crackBottomRight8 = new TextureRegion(atlas.findRegion("glass"), 11 * _sw, 0, _sw, _sh);
		crackBottomRight8.flip(true, false);
		crackBottomRight9 = new TextureRegion(atlas.findRegion("glass"), 0 * _sw, 1 * _sh, _sw, _sh);
		crackBottomRight9.flip(true, false);
		crackBottomRight10 = new TextureRegion(atlas.findRegion("glass"), 1 * _sw, 1 * _sh, _sw, _sh);
		crackBottomRight10.flip(true, false);
		Array<TextureRegion> frames = new Array<TextureRegion>();
		for (int i = 2; i <= 6; i++) {
			frames.add(new TextureRegion(atlas.findRegion("glass"), i * _sw, 1 * _sh, _sw, _sh));
		}
		shatterBottomLeft = new Animation<TextureRegion>(aSpd, frames, PlayMode.NORMAL);
		frames.clear();
		for (int i = 2; i <= 6; i++) {
			TextureRegion r = new TextureRegion(atlas.findRegion("glass"), i * _sw, 1 * _sh, _sw, _sh);
			r.flip(true, false);
			frames.add(r);
		}
		shatterBottomRight = new Animation<TextureRegion>(aSpd, frames, PlayMode.NORMAL);
		frames.clear();
		crackLeft = new TextureRegion(atlas.findRegion("glass"), 7 * _sw, 1 * _sh, _sw, _sh);
		crackLeft2 = new TextureRegion(atlas.findRegion("glass"), 8 * _sw, 1 * _sh, _sw, _sh);
		crackLeft3 = new TextureRegion(atlas.findRegion("glass"), 9 * _sw, 1 * _sh, _sw, _sh);
		crackLeft4 = new TextureRegion(atlas.findRegion("glass"), 10 * _sw, 1 * _sh, _sw, _sh);
		crackLeft5 = new TextureRegion(atlas.findRegion("glass"), 11 * _sw, 1 * _sh, _sw, _sh);
		crackLeft6 = new TextureRegion(atlas.findRegion("glass"), 0 * _sw, 2 * _sh, _sw, _sh);
		crackLeft7 = new TextureRegion(atlas.findRegion("glass"), 1 * _sw, 2 * _sh, _sw, _sh);
		crackLeft8 = new TextureRegion(atlas.findRegion("glass"), 2 * _sw, 2 * _sh, _sw, _sh);
		crackLeft9 = new TextureRegion(atlas.findRegion("glass"), 3 * _sw, 2 * _sh, _sw, _sh);
		crackLeft10 = new TextureRegion(atlas.findRegion("glass"), 4 * _sw, 2 * _sh, _sw, _sh);
		crackRight = new TextureRegion(atlas.findRegion("glass"), 7 * _sw, 1 * _sh, _sw, _sh);
		crackRight.flip(true, false);
		crackRight2 = new TextureRegion(atlas.findRegion("glass"), 8 * _sw, 1 * _sh, _sw, _sh);
		crackRight2.flip(true, false);
		crackRight3 = new TextureRegion(atlas.findRegion("glass"), 9 * _sw, 1 * _sh, _sw, _sh);
		crackRight3.flip(true, false);
		crackRight4 = new TextureRegion(atlas.findRegion("glass"), 10 * _sw, 1 * _sh, _sw, _sh);
		crackRight4.flip(true, false);
		crackRight5 = new TextureRegion(atlas.findRegion("glass"), 11 * _sw, 1 * _sh, _sw, _sh);
		crackRight5.flip(true, false);
		crackRight6 = new TextureRegion(atlas.findRegion("glass"), 0 * _sw, 2 * _sh, _sw, _sh);
		crackRight6.flip(true, false);
		crackRight7 = new TextureRegion(atlas.findRegion("glass"), 1 * _sw, 2 * _sh, _sw, _sh);
		crackRight7.flip(true, false);
		crackRight8 = new TextureRegion(atlas.findRegion("glass"), 2 * _sw, 2 * _sh, _sw, _sh);
		crackRight8.flip(true, false);
		crackRight9 = new TextureRegion(atlas.findRegion("glass"), 3 * _sw, 2 * _sh, _sw, _sh);
		crackRight9.flip(true, false);
		crackRight10 = new TextureRegion(atlas.findRegion("glass"), 4 * _sw, 2 * _sh, _sw, _sh);
		crackRight10.flip(true, false);
		for (int i = 5; i <= 9; i++) {
			frames.add(new TextureRegion(atlas.findRegion("glass"), i * _sw, 2 * _sh, _sw, _sh));
		}
		shatterLeft = new Animation<TextureRegion>(aSpd, frames, PlayMode.NORMAL);
		frames.clear();
		for (int i = 5; i <= 9; i++) {
			TextureRegion r = new TextureRegion(atlas.findRegion("glass"), i * _sw, 2 * _sh, _sw, _sh);
			r.flip(true, false);
			frames.add(r);
		}
		shatterRight = new Animation<TextureRegion>(aSpd, frames, PlayMode.NORMAL);
		frames.clear();
		crackUpperLeft = new TextureRegion(atlas.findRegion("glass"), 10 * _sw, 2 * _sh, _sw, _sh);
		crackUpperLeft2 = new TextureRegion(atlas.findRegion("glass"), 11 * _sw, 2 * _sh, _sw, _sh);
		crackUpperLeft3 = new TextureRegion(atlas.findRegion("glass"), 0 * _sw, 3 * _sh, _sw, _sh);
		crackUpperLeft4 = new TextureRegion(atlas.findRegion("glass"), 1 * _sw, 3 * _sh, _sw, _sh);
		crackUpperLeft5 = new TextureRegion(atlas.findRegion("glass"), 2 * _sw, 3 * _sh, _sw, _sh);
		crackUpperLeft6 = new TextureRegion(atlas.findRegion("glass"), 3 * _sw, 3 * _sh, _sw, _sh);
		crackUpperLeft7 = new TextureRegion(atlas.findRegion("glass"), 4 * _sw, 3 * _sh, _sw, _sh);
		crackUpperLeft8 = new TextureRegion(atlas.findRegion("glass"), 5 * _sw, 3 * _sh, _sw, _sh);
		crackUpperLeft9 = new TextureRegion(atlas.findRegion("glass"), 6 * _sw, 3 * _sh, _sw, _sh);
		crackUpperLeft10 = new TextureRegion(atlas.findRegion("glass"), 7 * _sw, 3 * _sh, _sw, _sh);
		crackUpperRight = new TextureRegion(atlas.findRegion("glass"), 10 * _sw, 2 * _sh, _sw, _sh);
		crackUpperRight.flip(true, false);
		crackUpperRight2 = new TextureRegion(atlas.findRegion("glass"), 11 * _sw, 2 * _sh, _sw, _sh);
		crackUpperRight2.flip(true, false);
		crackUpperRight3 = new TextureRegion(atlas.findRegion("glass"), 0 * _sw, 3 * _sh, _sw, _sh);
		crackUpperRight3.flip(true, false);
		crackUpperRight4 = new TextureRegion(atlas.findRegion("glass"), 1 * _sw, 3 * _sh, _sw, _sh);
		crackUpperRight4.flip(true, false);
		crackUpperRight5 = new TextureRegion(atlas.findRegion("glass"), 2 * _sw, 3 * _sh, _sw, _sh);
		crackUpperRight5.flip(true, false);
		crackUpperRight6 = new TextureRegion(atlas.findRegion("glass"), 3 * _sw, 3 * _sh, _sw, _sh);
		crackUpperRight6.flip(true, false);
		crackUpperRight7 = new TextureRegion(atlas.findRegion("glass"), 4 * _sw, 3 * _sh, _sw, _sh);
		crackUpperRight7.flip(true, false);
		crackUpperRight8 = new TextureRegion(atlas.findRegion("glass"), 5 * _sw, 3 * _sh, _sw, _sh);
		crackUpperRight8.flip(true, false);
		crackUpperRight9 = new TextureRegion(atlas.findRegion("glass"), 6 * _sw, 3 * _sh, _sw, _sh);
		crackUpperRight9.flip(true, false);
		crackUpperRight10 = new TextureRegion(atlas.findRegion("glass"), 7 * _sw, 3 * _sh, _sw, _sh);
		crackUpperRight10.flip(true, false);
		for (int i = 8; i <= 11; i++) {
			frames.add(new TextureRegion(atlas.findRegion("glass"), i * _sw, 3 * _sh, _sw, _sh));
			if (i == 11) {
				frames.add(new TextureRegion(atlas.findRegion("glass"), 0 * _sw, 4 * _sh, _sw, _sh));
			}
		}
		shatterUpperLeft = new Animation<TextureRegion>(aSpd, frames, PlayMode.NORMAL);
		frames.clear();
		for (int i = 8; i <= 11; i++) {
			TextureRegion r = new TextureRegion(atlas.findRegion("glass"), i * _sw, 3 * _sh, _sw, _sh);
			r.flip(true, false);
			frames.add(r);
			if (i == 11) {
				TextureRegion rr = new TextureRegion(atlas.findRegion("glass"), 0 * _sw, 4 * _sh, _sw, _sh);
				rr.flip(true, false);
				frames.add(rr);
			}
		}
		shatterUpperRight = new Animation<TextureRegion>(aSpd, frames, PlayMode.NORMAL);
		frames.clear();
		crackUp = new TextureRegion(atlas.findRegion("glass"), 1 * _sw, 4 * _sh, _sw, _sh);
		crackUp2 = new TextureRegion(atlas.findRegion("glass"), 2 * _sw, 4 * _sh, _sw, _sh);
		crackUp3 = new TextureRegion(atlas.findRegion("glass"), 3 * _sw, 4 * _sh, _sw, _sh);
		crackUp4 = new TextureRegion(atlas.findRegion("glass"), 4 * _sw, 4 * _sh, _sw, _sh);
		crackUp5 = new TextureRegion(atlas.findRegion("glass"), 5 * _sw, 4 * _sh, _sw, _sh);
		crackUp6 = new TextureRegion(atlas.findRegion("glass"), 6 * _sw, 4 * _sh, _sw, _sh);
		crackUp7 = new TextureRegion(atlas.findRegion("glass"), 7 * _sw, 4 * _sh, _sw, _sh);
		crackUp8 = new TextureRegion(atlas.findRegion("glass"), 8 * _sw, 4 * _sh, _sw, _sh);
		crackUp9 = new TextureRegion(atlas.findRegion("glass"), 9 * _sw, 4 * _sh, _sw, _sh);
		crackUp10 = new TextureRegion(atlas.findRegion("glass"), 10 * _sw, 4 * _sh, _sw, _sh);
		crackDown = new TextureRegion(atlas.findRegion("glass"), 1 * _sw, 4 * _sh, _sw, _sh);
		crackDown2 = new TextureRegion(atlas.findRegion("glass"), 2 * _sw, 4 * _sh, _sw, _sh);
		crackDown3 = new TextureRegion(atlas.findRegion("glass"), 3 * _sw, 4 * _sh, _sw, _sh);
		crackDown4 = new TextureRegion(atlas.findRegion("glass"), 4 * _sw, 4 * _sh, _sw, _sh);
		crackDown5 = new TextureRegion(atlas.findRegion("glass"), 5 * _sw, 4 * _sh, _sw, _sh);
		crackDown6 = new TextureRegion(atlas.findRegion("glass"), 6 * _sw, 4 * _sh, _sw, _sh);
		crackDown7 = new TextureRegion(atlas.findRegion("glass"), 7 * _sw, 4 * _sh, _sw, _sh);
		crackDown8 = new TextureRegion(atlas.findRegion("glass"), 8 * _sw, 4 * _sh, _sw, _sh);
		crackDown9 = new TextureRegion(atlas.findRegion("glass"), 9 * _sw, 4 * _sh, _sw, _sh);
		crackDown10 = new TextureRegion(atlas.findRegion("glass"), 10 * _sw, 4 * _sh, _sw, _sh);
		// add one because it's at the end, then do the loop...
		frames.add(new TextureRegion(atlas.findRegion("glass"), 11 * _sw, 4 * _sh, _sw, _sh));
		for (int i = 0; i <= 3; i++) {
			frames.add(new TextureRegion(atlas.findRegion("glass"), i * _sw, 5 * _sh, _sw, _sh));
		}
		shatterUp = new Animation<TextureRegion>(aSpd, frames, PlayMode.NORMAL);
		shatterDown = new Animation<TextureRegion>(aSpd, frames, PlayMode.NORMAL);
		frames.clear();
		color = Color.WHITE;
		setBounds(0, 0, _sw, _sh);
		setOriginCenter();
		if (_state == State.UP) {// set texture, not color here. i think... but it's just initial. the states below update constantly. ;-)
			isUp = true;
			rect.height = MathUtils.random(15f, 40f);
			setRegion(up);
		} else if (_state == State.LEFT) {
			isLeft = true;
			setRegion(left);
		} else if (_state == State.RIGHT) {
			isRight = true;
			rect.width = 19f;
			setRegion(right);
		} else if (_state == State.DOWN) {
			isDown = true;
			setRegion(down);
		} else if (_state == State.BOTTOMLEFT) {
			isBottomLeft = true;
			setRegion(bottomLeft);
		} else if (_state == State.UPPERLEFT) {
			isUpperLeft = true;
			rect.height = MathUtils.random(10f, 20f);
			setRegion(upperLeft);
		} else if (_state == State.UPPERRIGHT) {
			isUpperRight = true;
			rect.height = MathUtils.random(10f, 19f);
			setRegion(upperRight);
		} else {
			isBottomRight = true;
			rect.width = 19f;
			setRegion(bottomRight);
		}
		// System.out.println("state: " + _state);
	}

	public void update(State cs) {
		if ((cs == State.SHATTERUP || cs == State.SHATTERBOTTOM || cs == State.SHATTERBOTTOMLEFT || cs == State.SHATTERBOTTOMRIGHT || cs == State.SHATTERLEFT
				|| cs == State.SHATTERRIGHT || cs == State.SHATTERUPPERLEFT || cs == State.SHATTERUPPERRIGHT) && !oneSound) {
			oneSound = true;
			playRandomGlassShatterSound(5);
		}
	}

	// for all the animations: //this isn't even updated unless i call it from the other screen oh bother. *facepalm*
	public TextureRegion getFrame(OrthographicCamera camera, float dt) {
		currentState = getState();
		update(currentState);

		TextureRegion region;
		switch (currentState) {
		case UP:
			region = up;
			break;
		case DOWN:
			region = down;
			break;
		case LEFT:
			region = left;
			break;
		case RIGHT:
			region = right;
			break;
		case UPPERRIGHT:
			region = upperRight;
			break;
		case UPPERLEFT:
			region = upperLeft;
			break;
		case BOTTOMRIGHT:
			region = bottomRight;
			break;
		case BOTTOMLEFT:
			region = bottomLeft;
			break;
		case U1:
			region = crackUp;
			break;
		case U2:
			region = crackUp2;
			break;
		case U3:
			region = crackUp3;
			break;
		case U4:
			region = crackUp4;
			break;
		case U5:
			region = crackUp5;
			break;
		case U6:
			region = crackUp6;
			break;
		case U7:
			region = crackUp7;
			break;
		case U8:
			region = crackUp8;
			break;
		case U9:
			region = crackUp9;
			break;
		case U10:
			region = crackUp10;
			break;
		case SHATTERUP:
			region = shatterUp.getKeyFrame(_stateTimer, false);
			break;
		case UL1:
			region = crackUpperLeft;
			break;
		case UL2:
			region = crackUpperLeft2;
			break;
		case UL3:
			region = crackUpperLeft3;
			break;
		case UL4:
			region = crackUpperLeft4;
			break;
		case UL5:
			region = crackUpperLeft5;
			break;
		case UL6:
			region = crackUpperLeft6;
			break;
		case UL7:
			region = crackUpperLeft7;
			break;
		case UL8:
			region = crackUpperLeft8;
			break;
		case UL9:
			region = crackUpperLeft9;
			break;
		case UL10:
			region = crackUpperLeft10;
			break;
		case SHATTERUPPERLEFT:
			region = shatterUpperLeft.getKeyFrame(_stateTimer, false);
			break;
		case UR1:
			region = crackUpperRight;
			break;
		case UR2:
			region = crackUpperRight2;
			break;
		case UR3:
			region = crackUpperRight3;
			break;
		case UR4:
			region = crackUpperRight4;
			break;
		case UR5:
			region = crackUpperRight5;
			break;
		case UR6:
			region = crackUpperRight6;
			break;
		case UR7:
			region = crackUpperRight7;
			break;
		case UR8:
			region = crackUpperRight8;
			break;
		case UR9:
			region = crackUpperRight9;
			break;
		case UR10:
			region = crackUpperRight10;
			break;
		case SHATTERUPPERRIGHT:
			region = shatterUpperRight.getKeyFrame(_stateTimer, false);
			break;
		case R1:
			region = crackRight;
			break;
		case R2:
			region = crackRight2;
			break;
		case R3:
			region = crackRight3;
			break;
		case R4:
			region = crackRight4;
			break;
		case R5:
			region = crackRight5;
			break;
		case R6:
			region = crackRight6;
			break;
		case R7:
			region = crackRight7;
			break;
		case R8:
			region = crackRight8;
			break;
		case R9:
			region = crackRight9;
			break;
		case R10:
			region = crackRight10;
			break;
		case SHATTERRIGHT:
			region = shatterRight.getKeyFrame(_stateTimer, false);
			break;
		case BR1:
			region = crackBottomRight;
			break;
		case BR2:
			region = crackBottomRight2;
			break;
		case BR3:
			region = crackBottomRight3;
			break;
		case BR4:
			region = crackBottomRight4;
			break;
		case BR5:
			region = crackBottomRight5;
			break;
		case BR6:
			region = crackBottomRight6;
			break;
		case BR7:
			region = crackBottomRight7;
			break;
		case BR8:
			region = crackBottomRight8;
			break;
		case BR9:
			region = crackBottomRight9;
			break;
		case BR10:
			region = crackBottomRight10;
			break;
		case SHATTERBOTTOMRIGHT:
			region = shatterBottomRight.getKeyFrame(_stateTimer, false);
			break;
		case L1:
			region = crackLeft;
			break;
		case L2:
			region = crackLeft2;
			break;
		case L3:
			region = crackLeft3;
			break;
		case L4:
			region = crackLeft4;
			break;
		case L5:
			region = crackLeft5;
			break;
		case L6:
			region = crackLeft6;
			break;
		case L7:
			region = crackLeft7;
			break;
		case L8:
			region = crackLeft8;
			break;
		case L9:
			region = crackLeft9;
			break;
		case L10:
			region = crackLeft10;
			break;
		case SHATTERLEFT:
			region = shatterLeft.getKeyFrame(_stateTimer, false);
			break;
		case BL1:
			region = crackBottomLeft;
			break;
		case BL2:
			region = crackBottomLeft2;
			break;
		case BL3:
			region = crackBottomLeft3;
			break;
		case BL4:
			region = crackBottomLeft4;
			break;
		case BL5:
			region = crackBottomLeft5;
			break;
		case BL6:
			region = crackBottomLeft6;
			break;
		case BL7:
			region = crackBottomLeft7;
			break;
		case BL8:
			region = crackBottomLeft8;
			break;
		case BL9:
			region = crackBottomLeft9;
			break;
		case BL10:
			region = crackBottomLeft10;
			break;
		case SHATTERBOTTOMLEFT:
			region = shatterBottomLeft.getKeyFrame(_stateTimer, false);
			break;
		case D1:
			region = crackDown;
			break;
		case D2:
			region = crackDown2;
			break;
		case D3:
			region = crackDown3;
			break;
		case D4:
			region = crackDown4;
			break;
		case D5:
			region = crackDown5;
			break;
		case D6:
			region = crackDown6;
			break;
		case D7:
			region = crackDown7;
			break;
		case D8:
			region = crackDown8;
			break;
		case D9:
			region = crackDown9;
			break;
		case D10:
			region = crackDown10;
			break;
		case SHATTERBOTTOM:
			region = shatterDown.getKeyFrame(_stateTimer, false);
			break;
		default:
			region = up;
			break;
		}
		if (currentState != previousState)
			isAnimationOver = false;

		if (!isAnimationOver && currentState == previousState) {
			_stateTimer += dt;
		} else
			_stateTimer = 0;
		previousState = currentState;

		return region;
	}

	public State getState() {
		if (health <= 0 && isUp) {// this is out of bounds. heheh
			return State.SHATTERUP;
		} else if (health == 1 && isUp) {
			return State.U10;
		} else if (health == 2 && isUp) {
			return State.U9;
		} else if (health == 3 && isUp) {
			return State.U8;
		} else if (health == 4 && isUp) {
			return State.U7;
		} else if (health == 5 && isUp) {
			return State.U6;
		} else if (health == 6 && isUp) {
			return State.U5;
		} else if (health == 7 && isUp) {
			return State.U4;
		} else if (health == 8 && isUp) {
			return State.U3;
		} else if (health == 9 && isUp) {
			return State.U2;
		} else if (health == 10 && isUp) {
			return State.U1;
		} else if (health <= 0 && isUpperLeft) {
			return State.SHATTERUPPERLEFT;
		} else if (health == 1 && isUpperLeft) {
			return State.UL10;
		} else if (health == 2 && isUpperLeft) {
			return State.UL9;
		} else if (health == 3 && isUpperLeft) {
			return State.UL8;
		} else if (health == 4 && isUpperLeft) {
			return State.UL7;
		} else if (health == 5 && isUpperLeft) {
			return State.UL6;
		} else if (health == 6 && isUpperLeft) {
			return State.UL5;
		} else if (health == 7 && isUpperLeft) {
			return State.UL4;
		} else if (health == 8 && isUpperLeft) {
			return State.UL3;
		} else if (health == 9 && isUpperLeft) {
			return State.UL2;
		} else if (health == 10 && isUpperLeft) {
			return State.UL1;
		} else if (health <= 0 && isLeft) {
			return State.SHATTERLEFT;
		} else if (health == 1 && isLeft) {
			return State.L10;
		} else if (health == 2 && isLeft) {
			return State.L9;
		} else if (health == 3 && isLeft) {
			return State.L8;
		} else if (health == 4 && isLeft) {
			return State.L7;
		} else if (health == 5 && isLeft) {
			return State.L6;
		} else if (health == 6 && isLeft) {
			return State.L5;
		} else if (health == 7 && isLeft) {
			return State.L4;
		} else if (health == 8 && isLeft) {
			return State.L3;
		} else if (health == 9 && isLeft) {
			return State.L2;
		} else if (health == 10 && isLeft) {
			return State.L1;
		} else if (health <= 0 && isUpperRight) {
			return State.SHATTERUPPERRIGHT;
		} else if (health == 1 && isUpperRight) {
			return State.UR10;
		} else if (health == 2 && isUpperRight) {
			return State.UR9;
		} else if (health == 3 && isUpperRight) {
			return State.UR8;
		} else if (health == 4 && isUpperRight) {
			return State.UR7;
		} else if (health == 5 && isUpperRight) {
			return State.UR6;
		} else if (health == 6 && isUpperRight) {
			return State.UR5;
		} else if (health == 7 && isUpperRight) {
			return State.UR4;
		} else if (health == 8 && isUpperRight) {
			return State.UR3;
		} else if (health == 9 && isUpperRight) {
			return State.UR2;
		} else if (health == 10 && isUpperRight) {
			return State.UR1;
		} else if (health <= 0 && isRight) {
			return State.SHATTERRIGHT;
		} else if (health == 1 && isRight) {
			return State.R10;
		} else if (health == 2 && isRight) {
			return State.R9;
		} else if (health == 3 && isRight) {
			return State.R8;
		} else if (health == 4 && isRight) {
			return State.R7;
		} else if (health == 5 && isRight) {
			return State.R6;
		} else if (health == 6 && isRight) {
			return State.R5;
		} else if (health == 7 && isRight) {
			return State.R4;
		} else if (health == 8 && isRight) {
			return State.R3;
		} else if (health == 9 && isRight) {
			return State.R2;
		} else if (health == 10 && isRight) {
			return State.R1;
		} else if (health <= 0 && isBottomRight) {
			return State.SHATTERBOTTOMRIGHT;
		} else if (health == 1 && isBottomRight) {
			return State.BR10;
		} else if (health == 2 && isBottomRight) {
			return State.BR9;
		} else if (health == 3 && isBottomRight) {
			return State.BR8;
		} else if (health == 4 && isBottomRight) {
			return State.BR7;
		} else if (health == 5 && isBottomRight) {
			return State.BR6;
		} else if (health == 6 && isBottomRight) {
			return State.BR5;
		} else if (health == 7 && isBottomRight) {
			return State.BR4;
		} else if (health == 8 && isBottomRight) {
			return State.BR3;
		} else if (health == 9 && isBottomRight) {
			return State.BR2;
		} else if (health == 10 && isBottomRight) {
			return State.BR1;
		} else if (health <= 0 && isDown) {
			return State.SHATTERBOTTOM;
		} else if (health == 1 && isDown) {
			return State.D10;
		} else if (health == 2 && isDown) {
			return State.D9;
		} else if (health == 3 && isDown) {
			return State.D8;
		} else if (health == 4 && isDown) {
			return State.D7;
		} else if (health == 5 && isDown) {
			return State.D6;
		} else if (health == 6 && isDown) {
			return State.D5;
		} else if (health == 7 && isDown) {
			return State.D4;
		} else if (health == 8 && isDown) {
			return State.D3;
		} else if (health == 9 && isDown) {
			return State.D2;
		} else if (health == 10 && isDown) {
			return State.D1;
		} else if (health <= 0 && isBottomLeft) {
			return State.SHATTERBOTTOMLEFT;
		} else if (health == 1 && isBottomLeft) {
			return State.BL10;
		} else if (health == 2 && isBottomLeft) {
			return State.BL9;
		} else if (health == 3 && isBottomLeft) {
			return State.BL8;
		} else if (health == 4 && isBottomLeft) {
			return State.BL7;
		} else if (health == 5 && isBottomLeft) {
			return State.BL6;
		} else if (health == 6 && isBottomLeft) {
			return State.BL5;
		} else if (health == 7 && isBottomLeft) {
			return State.BL4;
		} else if (health == 8 && isBottomLeft) {
			return State.BL3;
		} else if (health == 9 && isBottomLeft) {
			return State.BL2;
		} else if (health == 10 && isBottomLeft) {
			return State.BL1;
		} else if (isUp) {
			return State.UP;
		} else if (isUpperRight) {
			return State.UPPERRIGHT;
		} else if (isRight) {
			return State.RIGHT;
		} else if (isBottomRight) {
			return State.BOTTOMRIGHT;
		} else if (isDown) {
			return State.DOWN;
		} else if (isBottomLeft) {
			return State.BOTTOMLEFT;
		} else if (isLeft) {
			return State.LEFT;
		} else if (isUpperLeft) {
			return State.UPPERLEFT;
		} else {
			return State.UP;
		}
	}

	public void playRandomGlassShatterSound(int numberOfSounds) {
		int randomSound = MathUtils.random(1, numberOfSounds);
		if (!Global.SetVolumeToZero) {
			if (randomSound == 1)
				glassBreak.play();
			else if (randomSound == 2)
				glassBreak2.play();
			else if (randomSound == 3)
				glassBreak3.play();
			else if (randomSound == 4)
				glassBreak4.play();
			else if (randomSound == 5)
				glassBreak5.play();
		}
	}

	public void render(HF game, OrthographicCamera camera, float dt) {// hmmm i think it just needs placed before? it gets here.
		game.batch.setColor(color);
		game.batch.draw(getFrame(camera, dt), rect.x, rect.y);
	}

	public void dispose() {
		glassBreak.dispose();
		glassBreak2.dispose();
		glassBreak3.dispose();
		glassBreak4.dispose();
		glassBreak5.dispose();
		atlas.dispose();
	}
}
