@SuppressWarnings("deprecation")
	public void run() {
		while (true) {
			
			/*
			 * To all spectre stuff
			 */
			for (Spectre spectre : spectres){
				spectre.spectreVelocity = spectre.spectreVelocity.add(character.characterPosition.subtract(spectre.spectrePosition).normalize().scale(Spectre.speed));
				spectre.spectrePosition = spectre.spectrePosition.add(spectre.spectreVelocity);
				spectre.spectreVelocity = spectre.spectreVelocity.scale(.9f);
				spectre.setX(spectre.spectrePosition.getX());
				spectre.setY(spectre.spectrePosition.getY());
				if (spectre.spectrePosition.subtract(character.characterPosition).length() <= 15 && character.health >= 0){
					character.hurt(spectre.getDamage());
					character.characterVelocity = character.characterPosition.subtract(spectre.spectrePosition).normalize().scale(2f);
					try {
						AudioLoader.getAudio("OGG", ResourceLoader.getResourceAsStream("/data/audio/effects/grunt-" + new Random().nextInt(3) + ".ogg")).playAsSoundEffect(1.0f, 1.0f, false);
					} catch (IOException e) {
						e.printStackTrace();
					}
					System.out.println("Health: " + character.health);
//					if (character.health <= 0){
//						System.exit(0);
//					}
				}
				Vector3D toPlayer = character.characterPosition.subtract(spectre.spectrePosition);
				spectre.setRot((float) (- Math.atan2(toPlayer.getX(), toPlayer.getY()) * 180 / Math.PI));
//				System.out.println(spectre.spectreVelocity.toString());
			}
			
//			System.out.println(character.characterPosition.toString());
			
			character.characterVelocity = character.characterVelocity.scale(character.characterSensitivity);
			
			character.characterPosition = character.characterPosition.add(character.characterVelocity);
			
			if (character.characterVelocity.length() > 0.1){
				character.setSprite("walking");
				//System.out.println("test");
			} else {
				character.setSprite("standing");
			}
			//System.out.println(character.curSpriteName);
			
			character.setX(character.characterPosition.getX());
			character.setY(character.characterPosition.getY());

//			this.viewTranslation = this.viewTranslation.add(tShis.cameraVelocity);
			

			Rtree newTree = new Rtree(rtree.maxCount);
			for (Sprite sprite : sprites){
				newTree.add(sprite);
			}
			rtree = newTree;
			rtreeGen = true;

			for (Chunk[] chunkSublist : chunks){
				for (Chunk chunk : chunkSublist){
					if (chunk.getBoundingBox().intersects(character.getBoundingBox())){
						chunk.activateSwitches(chunks);
						/*
						 * Calculate the local bounding box for the player within the rectangle
						 */
						Rectangle playerRect = character.getBoundingBox();
						playerRect.move((int) (playerRect.getX() - chunk.getBoundingBox().getX()), (int) (playerRect.getY() - chunk.getBoundingBox().getY()));
						for (int x = 0; x < Chunk.CHUNKDIMENSION; x++){
							for (int y = 0; y < Chunk.CHUNKDIMENSION; y++){
								if (chunk.getTiles()[x][y] == Chunk.WALL){ 
									Rectangle tileRect = new Rectangle(x * Chunk.WALLDIMENSION, y * Chunk.WALLDIMENSION, Chunk.WALLDIMENSION, Chunk.WALLDIMENSION);
									if (playerRect.intersects(tileRect)){
										Rectangle collisionRect = tileRect.intersection(playerRect);
										if (collisionRect.getHeight() > collisionRect.getWidth()){
											if (collisionRect.getX() == playerRect.getX()){
												character.characterPosition = character.characterPosition.add(new Vector3D((int) collisionRect.getWidth(), 0, 0));
											} else {
												character.characterPosition = character.characterPosition.add(new Vector3D(- (int) collisionRect.getWidth(), 0, 0));
											}
										} else {
											if (collisionRect.getY() == playerRect.getY()){
												character.characterPosition = character.characterPosition.add(new Vector3D(0, (int) collisionRect.getHeight(), 0));
											} else {
												character.characterPosition = character.characterPosition.add(new Vector3D(0, - (int) collisionRect.getHeight(), 0));
											}
										}
									}
								}
							}
						}
					}
					for (Spectre spectre : spectres){
						if (chunk.getBoundingBox().intersects(spectre.getBoundingBox())){
							/*
							 * Calculate the local bounding box for the player within the rectangle
							 */
							Rectangle spectreRect = spectre.getBoundingBox();
							spectreRect.move((int) (spectreRect.getX() - chunk.getBoundingBox().getX()), (int) (spectreRect.getY() - chunk.getBoundingBox().getY()));
							for (int x = 0; x < Chunk.CHUNKDIMENSION; x++){
								for (int y = 0; y < Chunk.CHUNKDIMENSION; y++){
									if (chunk.getTiles()[x][y] == Chunk.WALL){ 
										Rectangle tileRect = new Rectangle(x * Chunk.WALLDIMENSION, y * Chunk.WALLDIMENSION, Chunk.WALLDIMENSION, Chunk.WALLDIMENSION);
										if (spectreRect.intersects(tileRect)){
											Rectangle collisionRect = tileRect.intersection(spectreRect);
											if (collisionRect.getHeight() > collisionRect.getWidth()){
												if (collisionRect.getX() == spectreRect.getX()){
													spectre.spectrePosition = spectre.spectrePosition.add(new Vector3D((int) collisionRect.getWidth(), 0, 0));
												} else {
													spectre.spectrePosition = spectre.spectrePosition.add(new Vector3D(- (int) collisionRect.getWidth(), 0, 0));
												}
											} else {
												if (collisionRect.getY() == spectreRect.getY()){
													spectre.spectrePosition = spectre.spectrePosition.add(new Vector3D(0, (int) collisionRect.getHeight(), 0));
												} else {
													spectre.spectrePosition = spectre.spectrePosition.add(new Vector3D(0, - (int) collisionRect.getHeight(), 0));
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
			
			//ArrayList<Sprite> interChar = rtree.getIntersectingSprites(character);
			
			
			try {
				Thread.sleep(10);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			
			if (win > 0){
				if (win == 1000){
					System.out.println("PLAY");
					try {
						AudioLoader.getAudio("OGG", ResourceLoader.getResourceAsStream("/data/audio/effects/bum-bum-0.ogg")).playAsSoundEffect(1.0f, 1.0f, false);
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
				win--;
			}
		}
	}