package com.ld58.game;

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.Rectangle;
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 Global.Global;
import effects.FireParticle;
import effects.Torch;
import entities.PausePerson;
import entities.Player;
import levelElements.Exit;
import u.UsefulMethods;
import unearthables.AmethystHUD;
import unearthables.CopperHUD;
import unearthables.DiamondHUD;
import unearthables.GoldHUD;
import unearthables.PlatinumHUD;
import unearthables.RubyHUD;
import unearthables.SapphireHUD;
import unearthables.SilverHUD;
import unearthables.TopazHUD;

public class Store implements Screen {
	final rcr game;

	private Music levelMusic;
	private OrthographicCamera camera;
	private Viewport vport;
	private Player player;
//	private Player2 player2;
//	private Player3 player3;
//	private Player4 player4;
//	private Player5 player5;
//	private Player6 player6;
	int currentFrame = 1;
	int MAX_FRAMES = 5;

	public int sw = rcr.MW;// was 1440;
	public int sh = rcr.MH;// 720

	private PausePerson pp;
	private Sound enter;
	private Sound enter2;
	private Sound death;
	private int isDeadTimer = 40;
	private boolean isEverythingLoaded;
	private String whatIsLoading = "";
	private int delayTimer;
	private int DTSpd = 2;// was 5
	private boolean isLevelAdded;
	private boolean isPlayerAdded;
	private Sound reverseSlide;
	private Sound click;
	private Sound click2;
	private Sound click3;
	private Sound click4;
	private Sound click5;
	private Sound click6;
	private Sound click7;
	private Sound boom;
	private boolean isEvilShipsAdded;
	private Torch torch;
	public Array<FireParticle> fireParticles;
	private int cameraShakeTimer;
	private float cameraInitX;
	private float cameraInitY;
	private boolean isCameraPositionInitialized;
	private boolean onetime;
	private boolean playSoundOnce;
	private boolean onlyGoThroughLevelEndOnce;
	private AmethystHUD amethystHUD;
	private CopperHUD copperHUD;
	private DiamondHUD diamondHUD;
	private GoldHUD goldHUD;
	private PlatinumHUD platinumHUD;
	private RubyHUD rubyHUD;
	private SapphireHUD sapphireHUD;
	private SilverHUD silverHUD;
	private TopazHUD topazHUD;
	private Exit exit;
	// private Array<EvilShip> evilShips;
	private Rectangle defenseRect;
	private Rectangle maxHealthRect;
	private Rectangle movementSpeedRect;
	private Rectangle turretRect;
	private Rectangle drillRect;
	private Rectangle attackRangeRect;
	private Rectangle fireRateRect;
	private Rectangle unlockPersonalGunRect;

	/*
	 * what do i need to do with this store?
	 * defense(health),
	 * movement speed (engines),
	 * attack (guns),
	 * drills (speeds up the rate of digging things out of the earth for points? rate of timer decrease speed?)
	 * 
	 * how do I even present this?
	 * what is the best way to do this? Judging amount of time i have for implementation (just a few hours)
	 * I need to do it in the easiest manner possible. I can use a mouse you just click on stuff...
	 * 
	 * ok after that disaster of implementation of just ending a screen and it wasn't "actually hidden" like bother
	 * Your ship. your gems (in their current amounts...)
	 * somewhere to puchase additional upgrades on the screen. Buy those things above!
	 * 
	 * 
	 */
	public Store(final rcr game) {
		this.game = game;
		// camera
		camera = new OrthographicCamera();
		vport = new FitViewport(sw, sh, camera);
		System.out.println("Let's keep going");
		// sounds
		// music
		levelMusic = Gdx.audio.newMusic(Gdx.files.internal("sfx/nighttimeAmbience.ogg"));
		levelMusic.setLooping(true);
		levelMusic.setVolume(1f);
		camera.position.set(vport.getWorldWidth() / 2, vport.getWorldHeight() / 2, 0);
		// sfx
		reverseSlide = Gdx.audio.newSound(Gdx.files.internal("sfx/reverseSlide.ogg"));// death?
		death = Gdx.audio.newSound(Gdx.files.internal("sfx/death.ogg"));// death?
		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"));
		boom = Gdx.audio.newSound(Gdx.files.internal("sfx/boom.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, Gdx.graphics.getHeight() / 2);
		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. ;-)
		torch = new Torch();
		fireParticles = new Array<FireParticle>();
		// gem/metal HUD stuff
		amethystHUD = new AmethystHUD(0, 0);
		copperHUD = new CopperHUD(0, 0);
		diamondHUD = new DiamondHUD(0, 0);
		goldHUD = new GoldHUD(0, 0);
		platinumHUD = new PlatinumHUD(0, 0);
		rubyHUD = new RubyHUD(0, 0);
		sapphireHUD = new SapphireHUD(0, 0);
		silverHUD = new SilverHUD(0, 0);
		topazHUD = new TopazHUD(0, 0);
		// evil ship just to have an empty array (because it needs something correct to target)
		// evilShips = new Array<EvilShip>();
		if (rcr.ArriveTimer < 500)
			rcr.ArriveTimer += 500;
		// level stuff
		exit = new Exit(200, 200);

		// selection rectangles
		defenseRect = new Rectangle(rcr.MW / 2 - 150, rcr.MH - 340, 600, 50);
		maxHealthRect = new Rectangle(rcr.MW / 2 - 150, rcr.MH - 392, 600, 50);
		movementSpeedRect = new Rectangle(rcr.MW / 2 - 150, rcr.MH - 444, 600, 50);
		turretRect = new Rectangle(rcr.MW / 2 - 150, rcr.MH - 496, 600, 50);
		drillRect = new Rectangle(rcr.MW / 2 - 150, rcr.MH - 548, 600, 50);
		attackRangeRect = new Rectangle(rcr.MW / 2 - 150, rcr.MH - 600, 600, 50);
		fireRateRect = new Rectangle(rcr.MW / 2 - 150, rcr.MH - 652, 600, 50);
		unlockPersonalGunRect = new Rectangle(rcr.MW / 2 - 150, rcr.MH - 704, 600, 50);

		cameraInitX = camera.position.x;
		cameraInitY = camera.position.y;
	}

	public void update(float dt) {
		// now it's not tied to the players death. Just set the cameraShakeTimer;
		if (cameraShakeTimer > 0) {
			u.UsefulMethods.MoveCameraAroundRandomly(camera, 1, 4);
			camera.update();
			cameraShakeTimer -= 1;
		} else {
			camera.position.x = cameraInitX;
			camera.position.y = cameraInitY;
		}
	}

	@Override
	public void show() {
		Gdx.input.setInputProcessor(new InputAdapter() {
			@Override
			public boolean keyDown(int keyCode) {
				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;
			}

		});
	}

	@Override
	public void render(float delta) {
		// bind the fbo (lighting)
		// fbo.begin();
		Gdx.gl.glClearColor(0f, 0f, 0f, 0f);// lighting
		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(0f, 0f, 0f, 1);// black. we're outside.
		// ScreenUtils.clear(.2f, .5f, .2f, 1);// green.
		game.batch.setProjectionMatrix(camera.combined);
		if (!isCameraPositionInitialized) {
			cameraInitX = Gdx.graphics.getWidth() * .5f;
			cameraInitY = Gdx.graphics.getHeight() * .5f;
			isCameraPositionInitialized = true;
		}
		game.batch.begin();// start the batch. (should be already clear...)
		// System.out.println("game batch begin has been called. " + game.batch + " see? ");
		if (Global.IsPaused) {
			ScreenUtils.clear(0, 0, 0, 1);// black
			camera.position.x = Gdx.graphics.getWidth() * .5f;
			camera.position.y = Gdx.graphics.getHeight() * .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.playerSelectLeftRect, Color.RED, camera.combined);// if you want to use this, don't forget to comment out some
			// code in the main render loop below...
		} 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, whatIsLoading, camera.position.x - rcr.MW / 2 + 420, camera.position.y + rcr.MH / 2 - 247);// shadow
				game.font.setColor(Color.DARK_GRAY);
				game.font.draw(game.batch, whatIsLoading, camera.position.x - rcr.MW / 2 + 418, camera.position.y + rcr.MH / 2 - 245);
				if (!isLevelAdded && delayTimer <= 0) {
					System.out.println("doing the level");
					whatIsLoading = "Loading: there is aboslutely something here. Lets find out what it is";
					for (int x = 0; x < 1; x++) {// trying 5 of them.
						FireParticle firep = torch.obtain();
						firep.rect.x = Global.P.x;
						firep.rect.y = Global.P.y;
						fireParticles.add(firep);
					}
					System.out.println("some dirt? behind, well not really, i mean, well yeah YEAH take the dirt");
					isLevelAdded = true;
					delayTimer = DTSpd;
				} else if (!isPlayerAdded && delayTimer <= 0) {
					System.out.println("doing the Player(s)");
					whatIsLoading = "Loading: Constructing player";
					player = new Player(rcr.MW / 4, rcr.MH / 2);// to the left of center!
//					player2 = new Player2(rcr.MW / 4 - 20, rcr.MH / 2 - 20);// to the left of center!
//					player3 = new Player3(rcr.MW / 4 - 40, rcr.MH / 2 - 20);// to the left of center!
//					player4 = new Player4(rcr.MW / 4 - 60, rcr.MH / 2 + 20);// to the left of center!
//					player5 = new Player5(rcr.MW / 4 - 50, rcr.MH / 2 + 30);// to the left of center!
//					player6 = new Player6(rcr.MW / 4 + 20, rcr.MH / 2 - 10);// to the left of center!
					delayTimer = DTSpd;
					isPlayerAdded = true;
					isEvilShipsAdded = true;
				}
				if (isEvilShipsAdded && delayTimer <= 0) {
					System.out.println("now everything is done");
					isEverythingLoaded = true;
				}
				if (delayTimer > 0)
					delayTimer--;
				game.batch.end();
				// fbo.end();
			} else {
				// draw level
				exit.render(game, camera, delta);
				// draw engine particles
				// 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 - 15, player.rect.y - 4);// this must be the offset
//				// draw player2
//				game.batch.setColor(player2.color);
//				game.batch.draw(player2.getFrame(delta, camera), player2.rect.x - 24, player2.rect.y - 4);
//				// draw player3
//				game.batch.setColor(player3.color);
//				game.batch.draw(player3.getFrame(delta, camera), player3.rect.x - 24, player3.rect.y - 4);
//				// draw player4
//				game.batch.setColor(player4.color);
//				game.batch.draw(player4.getFrame(delta, camera), player4.rect.x - 24, player4.rect.y - 4);
//				// draw player5
//				game.batch.setColor(player5.color);
//				game.batch.draw(player5.getFrame(delta, camera), player5.rect.x - 24, player5.rect.y - 4);
//				// draw player6
//				game.batch.setColor(player6.color);
//				game.batch.draw(player6.getFrame(delta, camera), player6.rect.x - 24, player6.rect.y - 4);
				// p1 text
//				game.font.getData().setScale(.4f);
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "P1", player.rect.x, player.rect.y - 1);// shadow
//				game.font.setColor(Color.ORANGE);// set color before you draw
//				game.font.draw(game.batch, "P1", player.rect.x, player.rect.y);
//				game.font.getData().setScale(1f);
//				// p2 text
//				game.font.getData().setScale(.4f);
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "P2", player2.rect.x, player2.rect.y - 1);// shadow
//				game.font.setColor(Color.BLUE);// set color before you draw
//				game.font.draw(game.batch, "P2", player2.rect.x, player2.rect.y);
//				game.font.getData().setScale(1f);
//				// p3 text
//				game.font.getData().setScale(.4f);
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "P3", player3.rect.x, player3.rect.y - 1);// shadow
//				game.font.setColor(Color.PURPLE);// set color before you draw
//				game.font.draw(game.batch, "P3", player3.rect.x, player3.rect.y);
//				game.font.getData().setScale(1f);
//				// p4 text
//				game.font.getData().setScale(.4f);
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "P4", player4.rect.x, player4.rect.y - 1);// shadow
//				game.font.setColor(Color.GREEN);// set color before you draw
//				game.font.draw(game.batch, "P4", player4.rect.x, player4.rect.y);
//				game.font.getData().setScale(1f);
//				// p5 text
//				game.font.getData().setScale(.4f);
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "P5", player5.rect.x, player5.rect.y - 1);// shadow
//				game.font.setColor(Color.RED);// set color before you draw
//				game.font.draw(game.batch, "P5", player5.rect.x, player5.rect.y);
//				game.font.getData().setScale(1f);
//				// p6 text
//				game.font.getData().setScale(.4f);
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "P6", player6.rect.x, player6.rect.y - 1);// shadow
//				game.font.setColor(Color.TEAL);// set color before you draw
//				game.font.draw(game.batch, "P6", player6.rect.x, player6.rect.y);
				game.font.getData().setScale(1f);
				// player healthbar
				game.batch.setColor(player.healthBar.color);
				player.healthBar.render(game, camera, delta, player.rect.x, player.rect.y - 50f, Player.health, Player.healthMax);
				// player.powerBar.render(game, camera, delta, player.rect, player.powerBarNumber, player.powerBarMax);
				// draw player 1 balls
				for (int d = 0; d < player.balls.size; d++) {
					if (!player.balls.get(d).isDead) {
						// game.font.draw(game.batch, "" + player.balls.size, player.rect.x, player.rect.y);
						game.batch.setColor(player.balls.get(d).color);
						game.batch.draw(player.balls.get(d).getFrame(camera, delta), player.balls.get(d).rect.x, player.balls.get(d).rect.y);
					} else if (!player.balls.get(d).explosion.isDead) {
						game.batch.setColor(player.balls.get(d).explosion.getColor());
						game.batch.draw(player.balls.get(d).explosion.getFrame(camera, delta), player.balls.get(d).explosion.rect.x,
								player.balls.get(d).explosion.rect.y);
					}
				}
//				// player 2 healthbars
//				game.batch.setColor(player2.healthBar.color);
//				player2.healthBar.render(game, camera, delta, player2.rect, Player2.health, Player2.healthMax);
//				player2.powerBar.render(game, camera, delta, player2.rect, player2.powerBarNumber, player2.powerBarMax);
//				// player 3 healthbars
//				game.batch.setColor(player3.healthBar.color);
//				player3.healthBar.render(game, camera, delta, player3.rect, Player3.health, Player3.healthMax);
//				player3.powerBar.render(game, camera, delta, player3.rect, player3.powerBarNumber, player3.powerBarMax);
//				// player 4 healthbars
//				game.batch.setColor(player4.healthBar.color);
//				player4.healthBar.render(game, camera, delta, player4.rect, Player4.health, Player4.healthMax);
//				player4.powerBar.render(game, camera, delta, player4.rect, player4.powerBarNumber, player4.powerBarMax);
//				// player 5 healthbars
//				game.batch.setColor(player5.healthBar.color);
//				player5.healthBar.render(game, camera, delta, player5.rect, Player5.health, Player5.healthMax);
//				player5.powerBar.render(game, camera, delta, player5.rect, player5.powerBarNumber, player5.powerBarMax);
//				// player 6 healthbars
//				game.batch.setColor(player6.healthBar.color);
//				player6.healthBar.render(game, camera, delta, player6.rect, Player6.health, Player6.healthMax);
//				player6.powerBar.render(game, camera, delta, player6.rect, player6.powerBarNumber, player6.powerBarMax);
				// draw gun balls
				// icons:
				game.font.setColor(Color.WHITE);// set color before you draw
				game.batch.setColor(Color.WHITE);// reset batch color
				// draw gem/metal hud
				game.font.getData().setScale(.7f);
				amethystHUD.render(game, camera, delta, player.rect.x, player.rect.y - 25f);
				game.font.setColor(Color.PURPLE);
				game.font.draw(game.batch, "" + Global.p1AmethystStockpile, player.rect.x + 34f, player.rect.y - 14f);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "" + Global.p1AmethystStockpile, player.rect.x + 33f, player.rect.y - 13f);
				topazHUD.render(game, camera, delta, player.rect.x, player.rect.y - 45f);
				game.font.setColor(Color.GOLD);
				game.font.draw(game.batch, "" + Global.p1TopazStockpile, player.rect.x + 34f, player.rect.y - 34f);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "" + Global.p1TopazStockpile, player.rect.x + 33f, player.rect.y - 33f);
				sapphireHUD.render(game, camera, delta, player.rect.x, player.rect.y - 65f);
				game.font.setColor(Color.BLUE);
				game.font.draw(game.batch, "" + Global.p1SapphireStockpile, player.rect.x + 34f, player.rect.y - 54f);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "" + Global.p1SapphireStockpile, player.rect.x + 33f, player.rect.y - 53f);
				rubyHUD.render(game, camera, delta, player.rect.x, player.rect.y - 85f);
				game.font.setColor(Color.RED);
				game.font.draw(game.batch, "" + Global.p1RubyStockpile, player.rect.x + 34f, player.rect.y - 74f);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "" + Global.p1RubyStockpile, player.rect.x + 33f, player.rect.y - 73f);
				diamondHUD.render(game, camera, delta, player.rect.x, player.rect.y - 105f);
				game.font.setColor(Color.CYAN);
				game.font.draw(game.batch, "" + Global.p1DiamondStockpile, player.rect.x + 34f, player.rect.y - 94f);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "" + Global.p1DiamondStockpile, player.rect.x + 33f, player.rect.y - 93f);
				copperHUD.render(game, camera, delta, player.rect.x + 60f, player.rect.y - 30f);
				game.font.setColor(Color.SALMON);
				game.font.draw(game.batch, "" + Global.p1CopperStockpile, player.rect.x + 101f, player.rect.y - 16f);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "" + Global.p1CopperStockpile, player.rect.x + 100f, player.rect.y - 15f);
				silverHUD.render(game, camera, delta, player.rect.x + 60f, player.rect.y - 55f);
				game.font.setColor(Color.GRAY);
				game.font.draw(game.batch, "" + Global.p1SilverStockpile, player.rect.x + 101f, player.rect.y - 41f);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "" + Global.p1SilverStockpile, player.rect.x + 100f, player.rect.y - 40f);
				goldHUD.render(game, camera, delta, player.rect.x + 60f, player.rect.y - 80f);
				game.font.setColor(Color.YELLOW);
				game.font.draw(game.batch, "" + Global.p1GoldStockpile, player.rect.x + 101f, player.rect.y - 66f);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "" + Global.p1GoldStockpile, player.rect.x + 100f, player.rect.y - 65f);
				platinumHUD.render(game, camera, delta, player.rect.x + 60f, player.rect.y - 105f);
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "" + Global.p1PlatinumStockpile, player.rect.x + 101f, player.rect.y - 91f);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "" + Global.p1PlatinumStockpile, player.rect.x + 100f, player.rect.y - 90f);
				// draw HUD
				game.font.getData().setScale(1f);
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, player.p1displayScore, 12, rcr.MH - 12);// shadow
				game.font.setColor(Color.ORANGE);// set color before you draw
				game.font.draw(game.batch, player.p1displayScore, 13, rcr.MH - 11);

				// draw COSTS HUD
				game.font.getData().setScale(.7f);
				// punch power
				amethystHUD.render(game, camera, delta, 700, 530);
				game.font.setColor(Color.PURPLE);
				game.font.draw(game.batch, "30", 721, 541);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "30", 720, 540);
				// max health
				topazHUD.render(game, camera, delta, 700, 640);
				game.font.setColor(Color.GOLD);
				game.font.draw(game.batch, "10", 721, 651);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "10", 720, 650);
				copperHUD.render(game, camera, delta, 755, 635);
				game.font.setColor(Color.SALMON);
				game.font.draw(game.batch, "10", 777, 651);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "10", 776, 650);
				silverHUD.render(game, camera, delta, 635, 635);
				game.font.setColor(Color.GRAY);
				game.font.draw(game.batch, "5", 666, 651);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "5", 665, 650);
				goldHUD.render(game, camera, delta, 580, 635);
				game.font.setColor(Color.YELLOW);
				game.font.draw(game.batch, "1", 605, 651);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "1", 604, 650);
				// movement speed
				topazHUD.render(game, camera, delta, 700, 585);
				game.font.setColor(Color.GOLD);
				game.font.draw(game.batch, "10", 721, 595);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "10", 720, 594);
				// Drill
//				sapphireHUD.render(game, camera, delta, 700, 480);
//				game.font.setColor(Color.BLUE);
//				game.font.draw(game.batch, "20", 721, 491);// shadow
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "20", 720, 490);
//				goldHUD.render(game, camera, delta, 755, 480);
//				game.font.setColor(Color.YELLOW);
//				game.font.draw(game.batch, "10", 777, 491);// shadow
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "10", 776, 490);
				// Fire Rate
//				sapphireHUD.render(game, camera, delta, 700, 380);
//				game.font.setColor(Color.BLUE);
//				game.font.draw(game.batch, "13", 721, 391);// shadow
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "13", 720, 390);
				// restore your health back up
				copperHUD.render(game, camera, delta, 700, 685);
				game.font.setColor(Color.RED);
				game.font.draw(game.batch, "10", 721, 701);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "10", 720, 700);
				// attack Range
//				diamondHUD.render(game, camera, delta, 700, 430);
//				game.font.setColor(Color.CYAN);
//				game.font.draw(game.batch, "3", 721, 441);// shadow
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "3", 720, 440);
				// unlock personal gun
				copperHUD.render(game, camera, delta, 755, 320);
				game.font.setColor(Color.SALMON);
				game.font.draw(game.batch, "99", 777, 333);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "99", 776, 334);
				silverHUD.render(game, camera, delta, 700, 320);
				game.font.setColor(Color.GRAY);
				game.font.draw(game.batch, "60", 723, 333);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "60", 722, 332);
				goldHUD.render(game, camera, delta, 650, 320);
				game.font.setColor(Color.YELLOW);
				game.font.draw(game.batch, "50", 671, 333);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "50", 670, 332);
				platinumHUD.render(game, camera, delta, 600, 320);
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "10", 621, 333);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "10", 620, 332);
				sapphireHUD.render(game, camera, delta, 500, 320);
				game.font.setColor(Color.BLUE);
				game.font.draw(game.batch, "40", 521, 332);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "40", 520, 331);
				diamondHUD.render(game, camera, delta, 550, 320);
				game.font.setColor(Color.CYAN);
				game.font.draw(game.batch, "30", 565, 331);// shadow
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "30", 564, 330);
				// add upgrade options here:
				// 17) upgrade shop, defense(health), movement speed (engines), attack (guns), drills (speeds up the rate of digging things out of the earth for
				// points)
				int ofx = 100;
				int ofy = 200;
				game.font.getData().setScale(2f);
				game.font.setColor(Color.BROWN);
				game.font.draw(game.batch, "Welcome to the Night Stall", rcr.MW / 2 - 301 - ofx, rcr.MH + 101 - ofy);// shadow
				game.font.setColor(Color.WHITE);// set color before you draw
				game.font.draw(game.batch, "Welcome to the Night Stall", rcr.MW / 2 - 300 - ofx, rcr.MH + 100 - ofy);
				game.font.getData().setScale(1f);
				game.font.setColor(Color.ORANGE);
				game.font.draw(game.batch, "Use the mouse to select which one you'd like and just press them.", rcr.MW / 2 - 351 - ofx, rcr.MH + 31 - ofy);// shadow
				game.font.setColor(Color.WHITE);// set color before you draw
				game.font.draw(game.batch, "Use the mouse to select which one you'd like and just press them.", rcr.MW / 2 - 350 - ofx, rcr.MH + 30 - ofy);
				game.font.getData().setScale(1f);
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "When done go out the portal, like move your butt out to it.", rcr.MW / 2 - 351 - ofx, rcr.MH - ofy);// shadow
				game.font.setColor(Color.GREEN);// set color before you draw
				game.font.draw(game.batch, "When done go out the portal, like move your butt out to it.", rcr.MW / 2 - 350 - ofx, rcr.MH - ofy);
				game.font.getData().setScale(1f);
				// do the options below
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "HEAL SOME HEALTH", rcr.MW / 2 + 1 - ofx, rcr.MH - 112 - ofy);// shadow
				game.font.setColor(Color.RED);// set color before you draw
				game.font.draw(game.batch, "HEAL SOME HEALTH", rcr.MW / 2 - ofx, rcr.MH - 111 - ofy);
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "MAX HEALTH X 2", rcr.MW / 2 + 1 - ofx, rcr.MH - 162 - ofy);// shadow
				game.font.setColor(Color.SALMON);// set color before you draw
				game.font.draw(game.batch, "MAX HEALTH X 2", rcr.MW / 2 - ofx, rcr.MH - 161 - ofy);
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "MOVEMENT SPEED + 30", rcr.MW / 2 + 1 - ofx, rcr.MH - 212 - ofy);// shadow
				game.font.setColor(Color.ORANGE);// set color before you draw
				game.font.draw(game.batch, "MOVEMENT SPEED + 30", rcr.MW / 2 - ofx, rcr.MH - 211 - ofy);
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "PUNCH POWER", rcr.MW / 2 + 1 - ofx, rcr.MH - 262 - ofy);// shadow
				game.font.setColor(Color.PURPLE);// set color before you draw
				game.font.draw(game.batch, "PUNCH POWER", rcr.MW / 2 - ofx, rcr.MH - 261 - ofy);
				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "DRILL + 1", rcr.MW / 2 + 1 - ofx, rcr.MH - 314 - ofy);// shadow
//				game.font.setColor(Color.GREEN);// set color before you draw
//				game.font.draw(game.batch, "DRILL + 1", rcr.MW / 2 - ofx, rcr.MH - 313 - ofy);
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "ATTACK RANGE + 20", rcr.MW / 2 + 1 - ofx, rcr.MH - 366 - ofy);// shadow
//				game.font.setColor(Color.CYAN);// set color before you draw
//				game.font.draw(game.batch, "ATTACK RANGE + 20", rcr.MW / 2 - ofx, rcr.MH - 365 - ofy);
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "RATE OF FIRE - 1", rcr.MW / 2 + 1 - ofx, rcr.MH - 422 - ofy);// shadow
//				game.font.setColor(Color.BLUE);// set color before you draw
//				game.font.draw(game.batch, "RATE OF FIRE - 1", rcr.MW / 2 - ofx, rcr.MH - 421 - ofy);
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "UNLOCK A GUN", rcr.MW / 2 + 1 - ofx, rcr.MH - 472 - ofy);// shadow
				game.font.setColor(Color.GOLD);// set color before you draw
				game.font.draw(game.batch, "UNLOCK A GUN", rcr.MW / 2 - ofx, rcr.MH - 471 - ofy);
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "P2: " + Player2.score, 12 + 150, rcr.MH - 12);// shadow
//				game.font.setColor(Color.BLUE);// set color before you draw
//				game.font.draw(game.batch, "P2: " + Player2.score, 13 + 150, rcr.MH - 11);
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "P3: " + Player3.score, 12 + 160 * 2, rcr.MH - 12);// shadow
//				game.font.setColor(Color.PURPLE);// set color before you draw
//				game.font.draw(game.batch, "P3: " + Player3.score, 13 + 160 * 2, rcr.MH - 11);
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "P4: " + Player4.score, 12 + 160 * 3, rcr.MH - 12);// shadow
//				game.font.setColor(Color.GREEN);// set color before you draw
//				game.font.draw(game.batch, "P4: " + Player4.score, 13 + 160 * 3, rcr.MH - 11);
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "P5: " + Player5.score, 12 + 160 * 4, rcr.MH - 12);// shadow
//				game.font.setColor(Color.RED);// set color before you draw
//				game.font.draw(game.batch, "P5: " + Player5.score, 13 + 160 * 4, rcr.MH - 11);
//				game.font.setColor(Color.WHITE);
//				game.font.draw(game.batch, "P6: " + Player6.score, 12 + 160 * 5, rcr.MH - 12);// shadow
//				game.font.setColor(Color.TEAL);// set color before you draw
//				game.font.draw(game.batch, "P6: " + Player6.score, 13 + 160 * 5, rcr.MH - 11);

				game.font.setColor(Color.RED);
				game.font.draw(game.batch, "Rastic Rush", Gdx.graphics.getWidth() / 2 - 300, rcr.MH - 12);// shadow
				game.font.setColor(Color.RED);// set color before you draw
				game.font.draw(game.batch, "Rastic Rush", Gdx.graphics.getWidth() / 2 - 300, rcr.MH - 11);

				game.font.setColor(Color.BROWN);
				game.font.draw(game.batch, "Level unknown! where are you?", rcr.MW - 440, rcr.MH - 16);// shadows
				game.font.setColor(Color.WHITE);
				game.font.draw(game.batch, "Level unknown! where are you?", rcr.MW - 439, rcr.MH - 15);
				game.font.setColor(Color.BLACK);
				// UI
				game.font.getData().setScale(1f);
				// debug info:
				// game.font.setColor(Color.BLACK);
				// game.font.draw(game.batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), rcr.MW - 156, 36);// shadow
				// game.font.setColor(Color.WHITE);
				// game.font.draw(game.batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), rcr.MW - 157, 37);
				// 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 stop: " + rcr.ExtractionTimer, camera.position.x - 300,
				 * camera.position.y + 340); game.font.setColor(Color.WHITE); game.font.draw(game.batch, "Time till Extraction: " + rcr.ExtractionTimer,
				 * camera.position.x - 301, camera.position.y + 342);
				 */
				// separate render loop for shadows.
				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(defenseRect, Color.RED, camera.combined);
				u.DebugRenderer.DrawDebugRectangle(maxHealthRect, Color.SALMON, camera.combined);
				u.DebugRenderer.DrawDebugRectangle(movementSpeedRect, Color.ORANGE, camera.combined);
				u.DebugRenderer.DrawDebugRectangle(turretRect, Color.PURPLE, camera.combined);
//				u.DebugRenderer.DrawDebugRectangle(drillRect, Color.GREEN, camera.combined);
//				u.DebugRenderer.DrawDebugRectangle(attackRangeRect, Color.CYAN, camera.combined);
//				u.DebugRenderer.DrawDebugRectangle(fireRateRect, Color.BLUE, camera.combined);
				u.DebugRenderer.DrawDebugRectangle(unlockPersonalGunRect, Color.GOLD, camera.combined);
				// u.DebugRenderer.DrawDebugRectangle(giantFoot.rect, Color.RED, camera.combined);
//				for (int i = 0; i < wallTiles.size; i++) {
//					// System.out.println("rect?: " + wallTiles.get(i).getRect());
//					u.DebugRenderer.DrawDebugRectangle(wallTiles.get(i).getRect(), Color.RED, camera.combined);
//				}
				// test for whether you are clicking on things
				if (Gdx.input.isButtonJustPressed(Input.Buttons.LEFT) && UsefulMethods.IsMouseInsideRectangle(defenseRect, camera)) {
					if (Global.p1CopperStockpile >= 10) {
						Global.p1CopperStockpile -= 10;
						Player.health += 500;
						Player.score += 2000;
					} else {
						if (!Global.SetVolumeToZero)
							click.play();
					}
				}
				if (Gdx.input.isButtonJustPressed(Input.Buttons.LEFT) && UsefulMethods.IsMouseInsideRectangle(maxHealthRect, camera)) {
					if (Global.p1CopperStockpile >= 10 && Global.p1TopazStockpile >= 10 && Global.p1SilverStockpile >= 5 && Global.p1GoldStockpile >= 1) {
						Global.p1CopperStockpile -= 10;
						Global.p1TopazStockpile -= 10;
						Global.p1SilverStockpile -= 5;
						Global.p1GoldStockpile--;
						Player.score += 4000;
					} else {
						if (!Global.SetVolumeToZero)
							click.play();
					}
				}
				if (Gdx.input.isButtonJustPressed(Input.Buttons.LEFT) && UsefulMethods.IsMouseInsideRectangle(movementSpeedRect, camera)) {
					if (Global.p1TopazStockpile >= 10) {
						Global.p1TopazStockpile -= 10;
						Global.p1Speed += 100f;
						Player.score += 1000;
					} else {
						if (!Global.SetVolumeToZero)
							click.play();
					}
				}
				if (Gdx.input.isButtonJustPressed(Input.Buttons.LEFT) && UsefulMethods.IsMouseInsideRectangle(turretRect, camera)) {
					if (Global.p1AmethystStockpile >= 30) {
						Global.p1AmethystStockpile -= 30;
						Global.p1PunchPower += 10;
						Player.score += 5000;
					} else {
						if (!Global.SetVolumeToZero)
							click.play();
					}
				}
				if (Gdx.input.isButtonJustPressed(Input.Buttons.LEFT) && UsefulMethods.IsMouseInsideRectangle(drillRect, camera)) {
					if (Global.p1SapphireStockpile >= 20 && Global.p1GoldStockpile >= 10) {
						Global.p1SapphireStockpile -= 20;
						Global.p1GoldStockpile -= 10;
						Global.isDrillV2 = true;
						Player.score += 5000;
					} else {
						if (!Global.SetVolumeToZero)
							click.play();
					}
				}
				if (Gdx.input.isButtonJustPressed(Input.Buttons.LEFT) && UsefulMethods.IsMouseInsideRectangle(attackRangeRect, camera)) {
					if (Global.p1DiamondStockpile >= 3) {
						Global.p1DiamondStockpile -= 3;
						Global.gunFiringDistance += 50f;
						Player.score += 1000;
					} else {
						if (!Global.SetVolumeToZero)
							click.play();
					}
				}
				if (Gdx.input.isButtonJustPressed(Input.Buttons.LEFT) && UsefulMethods.IsMouseInsideRectangle(fireRateRect, camera)) {
					if (Global.p1SapphireStockpile >= 13) {
						Global.p1SapphireStockpile -= 13;
						if (Global.fireDelay >= 30)
							Global.fireDelay -= 30;
						else
							Global.fireDelay = 0;
						Player.score += 1000;
					} else {
						if (!Global.SetVolumeToZero)
							click.play();
					}
				}
				if (Gdx.input.isButtonJustPressed(Input.Buttons.LEFT) && UsefulMethods.IsMouseInsideRectangle(unlockPersonalGunRect, camera)) {
					if (Global.p1DiamondStockpile >= 30 && Global.p1PlatinumStockpile >= 10 && Global.p1SapphireStockpile >= 40 && Global.p1GoldStockpile >= 50
							&& Global.p1SilverStockpile >= 60 && Global.p1CopperStockpile >= 99) {
						Global.p1DiamondStockpile -= 30;
						Global.p1PlatinumStockpile -= 10;
						Global.p1SapphireStockpile -= 40;
						Global.p1GoldStockpile -= 50;
						Global.p1SilverStockpile -= 60;
						Global.p1CopperStockpile -= 99;
						Global.isPersonalGunUnlocked = true;
						Player.score += 10000;
					} else {
						if (!Global.SetVolumeToZero)
							click.play();
					}
				}
				// music check, the show box wasn't working
				if (!Global.IsMusicPaused)
					levelMusic.play();
				// collisions
				checkPlayerShipCollisions();
				// 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. ;-) )
					Global.resetPlayersStats();
					// camera.position.y = 0;
					// camera.position.x = 0;
					// camera.update();
					game.setScreen(new Store(game));
				}
				if (player.dead) {// if you die
					System.out.println("you can't even die in here. It's the stall.");
					camera.position.y = 0;
					camera.position.x = 0;
					camera.update();
					dispose();
					game.setScreen(new LoseScreen(game, "You died!? why? what happened?"));
				}

				if (Player.health <= 0 && isDeadTimer > 0) {
					isDeadTimer--;
					if (!Global.SetVolumeToZero && !onetime) {
						onetime = true;
						death.play();
					}
					player.isDying = true;
				}
				if (rcr.ArriveTimer <= 0 && exit.isClicked && !player.isDying && Player.health >= 0 && !onlyGoThroughLevelEndOnce) {
					onlyGoThroughLevelEndOnce = true;
					player.updatep1ScoreDisplay();
					if (Global.WhatLevel == 1) {
						Global.WhatLevel = 2;
						rcr.GameSettings.putInteger("whatLevel", 2);
						rcr.GameSettings.flush();
					} else if (Global.WhatLevel == 2) {
						Global.WhatLevel = 3;
						rcr.GameSettings.putInteger("whatLevel", 3);
						rcr.GameSettings.flush();
					} else if (Global.WhatLevel == 3) {
						Global.WhatLevel = 4;
						rcr.GameSettings.putInteger("whatLevel", 4);
						rcr.GameSettings.flush();
					} else if (Global.WhatLevel == 4) {
						Global.WhatLevel = 5;
						rcr.GameSettings.putInteger("whatLevel", 5);
						rcr.GameSettings.flush();
					}
					if (!Global.SetVolumeToZero && !playSoundOnce) {
						playSoundOnce = true;
						reverseSlide.play();
					}
					camera.position.y = 0;
					camera.position.x = 0;
					camera.update();
					rcr.ArriveTimer = 0;
					dispose();
					if (Global.WhatLevel == 2)
						game.setScreen(new LevelMinusTwo(game));
					else if (Global.WhatLevel == 3)
						game.setScreen(new LevelMinusOne(game));
					else if (Global.WhatLevel == 4)
						game.setScreen(new LevelZero(game));
					else if (Global.WhatLevel == 5)
						game.setScreen(new GameScreen(game));
				}
				if (rcr.ArriveTimer > 0)
					rcr.ArriveTimer -= 10;
				update(delta);// going to set camera position to last. :-)
			}
		}

	}// end of render (or update)

	private void checkPlayerShipCollisions() {
		if (player.rect.overlaps(exit.rect)) {
			System.out.println("clicked the exit");
			exit.isClicked = true;// activate the exit!
		}
	}

//	private void setCorrectScreenCoords(int x, int y, int z) {
//		tempCoords.x = x;
//		tempCoords.y = y;
//		tempCoords.z = z;
//		mousePos = camera.unproject(tempCoords);
//	}

	/**
	 * 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() {
		enter.dispose();
		enter2.dispose();
		levelMusic.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
//		player2.dispose();
//		player3.dispose();
//		player4.dispose();
//		player5.dispose();
		click.dispose();
		click2.dispose();
		click3.dispose();
		click4.dispose();
		click5.dispose();
		click6.dispose();
		click7.dispose();
		boom.dispose();
		death.dispose();
		reverseSlide.dispose();
	}

	@Override
	public void resize(int width, int height) {
		vport.update(width, height, true);
		// camera.setToOrtho(false, width / 32f / 2f, height / 32f / 2f);
		if (!levelMusic.isPlaying() && !Global.IsMusicPaused) {
			levelMusic.play();
		}
	}

	@Override
	public void hide() {
		if (levelMusic.isPlaying() && !Global.IsMusicPaused) {
			levelMusic.pause();
		}
	}

	@Override
	public void pause() {
		if (levelMusic.isPlaying() && !Global.IsMusicPaused) {
			levelMusic.pause();
		}
	}

	@Override
	public void resume() {
		if (!levelMusic.isPlaying() && !Global.IsMusicPaused) {
			levelMusic.play();
		}
	}

}
