package com.ld52.agent;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ScreenUtils;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;

import java.util.Iterator;

import Global.Global;
import entities.Ball;
import entities.EvilAgent;
import entities.EvilPlane;
import entities.Harvester;
import entities.Kitten;
import entities.PausePerson;
import entities.Person;
import entities.Plant;
import entities.Player;
import entities.SavingTruck;
import entities.Worker;
import u.Uinput;
import u.UsefulMethods;

public class GameScreen implements Screen {
	final Agent game;

	private Music levelMusic;
	private OrthographicCamera camera;
	private Viewport vport;
	private Player player;
	int currentFrame = 1;
	int MAX_FRAMES = 5;
	// private LevelTmx levelTmx;
	public int sw = 1600;// was 1440
	public int sh = 900;// 720
	private int cameraMoveTimer = 25;

	private Array<EvilAgent> evilAgents;
	private Array<Plant> plants;
	private Array<Person> peoples;
	private Array<Kitten> kittens;
	private Array<Worker> workers;
	private Array<Ball> balls;
	private Vector3 pos23;
	private Vector3 mousePos;
	// add pause person. This is added to ever screen in the game you want a pause menu.
	private PausePerson pp;
	private Harvester harvester;
	private SavingTruck savingTruck;
	private EvilPlane evilPlane;
	// test the hamsterwheel
//	private HamsterWheel hamsterWheel;
//	private HamsterWheelIcon hamsterWheelIcon;
//	private HoverHamsterWheel hoverHamsterWheel;
//	private Turret turret;
//	private TurretIcon turretIcon;
//	private HoverTurret hoverTurret;
	private Ball ball;
	private Sound enter;
	private Sound enter2;
	// other sfx
	private Sound hit;
	private Sound clunk;
	private Sound death;

	private int isDeadTimer = 40;

	private int gameTimer = 0;
	private int translateTimer = 600;// 60fps... so yeah. lol

	private boolean goal;

	private boolean isEverythingLoaded;

	private String whatIsLoading;
	private int delayTimer;
	private int DTSpd = 2;// was 5

	private boolean leftLoop;

	private boolean isLevelAdded;
	private boolean isPlayerAdded;

	private Sound click;
	private Sound click2;
	private Sound click3;
	private Sound click4;
	private Sound click5;
	private Sound click6;
	private Sound click7;
	private Sound dropGun2;
	private Sound grind;
	private Sound grind2;
	private Sound grind3;
	private Sound yay;
	private Sound horn;
	private Sound stampLight;

	private boolean isHarvesterAdded;
	private boolean harvesterLoop;
	private boolean isDelayTimerActive;
	private boolean masterSwitch;

	private boolean evilAgentLoop;
	private boolean isEvilAgentsAdded;
	private int addTimer;
	private int goalTimer;
	private int testTimer;

	private Vector2 sp;

	private Vector2 sps;

	private Vector2 ep;

	private Vector2 eps;

	private boolean isPlantsAdded;

	private boolean plantLoop;

	private boolean personLoop;

	private boolean kittenLoop;

	private boolean isPeoplesAdded;

	private boolean isKittensAdded;

	private boolean workerLoop;

	private boolean isWorkersAdded;

	private int dropStuffOffTimer;

	public GameScreen(final Agent game) {
		this.game = game;
		// camera
		camera = new OrthographicCamera();
		vport = new FitViewport(sw, sh, camera);
		System.out.println("trying to create all the things!");
		// sounds
		// music
		levelMusic = Gdx.audio.newMusic(Gdx.files.internal("sfx/Mood.ogg"));
		levelMusic.setLooping(true);
		camera.position.set(vport.getWorldWidth() / 2, vport.getWorldHeight() / 2, 0);
		// font
		Agent.Score = 0;
		// sfx
		// hit = Gdx.audio.newSound(Gdx.files.internal("sfx/hit.ogg"));
		death = Gdx.audio.newSound(Gdx.files.internal("sfx/death.ogg"));
		click = Gdx.audio.newSound(Gdx.files.internal("sfx/click.ogg"));
		click2 = Gdx.audio.newSound(Gdx.files.internal("sfx/click2.ogg"));
		click3 = Gdx.audio.newSound(Gdx.files.internal("sfx/click3.ogg"));
		click4 = Gdx.audio.newSound(Gdx.files.internal("sfx/click4.ogg"));
		click5 = Gdx.audio.newSound(Gdx.files.internal("sfx/click5.ogg"));
		click6 = Gdx.audio.newSound(Gdx.files.internal("sfx/click6.ogg"));
		click7 = Gdx.audio.newSound(Gdx.files.internal("sfx/click7.ogg"));
		grind = Gdx.audio.newSound(Gdx.files.internal("sfx/grind.ogg"));
		grind2 = Gdx.audio.newSound(Gdx.files.internal("sfx/grind2.ogg"));
		grind3 = Gdx.audio.newSound(Gdx.files.internal("sfx/grind3.ogg"));
		yay = Gdx.audio.newSound(Gdx.files.internal("sfx/yay.ogg"));
		dropGun2 = Gdx.audio.newSound(Gdx.files.internal("sfx/dropGun2.ogg"));
		horn = Gdx.audio.newSound(Gdx.files.internal("sfx/horn.ogg"));
		hit = Gdx.audio.newSound(Gdx.files.internal("sfx/spin.ogg"));
		clunk = Gdx.audio.newSound(Gdx.files.internal("sfx/spin2.ogg"));
		stampLight = Gdx.audio.newSound(Gdx.files.internal("sfx/flutter.ogg"));
		// add pause person. This is added to every screen in the game you want a pause menu.
		pp = new PausePerson(Gdx.graphics.getWidth() / 2 - 210, Gdx.graphics.getHeight() - 235f);
		enter = Gdx.audio.newSound(Gdx.files.internal("sfx/click7.ogg"));
		enter2 = Gdx.audio.newSound(Gdx.files.internal("sfx/click8.ogg"));
		// add an empty array to fill as the game goes on. ;-)
		kittens = new Array<Kitten>();
		peoples = new Array<Person>();
		plants = new Array<Plant>();
		workers = new Array<Worker>();
		evilAgents = new Array<EvilAgent>();
		balls = new Array<Ball>();
		// adding this hover hamster. It will just be following the mouse around all the time, but visibly will be toggled... :O
		pos23 = camera.unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0));
		mousePos = camera.unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0));
//		hoverHamsterWheel = new HoverHamsterWheel(pos23.x, pos23.y);
//		hoverTurret = new HoverTurret(pos23.x, pos23.y);
		ball = new Ball(9000, 9000, 9000, 9000);
		if (Agent.HarvesterHealth < 2000)
			Agent.HarvesterHealth += 2000;
	}

	/*
	 * private void RenderAllTheGlass(HF game, OrthographicCamera camera, float dt) { for (int d = 0; d < glassTop.size; d++) { glassTop.get(d).render(game,
	 * camera, dt); } for (int d = 0; d < glassLeft.size; d++) { glassLeft.get(d).render(game, camera, dt); } for (int d = 0; d < glassRight.size; d++) {
	 * glassRight.get(d).render(game, camera, dt); } glassUpperRight.render(game, camera, dt); glassUpperLeft.render(game, camera, dt); }
	 */

	public void update(float dt) {
		if (player.isDying) {
			// don't move camera. :D ?? maybe?
			if (cameraMoveTimer > 0) {
				cameraMoveTimer--;
				UsefulMethods.MoveCameraAroundRandomly(camera);
			}
		} else {
			// System.out.println("cameraX: " + camera.position.x + " cameraY: " + camera.position.y);
			// System.out.println("getGraphicsWidth : " + (Gdx.graphics.getWidth()));
			// System.out.println("getGraphicsHeight: " + Gdx.graphics.getHeight());
			// System.out.println("Level width: " + level.w * Agent.TW);
			// System.out.println("Level height:" + level.h * Agent.TH);
			/*
			 * if (camera.position.x <= 0) camera.position.x = 1; else if (camera.position.x >= level.w * Agent.TW - (Gdx.graphics.getWidth() / 2))
			 * camera.position.x = level.w * Agent.TW - (Gdx.graphics.getWidth() / 2) - 1; else camera.position.x = player.rect.x; if (camera.position.y >
			 * level.h * Agent.TH - (Gdx.graphics.getHeight() / 2)) camera.position.y = level.h * Agent.TH - (Gdx.graphics.getHeight() / 2) - 1; else if
			 * (camera.position.y < 0) camera.position.y = 1; else camera.position.y = player.rect.y;
			 */
			// camera.xy = render_camera.xy + (displacement.xy + subsampling.xy) / upscale;
			camera.position.x = (int) Math.floor(player.rect.x);
			camera.position.y = (int) Math.floor(player.rect.y);
		}
		// isMouseClickingOnMouseWheelIcon();
		setGameTimer();
		goalTimer++;
		translateTimer--;
		camera.update();
	}

	@Override
	public void show() {
		Gdx.input.setInputProcessor(new InputAdapter() {
			@Override
			public boolean keyDown(int keyCode) {
				// add this first part for the pause portion of the screen. The escape button. Otherwise retain the space control.
				// Maybe we'll have a clickable button on the bottom side for options?
				if (keyCode == Input.Keys.ESCAPE && !Global.IsPaused) {
					if (!Global.SetVolumeToZero)
						enter.play(2f);
					Global.IsPaused = true;
				} else if (keyCode == Input.Keys.ESCAPE && Global.IsPaused && Global.IsKeyBindings && Global.IsSetKey) {
					if (!Global.SetVolumeToZero)
						enter2.play(2f);
					Global.IsSetKey = false;
				} else if (keyCode == Input.Keys.ESCAPE && Global.IsPaused && Global.IsKeyBindings) {
					if (!Global.SetVolumeToZero)
						enter2.play(2f);
					Global.IsKeyBindings = false;
					pp.IsSwitchingToKeyBindings = true;
				} else if (keyCode == Input.Keys.ESCAPE && Global.IsPaused) {
					if (!Global.SetVolumeToZero)
						enter2.play(2f);
					Global.IsPaused = false;
				}
				if (Global.IsSetKey)
					Global.KeycodeSet = keyCode;
				return true;
			}

			@Override
			public boolean touchDown(int x, int y, int pointer, int button) {// this is for capturing mouse clicks
				if (Global.IsSetKey && Global.IsPaused)
					Global.KeycodeSet = button;
				return true;
			}

		});
		// start the play back of the background music
		// when the screen is shown
		levelMusic.setVolume(.7f);
		if (!Global.IsMusicPaused)
			levelMusic.play();
	}

	@Override
	public void render(float delta) {
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		// this is going to be my background, depending on what scene or area you are in. Trust me, this is intentional.
		ScreenUtils.clear(.15f, .15f, .15f, 1);// brown
		// ScreenUtils.clear(.2f, .5f, .2f, 1);// green.
		game.batch.setProjectionMatrix(camera.combined);
		game.batch.begin();
		// System.out.println("game batch begin has been called. " + game.batch + " see? ");
		if (Global.IsPaused) {
			ScreenUtils.clear(0, 0, 0, 1);// black
			camera.position.y = Gdx.graphics.getHeight() * .5f;
			camera.position.x = Gdx.graphics.getWidth() * .5f;
			camera.update();
			// System.out.println("cameraX: " + camera.position.x + " cameraY: " + camera.position.y);
			pp.RenderEntirePauseMenu(delta, game, game.font, levelMusic, camera);

			// DebugRenderer.DrawDebugRectangle(pp.saveGameRect, Color.RED, camera.combined);//there were a lot more of these heheeh
		} else {
			// System.out.println("this should run before level.render");
			if (!isEverythingLoaded) {
				// lets load everything in pieces, while it's loading everything lets render stuff to the screen that represents the load state.
				game.font.setColor(Color.GRAY);
				game.font.draw(game.batch, "Loading: " + whatIsLoading, camera.position.x - Agent.MW / 2 + 420, camera.position.y + Agent.MH / 2 - 247);// shadow
				game.font.setColor(Color.DARK_GRAY);
				game.font.draw(game.batch, "Loading: " + whatIsLoading, camera.position.x - Agent.MW / 2 + 418, camera.position.y + Agent.MH / 2 - 245);
				if (!isLevelAdded && delayTimer <= 0) {
					System.out.println("doing the level");
					whatIsLoading = "leveling the entire world into a flat 2d plain actually there is no world you are in a void nothing exists";
					// levelTmx = new LevelTmx(Agent.LW, Agent.LH, this, assets);// need to know exactly how big the constructed sets are going to be? Screen
					// size?
					// level = new Level(Agent.LW, Agent.LH, this, assets);// was 64,64//needs constructed after the tile textures exist. :-)
					isLevelAdded = true;
					delayTimer = DTSpd;
				} else if (!isPlayerAdded && delayTimer <= 0) {
					System.out.println("doing the Player");
					whatIsLoading = "Constructing player";
					player = new Player(0, 0);// this places the player exactly in the middle of the map.(because it's setin the
					reloadGun();
					delayTimer = DTSpd;
					isPlayerAdded = true;
					harvesterLoop = true;
				} else if (!isHarvesterAdded && delayTimer <= 0) {
					System.out.println("doing the harvester");
					whatIsLoading = "The Harvester & saving Truck & evilPlane booooo EVIL!";
					if (harvesterLoop && delayTimer <= 0) {
						harvester = new Harvester(200, 0);
						savingTruck = new SavingTruck(9000, 9000);
						evilPlane = new EvilPlane(9000, 9000);// was 9000,9000
						isHarvesterAdded = true;
						plantLoop = true;
						delayTimer = DTSpd;
					}
				} else if (!isPlantsAdded && delayTimer <= 0) {
					System.out.println("doing the Plants");
					if (plantLoop && delayTimer <= 0) {
						whatIsLoading = "Those Plants, they descended from the rafters!";
						System.out.println("Plants added (at least one!)");
						plants = new Array<Plant>();
						for (int x = 0; x < 25; x++) {// was 500 yeah, and now it's ONE haha
							for (int y = 0; y < 25; y++) {
								plants.add(new Plant(-1100 + x * 40, y * 40));
							}
							if (x + 1 == 1) {// end of loop
								isPlantsAdded = true;
								personLoop = true;
								delayTimer = DTSpd;
							}
						}
						isPlantsAdded = true;
					}

				} else if (!isPeoplesAdded && delayTimer <= 0) {
					System.out.println("doing the Peoples");
					if (personLoop && delayTimer <= 0) {
						whatIsLoading = "Those Peoples, they descended from the rafters!";
						System.out.println("Peoples added (at least one!)");
						peoples = new Array<Person>();
						for (int x = 0; x < 150; x++) {// was 500 yeah, and now it's ONE haha
							peoples.add(new Person(MathUtils.random(-100, 600), MathUtils.random(400, 800)));
							if (x + 1 == 1) {// end of loop
								isPeoplesAdded = true;
								kittenLoop = true;
								delayTimer = DTSpd;
							}
						}
						isPeoplesAdded = true;
					}

				} else if (!isKittensAdded && delayTimer <= 0) {
					System.out.println("doing the Kittens");
					if (kittenLoop && delayTimer <= 0) {
						whatIsLoading = "Those Kittens meeeeeeeeeeeeeeeeeeeeeeows!";
						System.out.println("Kittens added (at least one!)");
						kittens = new Array<Kitten>();
						for (int x = 0; x < 300; x++) {// was 500 yeah, and now it's ONE haha
							kittens.add(new Kitten(MathUtils.random(-600, 400), MathUtils.random(-600, -400)));
							if (x + 1 == 1) {// end of loop
								isKittensAdded = true;
								workerLoop = true;
								delayTimer = DTSpd;
							}
						}
						isKittensAdded = true;
					}

				} else if (!isWorkersAdded && delayTimer <= 0) {
					System.out.println("doing the Workers");
					if (workerLoop && delayTimer <= 0) {
						whatIsLoading = "Those workers ... worked!";
						System.out.println("workers added (at least one!)");
						workers = new Array<Worker>();
						for (int x = 0; x < 80; x++) {// was 80 yeah, and now it's ONE haha
							workers.add(new Worker(MathUtils.random(-300, -200), MathUtils.random(-300, -200)));
							if (x + 1 == 1) {// end of loop
								isWorkersAdded = true;
								evilAgentLoop = true;
								delayTimer = DTSpd;
							}
						}
						isWorkersAdded = true;
					}

				} else if (!isEvilAgentsAdded && delayTimer <= 0) {
					System.out.println("doing the evilAgents");
					if (evilAgentLoop && delayTimer <= 0) {
						whatIsLoading = "Those evilAgents, they descended from the rafters!";
						System.out.println("evilAgents added (at least one!)");
						evilAgents = new Array<EvilAgent>();
						for (int x = 0; x < 100; x++) {// was 500 yeah, and now it's ONE haha
							evilAgents.add(new EvilAgent(MathUtils.random(-Agent.MW, -Agent.MW + 32), MathUtils.random(-Agent.MH, Agent.MH)));
							evilAgents.add(new EvilAgent(MathUtils.random(Agent.MW - 32, Agent.MW), MathUtils.random(-Agent.MH, Agent.MH)));
							evilAgents.add(new EvilAgent(MathUtils.random(-Agent.MW, Agent.MW - 32), MathUtils.random(-Agent.MH, -Agent.MH + 32)));
							evilAgents.add(new EvilAgent(MathUtils.random(-Agent.MW, Agent.MW - 32), MathUtils.random(Agent.MH - 32, Agent.MH)));
							if (x + 1 == 1) {// end of loop
								isEvilAgentsAdded = true;
								delayTimer = DTSpd;
							}
						}
						isEvilAgentsAdded = true;
					}

				}
				if (isEvilAgentsAdded && delayTimer <= 0) {
					System.out.println("now everything is done");
					isEverythingLoaded = true;
				}
				if (delayTimer > 0)
					delayTimer--;
				game.batch.end();
			} else {
				// draw level
				// levelTmx.render(game, camera, delta);
				// level.render(game, camera, delta);
				// draw plants
				for (int d = 0; d < plants.size; d++) {
					game.batch.setColor(plants.get(d).color);
					plants.get(d).render(game, workers, player, delta);
				}
				// draw player
				game.batch.setColor(player.color);// set color before you draw
				// DebugRenderer.DrawDebugRectangle(player.rect, Color.RED, camera.combined);// there were a lot more of these heheeh
				pos23 = camera.unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0));
				game.batch.draw(player.getFrame(delta, camera), player.rect.x - 24, player.rect.y - 4);
				// draw harvester
				game.batch.setColor(harvester.color);// set color before you draw
				game.batch.draw(harvester.getFrame(camera, delta), harvester.rect.x, harvester.rect.y);
				// draw saving Truck
				game.batch.setColor(savingTruck.color);// set color before you draw
				game.batch.draw(savingTruck.getFrame(camera, delta), savingTruck.rect.x, savingTruck.rect.y);
				// draw ball
				// if (!ball.isDead) {
				// game.batch.setColor(ball.color);// set color before you draw
				// game.batch.draw(ball.getFrame(camera, delta), ball.rect.x, ball.rect.y);
				// }
				// draw balls
				for (int d = 0; d < balls.size; d++) {
					if (!balls.get(d).isDead) {
						game.batch.setColor(balls.get(d).shadow.color);
						game.batch.draw(balls.get(d).shadow.getFrame(camera, delta), balls.get(d).shadow.rect.x, balls.get(d).shadow.rect.y);
						game.batch.setColor(balls.get(d).color);
						game.batch.draw(balls.get(d).getFrame(camera, delta), balls.get(d).rect.x, balls.get(d).rect.y);
					}
				}
				// draw kittens
				for (int d = 0; d < kittens.size; d++) {
					game.batch.setColor(kittens.get(d).color); // DebugRenderer.DrawDebugRectangle(furbals.get(d).rect, Color.YELLOW, camera.combined);
					kittens.get(d).render(game, workers, player, delta);
				}
				// draw peoples
				for (int d = 0; d < peoples.size; d++) {
					game.batch.setColor(peoples.get(d).color); // DebugRenderer.DrawDebugRectangle(furbals.get(d).rect, Color.YELLOW, camera.combined);
					peoples.get(d).render(game, workers, player, delta);
				}
				// draw workers
				for (int d = 0; d < workers.size; d++) {
					game.batch.setColor(workers.get(d).color); // DebugRenderer.DrawDebugRectangle(furbals.get(d).rect, Color.YELLOW, camera.combined);
					workers.get(d).render(game, delta, plants, peoples, kittens, harvester);
				}
				// draw the evilAgents
				for (int d = 0; d < evilAgents.size; d++) {
					game.batch.setColor(evilAgents.get(d).color);
					// DebugRenderer.DrawDebugRectangle(evilAgents.get(d).rect, Color.YELLOW, camera.combined);
					evilAgents.get(d).render(game, camera, delta, player);

					if (!evilAgents.get(d).enemyBall.isDead) {
						// enemyball
						game.batch.setColor(evilAgents.get(d).enemyBall.shadow.color);
						game.batch.draw(evilAgents.get(d).enemyBall.shadow.getFrame(camera, delta), evilAgents.get(d).enemyBall.shadow.rect.x,
								evilAgents.get(d).enemyBall.shadow.rect.y);
						game.batch.setColor(evilAgents.get(d).enemyBall.color);
						game.batch.draw(evilAgents.get(d).enemyBall.getFrame(camera, delta), evilAgents.get(d).enemyBall.rect.x,
								evilAgents.get(d).enemyBall.rect.y);
					}
					if (!evilAgents.get(d).drum.isDead) {
						// enemy drum
						game.batch.setColor(evilAgents.get(d).drum.color);
						game.batch.draw(evilAgents.get(d).drum.getFrame(camera, delta), evilAgents.get(d).drum.rect.x, evilAgents.get(d).drum.rect.y);
					}
					if (!evilAgents.get(d).beam.isDead) {
						// enemy beam
						game.batch.setColor(evilAgents.get(d).beam.shadow.color);
						game.batch.draw(evilAgents.get(d).beam.shadow.getFrame(camera, delta), evilAgents.get(d).beam.shadow.rect.x,
								evilAgents.get(d).beam.shadow.rect.y);
						game.batch.setColor(evilAgents.get(d).beam.color);
						game.batch.draw(evilAgents.get(d).beam.getFrame(camera, delta), evilAgents.get(d).beam.rect.x, evilAgents.get(d).beam.rect.y);
					}
				}
				// draw evil plane
				game.batch.setColor(evilPlane.color);// set color before you draw
				game.batch.draw(evilPlane.getFrame(camera, delta), evilPlane.rect.x, evilPlane.rect.y);
				game.batch.setColor(evilPlane.evilPlaneShadow.color);
				game.batch.draw(evilPlane.evilPlaneShadow.getFrame(camera, delta), evilPlane.evilPlaneShadow.rect.x, evilPlane.evilPlaneShadow.rect.y);
				// icons:
				game.font.setColor(Color.WHITE);// set color before you draw
				game.batch.setColor(Color.WHITE);// reset batch color
				// draw HUD
				game.font.getData().setScale(1f);
				game.font.setColor(Color.BLACK);// set color before you draw
				game.font.draw(game.batch, "Score: " + Agent.Score, camera.position.x - Agent.MW / 2 + 142, camera.position.y + Agent.MH / 2 - 16);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "Score: " + Agent.Score, camera.position.x - Agent.MW / 2 + 140, camera.position.y + Agent.MH / 2 - 14);

				game.font.getData().setScale(.4f);
				if (player.ammo <= 0) {
					game.font.setColor(Color.RED);//
					game.font.draw(game.batch, "Reload!", player.rect.x + 10, player.rect.y + 80);// shadow
					game.font.setColor(Color.YELLOW);
					game.font.draw(game.batch, "Reload!", player.rect.x + 10, player.rect.y + 80);// shadow
				}
				game.font.setColor(Color.MAROON);// set color before you draw
				game.font.draw(game.batch, "" + Agent.Health, player.rect.x - 13, player.rect.y + 60);// shadow
				game.font.setColor(Color.RED);// set color before you draw
				game.font.draw(game.batch, "" + Agent.Health, player.rect.x - 14, player.rect.y + 61);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "" + Agent.Health, player.rect.x - 15, player.rect.y + 62);
				game.font.setColor(Color.RED);// set color before you draw
				game.font.draw(game.batch, "" + Agent.HarvesterHealth, harvester.rect.x - 21, harvester.rect.y + 99);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "" + Agent.HarvesterHealth, harvester.rect.x - 22, harvester.rect.y + 100);
				game.font.setColor(Color.BLACK);
				game.font.getData().setScale(1f);
				game.font.draw(game.batch, "Jiicamas Left: " + plants.size, camera.position.x - 90, camera.position.y + Agent.MH / 2 - 16);// shadow
				if (plants.size <= 0)
					game.font.setColor(Color.RED);
				else
					game.font.setColor(Color.BROWN);
				game.font.draw(game.batch, "Jiicamas Left: " + plants.size, camera.position.x - 88, camera.position.y + Agent.MH / 2 - 14);
				game.font.setColor(Color.BLACK);
				game.font.draw(game.batch, "Kittens Left: " + kittens.size, camera.position.x + 220, camera.position.y + Agent.MH / 2 - 16);// shadow
				if (kittens.size <= 0)
					game.font.setColor(Color.RED);
				else
					game.font.setColor(Color.BLUE);
				game.font.draw(game.batch, "Kittens Left: " + kittens.size, camera.position.x + 218, camera.position.y + Agent.MH / 2 - 14);
				game.font.setColor(Color.BLACK);
				game.font.draw(game.batch, "Prisoners Left: " + peoples.size, camera.position.x + 506, camera.position.y + Agent.MH / 2 - 16);// shadow
				if (peoples.size <= 0)
					game.font.setColor(Color.RED);
				else
					game.font.setColor(Color.PURPLE);
				game.font.draw(game.batch, "Prisoners Left: " + peoples.size, camera.position.x + 508, camera.position.y + Agent.MH / 2 - 14);
				game.font.setColor(Color.BLACK);
				game.font.draw(game.batch, "Harvester Health: " + Agent.HarvesterHealth, camera.position.x - 440, camera.position.y + Agent.MH / 2 - 16);// shadow
				if (Agent.HarvesterHealth <= 0)
					game.font.setColor(Color.BLACK);
				else
					game.font.setColor(Color.FIREBRICK);
				game.font.draw(game.batch, "Harvester Health: " + Agent.HarvesterHealth, camera.position.x - 442, camera.position.y + Agent.MH / 2 - 14);
				// UI
				game.font.getData().setScale(1f);
				game.font.setColor(Color.BLACK);
				game.font.draw(game.batch, "Items Collected: " + player.swirlingObjects, camera.position.x - Agent.MW / 2 + 22, camera.position.y - 370);// shadow
				game.font.setColor(Color.ROYAL);
				game.font.draw(game.batch, "Items Collected: " + player.swirlingObjects, camera.position.x - Agent.MW / 2 + 20, camera.position.y - 370);
				game.font.setColor(Color.LIGHT_GRAY);
				game.font.draw(game.batch, "Saving Truck: " + Agent.SavingTruckTimer, camera.position.x - 106, camera.position.y - 371);// shadow
				game.font.setColor(Color.GOLD);
				game.font.draw(game.batch, "Saving Truck: " + Agent.SavingTruckTimer, camera.position.x - 104, camera.position.y - 370);
				game.font.setColor(Color.TEAL);
				game.font.draw(game.batch, "?? " + Agent.EvilPlaneTimer, camera.position.x - 356, camera.position.y - 371);// shadow
				game.font.setColor(Color.GRAY);
				game.font.draw(game.batch, "?? " + Agent.EvilPlaneTimer, camera.position.x - 354, camera.position.y - 370);// EnemyTruckMovingTimer
				if (Agent.EnemyTruckMovingTimer > 0) {
					game.font.setColor(Color.CYAN);
					game.font.draw(game.batch, "OhNo!! " + Agent.EnemyTruckMovingTimer, camera.position.x + 266, camera.position.y - 371);// shadow
					game.font.setColor(Color.GRAY);
					game.font.draw(game.batch, "OhNo!! " + Agent.EnemyTruckMovingTimer, camera.position.x + 264, camera.position.y - 370);// EnemyTruckMovingTimer
				} else {
					game.font.setColor(Color.RED);
					game.font.draw(game.batch, "! ! ! !" + Agent.EnemyTruckMovingTimer, camera.position.x + 266, camera.position.y - 371);// shadow
					game.font.setColor(Color.GRAY);
					game.font.draw(game.batch, "! ! ! !" + Agent.EnemyTruckMovingTimer, camera.position.x + 264, camera.position.y - 370);// EnemyTruckMovingTimer
				}
				game.font.setColor(Color.BLACK);
				game.font.draw(game.batch, "AMMO: " + player.ammo, camera.position.x + 530, camera.position.y - 370);// shadow
				game.font.setColor(Color.GRAY);
				game.font.draw(game.batch, "AMMO: " + player.ammo, camera.position.x + 528, camera.position.y - 370);
				game.font.setColor(Color.BLACK);
				game.font.draw(game.batch, "/", camera.position.x + 714, camera.position.y - 370);// shadow
				game.font.setColor(Color.GRAY);
				game.font.draw(game.batch, "/", camera.position.x + 712, camera.position.y - 370);
				game.font.setColor(Color.BLACK);
				game.font.draw(game.batch, " " + player.ammoSize, camera.position.x + 720, camera.position.y - 370);// shadow
				game.font.setColor(Color.GRAY);
				game.font.draw(game.batch, " " + player.ammoSize, camera.position.x + 718, camera.position.y - 370);
				// debug info:
				game.font.setColor(Color.BLACK);
				game.font.draw(game.batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), camera.position.x + 650, camera.position.y - 420);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), camera.position.x + 648, camera.position.y - 420);
				// game.font.setColor(Color.BLACK);
				// game.font.draw(game.batch, "JavaMem: " + Gdx.app.getJavaHeap(), camera.position.x + 320, camera.position.y - 297);// SL
				// game.font.setColor(Color.WHITE);
				// game.font.draw(game.batch, "JavaMem: " + Gdx.app.getJavaHeap(), camera.position.x + 328, camera.position.y - 295);
				// game.font.setColor(Color.BLACK);
				// game.font.draw(game.batch, "NativMem: " + Gdx.app.getNativeHeap(), camera.position.x + 320, camera.position.y - 267);// SL
				// game.font.setColor(Color.WHITE);
				// game.font.draw(game.batch, "NativMem: " + Gdx.app.getNativeHeap(), camera.position.x + 328, camera.position.y - 265);
				// game.font.draw(game.batch, "NativMem: " + Gdx.app.getNativeHeap(), camera.position.x + 328, camera.position.y - 265);
				// game.font.setColor(Color.BLACK);
				// end debug info
				// timer till extraction
				/*
				 * game.font.setColor(Color.CYAN); game.font.draw(game.batch, "Time till Extraction: " + Agent.ExtractionTimer, camera.position.x - 300,
				 * camera.position.y + 340); game.font.setColor(Color.WHITE); game.font.draw(game.batch, "Time till Extraction: " + Agent.ExtractionTimer,
				 * camera.position.x - 301, camera.position.y + 342);
				 */

				game.batch.end();
				// debug drawing section: this IS important. I'm glad this is starting to make sense. It's handled on a different batch render call.
				// DrawDebugLine(posV2, mousePosV2, 2, Color.CORAL, camera.combined);
				// if (balls.size > 0)
				// u.DebugRenderer.DrawDebugRectangle(balls.get(0).rect, Color.BLUE, camera.combined);
				// if (plants.size > 1)
				// u.DebugRenderer.DrawDebugRectangle(player.rect, Color.YELLOW, camera.combined);
				// u.DebugRenderer.DrawDebugBoundingBox(rbox, Color.RED, camera.combined);
				// collisions
				checkPlayerCollisions(player);
				checkHarvesterCollisions(harvester);
				checkWorkerCollisions(workers);
				checkEvilAgentCollisions(evilAgents);
				checkKittyCollisions(kittens);
				checkPersonCollisions(peoples);
				checkPlantCollisions(plants);
				// ui collisions

				if (Gdx.input.isKeyJustPressed(Input.Keys.Q)) {// reset map or screen
					System.out.println("\r\r\r\r\r\r\r");
					dispose();// hee hee i figured out how to reset the level. xD (dispose of the level and reload it. ;-) )
					camera.position.y = 0;
					camera.position.x = 0;
					camera.update();
					game.setScreen(new GameScreen(game));
				}
				// end game: //if you run out of items on the map. (player is dead, turrets are dead, etc you lose)
				if (Agent.Health <= 0 && isDeadTimer <= 0) {
					camera.position.y = 0;
					camera.position.x = 0;
					camera.update();
					dispose();
					game.setScreen(new LoseScreen(game));
				}
				if (Agent.Health <= 0 && isDeadTimer > 0) {
					isDeadTimer--;
					death.play();
					player.isDying = true;
				}
				if (Agent.HarvesterHealth <= 0) {
					camera.position.y = 0;
					camera.position.x = 0;
					camera.update();
					dispose();
					game.setScreen(new WinScreen(game));
				}
				if (Agent.SavingTruckTimer > 0)
					Agent.SavingTruckTimer--;
				if (Agent.SavingTruckTimer <= 0) {
					Agent.SavingTruckTimerMax = MathUtils.random(100, 2500);// was 100,3000
					Agent.SavingTruckTimer = Agent.SavingTruckTimerMax;
					savingTruck.speed = MathUtils.random(300f, 700f);
					System.out.println("truck speed: " + savingTruck.speed);
					savingTruck.rect.y = MathUtils.random(-Agent.MH, Agent.MH);
					savingTruck.rect.x = Agent.MW;
					horn.play();
				}
				if (Agent.EvilPlaneTimer > 0)
					Agent.EvilPlaneTimer--;
				if (Agent.EvilPlaneTimer <= 0) {
					Agent.EvilPlaneTimerMax = MathUtils.random(100, 700);// was 100,700
					Agent.EvilPlaneTimer = Agent.SavingTruckTimerMax;
					evilPlane.speed = MathUtils.random(300f, 900f);
					float ss = evilPlane.speed;
					evilPlane.evilPlaneShadow.speed = ss;
					System.out.println("evil Plane speed: " + evilPlane.speed);
					evilPlane.rect.y = MathUtils.random(-Agent.MH, Agent.MH);
					evilPlane.rect.x = -Agent.MW;
					float sx = evilPlane.rect.x;
					float sy = evilPlane.rect.y;
					sy -= 300;
					evilPlane.evilPlaneShadow.rect.x = sx;
					evilPlane.evilPlaneShadow.rect.y = sy;
					horn.play();
					dropStuffOffTimer = MathUtils.random(100, 300);
				}
				if (dropStuffOffTimer > 0) {
					dropStuffOffTimer--;
					int rand = MathUtils.random(1, 5);
					if (rand == 1)
						workers.add(new Worker((int) evilPlane.rect.x + MathUtils.random(-10, 10), (int) evilPlane.rect.y + MathUtils.random(-10, 10)));
					else if (rand == 2)
						plants.add(new Plant((int) evilPlane.rect.x + MathUtils.random(-10, 10), (int) evilPlane.rect.y + MathUtils.random(-10, 10)));
					else if (rand == 3)
						peoples.add(new Person((int) evilPlane.rect.x + MathUtils.random(-10, 10), (int) evilPlane.rect.y + MathUtils.random(-10, 10)));
					else if (rand == 4)
						kittens.add(new Kitten((int) evilPlane.rect.x + MathUtils.random(-10, 10), (int) evilPlane.rect.y + MathUtils.random(-10, 10)));
					else
						evilAgents.add(new EvilAgent((int) evilPlane.rect.x + MathUtils.random(-10, 10), (int) evilPlane.rect.y + MathUtils.random(-10, 10)));
				}
				if (Agent.EnemyTruckMovingTimer > 0)
					Agent.EnemyTruckMovingTimer--;
				if (Agent.EnemyTruckMovingTimer <= 0) {
					System.out.println("move!");
					sp = new Vector2(harvester.rect.x, harvester.rect.y);
					ep = new Vector2(player.rect.x, player.rect.y);
					harvester.dir = u.UsefulMethods.GetDirection(sp, ep);
					if (Agent.HarvestedStuff < 250)
						harvester.speed = Agent.HarvestedStuff;
					else
						harvester.speed = 250;
					harvester.isMoving = true;
				}
				if (player.isReloading) {
					player.isReloading = false;
					reloadGun();
				}
				if (Gdx.input.isButtonJustPressed(Uinput.Fire()) && player.hasGun && player.ammo > 0) {
					mousePos = camera.unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0));
					sp = new Vector2(player.rect.x, player.rect.y);
					sps = new Vector2(player.rect.x, player.rect.y);
					sps.y -= 20;// to put it down!
					ep = new Vector2(mousePos.x, mousePos.y);
					eps = new Vector2(mousePos.x, mousePos.y);
					eps.y -= 20;// to put it down!
					player.ammo--;
					balls.get(player.ammo).dir = u.UsefulMethods.GetDirection(sp, ep);
					balls.get(player.ammo).rect.x = sp.x;
					balls.get(player.ammo).rect.y = sp.y;
					// balls.get(d).dist = distance;
					balls.get(player.ammo).fired = true;
					balls.get(player.ammo).isDead = false;
					balls.get(player.ammo).shadow.dir = u.UsefulMethods.GetDirection(sp, ep);
					balls.get(player.ammo).shadow.rect.x = sps.x;
					balls.get(player.ammo).shadow.rect.y = sps.y;
					System.out.println("eps: " + eps);
					balls.get(player.ammo).shadow.firedOne = false;
					balls.get(player.ammo).shadow.fired = true;
					balls.get(player.ammo).shadow.isDead = false;

				}
				update(delta);// going to set camera position to last. :-)
			}

		}

	}// end of render (or update)

	public void checkPlayerCollisions(Player player) {
		// for colliding with a group of objects.
		for (int i = 0; i < evilAgents.size; i++) {
			if (Agent.Health > 0 && evilAgents.get(i).enemyBall.rect.overlaps(player.rect)) {
				if (!evilAgents.get(i).enemyBall.isDead) {
					evilAgents.get(i).enemyBall.isDead = true;
					Agent.Health--;
					Agent.Score--;
					if (!Global.SetVolumeToZero)
						player.playRandomHurtSound(6);
				}
			}
			// drums
			if (Agent.Health > 0 && !player.isJumping && evilAgents.get(i).drum.rect.overlaps(player.rect)) {
				if (!evilAgents.get(i).drum.isDead) {
					evilAgents.get(i).drum.isDead = true;
					Agent.Health -= 2;
					Agent.Score--;
					if (!Global.SetVolumeToZero)
						player.playRandomHurtSound(6);
				}
			}
			if (Agent.Health > 0 && player.isJumping && evilAgents.get(i).drum.rect.overlaps(player.rect)) {
				if (!evilAgents.get(i).drum.isDead) {
					evilAgents.get(i).drum.isDead = true;
					Agent.Score += 10;
					if (!Global.SetVolumeToZero)
						yay.play();
				}
			}
			// beams
			if (Agent.Health > 0 && !player.isDucked && evilAgents.get(i).beam.rect.overlaps(player.rect)) {
				if (!evilAgents.get(i).beam.isDead) {
					evilAgents.get(i).beam.isDead = true;
					Agent.Health -= 4;
					Agent.Score--;
					if (!Global.SetVolumeToZero)
						player.playRandomHurtSound(6);
				}
			}
		}

	}

	public void checkEvilAgentCollisions(Array<EvilAgent> evilAgents) {
		for (Iterator<EvilAgent> iter = evilAgents.iterator(); iter.hasNext();) {
			EvilAgent w = iter.next();
			// for colliding with a group of objects.
			for (Iterator<Ball> iter2 = balls.iterator(); iter2.hasNext();) {
				Ball b = iter2.next();
				if (!w.isDying && w.rect.overlaps(b.rect)) {
					balls.removeValue(b, true);// drop it from the array.
					evilAgents.removeValue(w, true);
					w.isDying = true;
				}
			}
			// for colliding with a group of objects.
			for (Iterator<Ball> iter2 = balls.iterator(); iter2.hasNext();) {
				Ball b = iter2.next();
				if (w.drum.rect.overlaps(b.rect)) {
					if (!w.drum.isDead) {
						Agent.Score++;
						w.drum.isDead = true;
						w.isDying = true;
						b.isDead = true;
						balls.removeValue(b, true);
					}
				}
			}
			// collding with a single object:
			if (Agent.Health > 0 && w.rect.overlaps(player.rect)) {
				if (!w.isSpinning) {// now it only hits you once and sounds once. and negatives your score once. i'll make it bigger tough. minus 20! why didn't
									// i
					Agent.Health--;
					if (!Global.SetVolumeToZero)
						player.playRandomHurtSound(6);
					Agent.Score -= 2;// testing score (remove this!)
					w.isSpinning = true;
				}
			}
		}
	}

	public void checkHarvesterCollisions(Harvester harvester) {
		// for colliding with a group of objects.
		for (Iterator<Ball> iter2 = balls.iterator(); iter2.hasNext();) {
			Ball b = iter2.next();
			if (Agent.HarvesterHealth > 0 && harvester.rect.overlaps(b.rect)) {
				balls.removeValue(b, true);// drop it from the array.
				Agent.HarvesterHealth -= 10;
				if (!Global.SetVolumeToZero)
					player.playRandomClickSound(6);
			}
		}
		// collding with a single object:
		if (Agent.Health > 0 && harvester.rect.overlaps(player.rect)) {
			Agent.Health--;
			if (player.hasGun) {
				if (!Global.SetVolumeToZero)
					dropGun2.play();
				player.hasGun = false;
			}
			Agent.Score -= 2;// testing score (remove this!)
		}
	}

	public void checkWorkerCollisions(Array<Worker> workers) {
		for (Iterator<Worker> iter = workers.iterator(); iter.hasNext();) {
			Worker w = iter.next();
			// for colliding with a group of objects.
			for (Iterator<Ball> iter2 = balls.iterator(); iter2.hasNext();) {
				Ball b = iter2.next();
				if (w.rect.overlaps(b.rect)) {
					if (!w.isDead) {
						w.isDead = true;
						w.isDying = true;
						b.isDead = true;
						balls.removeValue(b, true);
						workers.removeValue(w, true);// drop it from the array!
					}
				}
			}
			// for colliding with a group of objects.
			for (Iterator<Plant> iter2 = plants.iterator(); iter2.hasNext();) {
				Plant p = iter2.next();
				if (w.rect.overlaps(p.rect)) { // TODO: This
					if (!p.isCarried && !w.isHolding) {// plant can't be carried if already carried, worker can't hold more than one
						if (p.isCarriedByPlayer) {
							p.isCarriedByPlayer = false;
							if (player.swirlingObjects > 0)
								player.swirlingObjects--;
						}
						p.isCarried = true;
						p.uuid = w.uuid;
						w.isHolding = true;
					}
				}
			}
			// for colliding with a group of objects.
			for (Iterator<Kitten> iter2 = kittens.iterator(); iter2.hasNext();) {
				Kitten k = iter2.next();
				if (w.rect.overlaps(k.rect)) { // TODO: This
					if (!k.isCarried && !w.isHolding) {// plant can't be carried if already carried, worker can't hold more than one
						if (k.isCarriedByPlayer) {
							k.isCarriedByPlayer = false;
							if (player.swirlingObjects > 0)
								player.swirlingObjects--;
						}
						k.isCarried = true;
						k.uuid = w.uuid;
						w.isHolding = true;
					}
				}
			}
			// for colliding with a group of objects.
			for (Iterator<Person> iter2 = peoples.iterator(); iter2.hasNext();) {
				Person pr = iter2.next();
				if (w.rect.overlaps(pr.rect)) { // TODO: This
					if (!pr.isCarried && !w.isHolding) {// plant can't be carried if already carried, worker can't hold more than one
						if (pr.isCarriedByPlayer) {
							pr.isCarriedByPlayer = false;
							if (player.swirlingObjects > 0)
								player.swirlingObjects--;
						}
						pr.isCarried = true;
						pr.uuid = w.uuid;
						w.isHolding = true;
					}
				}
			}
			// collding with a single object:
			if (w.isHolding && w.rect.overlaps(harvester.rect)) {
				if (!w.isDying) {
					// Agent.Health--;
					w.isHolding = false;
				}
				// w.isDying = true;
			}
		}

	}

	public void checkKittyCollisions(Array<Kitten> kittens) {
		for (Iterator<Kitten> iter = kittens.iterator(); iter.hasNext();) {
			Kitten k = iter.next();
			// collding with a single object:
			if (Agent.Health > 0 && k.rect.overlaps(player.rect)) {
				if (!k.isCarriedByPlayer && !k.isCarried && !k.isDead) {
					Agent.Health++;
					Agent.Score += 2;// testing score (remove this!)
					player.swirlingObjects++;
					k.isCarriedByPlayer = true;
				}
			}
			// collding with a single object:
			if (k.isCarried && k.rect.overlaps(harvester.rect)) {
				if (!k.isDead) {
					if (!Global.SetVolumeToZero)
						grind.play();
					Agent.HarvestedStuff++;
					Agent.Score -= 2;// testing score (remove this!)
				}
				k.isDead = true;
				kittens.removeValue(k, true);// drop it from the array!
			}
			// collding with a single object:
			if (k.isCarriedByPlayer && k.rect.overlaps(savingTruck.rect)) {
				if (!k.isDead) {
					if (!Global.SetVolumeToZero)
						yay.play();
					if (player.swirlingObjects > 0)
						player.swirlingObjects--;
					Agent.Score += 510;// testing score (remove this!)
				}
				k.isDead = true;
				kittens.removeValue(k, true);// drop it from the array!
			}
		}
	}

	public void checkPlantCollisions(Array<Plant> plants) {
		for (Iterator<Plant> iter = plants.iterator(); iter.hasNext();) {
			Plant p = iter.next();
			// collding with a single object:
			if (Agent.Health > 0 && p.rect.overlaps(player.rect)) {
				if (!p.isCarriedByPlayer && !p.isCarried && !p.isDead) {
					Agent.Health++;
					Agent.Score += 2;// testing score (remove this!)
					player.swirlingObjects++;
					p.isCarriedByPlayer = true;
				}
			}
			// collding with a single object:
			if (p.isCarried && p.rect.overlaps(harvester.rect)) {
				if (!p.isDead) {
					Agent.Score -= 2;// testing score (remove this!)
					Agent.HarvestedStuff++;
					if (!Global.SetVolumeToZero)
						grind2.play();
				}
				p.isDead = true;
				plants.removeValue(p, true);// drop it from the array!
			}
			// collding with a single object:
			if (p.isCarriedByPlayer && p.rect.overlaps(savingTruck.rect)) {
				if (!p.isDead) {
					if (!Global.SetVolumeToZero)
						yay.play();
					if (player.swirlingObjects > 0) {
						player.swirlingObjects--;
						player.ammoPower++;
					}
					Agent.Score += 100;// testing score (remove this!)
				}
				p.isDead = true;
				plants.removeValue(p, true);// drop it from the array!
			}
		}
	}

	public void checkPersonCollisions(Array<Person> peoples) {
		for (Iterator<Person> iter = peoples.iterator(); iter.hasNext();) {
			Person p = iter.next();
			// collding with a single object:
			if (Agent.Health > 0 && p.rect.overlaps(player.rect)) {
				if (!p.isCarriedByPlayer && !p.isCarried && !p.isDead) {
					Agent.Health++;
					Agent.Score += 2;// testing score (remove this!)
					player.swirlingObjects++;
					p.isCarriedByPlayer = true;
				}
			}
			// collding with a single object:
			if (p.isCarried && p.rect.overlaps(harvester.rect)) {
				if (!p.isDead) {
					Agent.Score -= 2;// testing score (remove this!)
					if (!Global.SetVolumeToZero)
						grind3.play();
					Agent.HarvestedStuff++;
				}
				p.isDead = true;
				peoples.removeValue(p, true);// drop it from the array!
			}
			// collding with a single object:
			if (p.isCarriedByPlayer && p.rect.overlaps(savingTruck.rect)) {
				if (!p.isDead) {
					if (!Global.SetVolumeToZero)
						yay.play();
					if (player.swirlingObjects > 0) {
						player.swirlingObjects--;
						player.ammoSize++;
					}
					Agent.Score += 130;// testing score (remove this!)
				}
				p.isDead = true;
				peoples.removeValue(p, true);// drop it from the array!
			}
		}
	}

	public void reloadGun() {
		int aSize = player.ammoSize;
		for (int i = 0; i < player.ammoSize; i++)
			balls.add(new Ball(9000, 9000, 9000, 9000));
		player.ammo = aSize;
	}

	/***
	 * sets the game timer to the correct display
	 */
	public void setGameTimer() {
		if (translateTimer > 540) {
			gameTimer = 10;
		} else if (translateTimer > 480 && translateTimer <= 540) {
			gameTimer = 9;
		} else if (translateTimer > 420 && translateTimer <= 480) {
			gameTimer = 8;
		} else if (translateTimer > 360 && translateTimer <= 420) {
			gameTimer = 7;
		} else if (translateTimer > 300 && translateTimer <= 360) {
			gameTimer = 6;
		} else if (translateTimer > 240 && translateTimer <= 300) {
			gameTimer = 5;
		} else if (translateTimer > 180 && translateTimer <= 240) {
			gameTimer = 4;
		} else if (translateTimer > 120 && translateTimer <= 180) {
			gameTimer = 3;
		} else if (translateTimer > 60 && translateTimer <= 120) {
			gameTimer = 2;
		} else if (translateTimer > 0 && translateTimer <= 60) {
			gameTimer = 1;
		} else if (translateTimer <= 0) {
			gameTimer = 0;
		}
		if (translateTimer <= 0 && !isDelayTimerActive) {
			isDelayTimerActive = true;
			delayTimer = 60;
			if (!masterSwitch) {
				masterSwitch = true;
				Agent.IsTenSecondsActive = true;
			}
		}
		if (translateTimer <= 0 && delayTimer > 0) {
			delayTimer--;
		}
		if (translateTimer <= 0 && delayTimer <= 0) {
			translateTimer = 600;
			isDelayTimerActive = false;
			Agent.IsTenSecondsActive = false;
			masterSwitch = false;
		}
	}

	/**
	 * plays one through 6 sounds set numberOfSounds to 7 to randomly use one of all of them. xD
	 */
	public void playRandomClickSound(int numberOfSounds) {
		int randomSound = MathUtils.random(1, numberOfSounds);
		if (!Global.SetVolumeToZero) {
			if (randomSound == 1)
				click.play();
			else if (randomSound == 2)
				click2.play();
			else if (randomSound == 3)
				click4.play();
			else if (randomSound == 4)
				click5.play();
			else if (randomSound == 5)
				click6.play();
			else if (randomSound == 6)
				click7.play();
		}
	}

	@Override
	public void dispose() {
		// dropSound.dispose();
		// calm.dispose();
		// sfx_growl.dispose();
		// growlHit.dispose();
		enter.dispose();
		enter2.dispose();
		levelMusic.dispose();
		// hit.dispose();
		player.dispose();// for disposing the sound effects... because i'm not sure what needs disposed yet. I don't even know if this is needed. lol
		// atlasFurbal.dispose();
		click.dispose();
		click2.dispose();
		click3.dispose();
		click4.dispose();
		click5.dispose();
		click6.dispose();
		click7.dispose();
		dropGun2.dispose();
		horn.dispose();
		death.dispose();
	}

	@Override
	public void resize(int width, int height) {
		vport.update(width, height, true);
		// camera.setToOrtho(false, width / 32f / 2f, height / 32f / 2f);
	}

	@Override
	public void hide() {
		// rainMusic.stop();
	}

	@Override
	public void pause() {
	}

	@Override
	public void resume() {
	}

}
