private void update() {
		// This is where all the fancy game magic happens.
		
		currentFrame= currentFrame+1%60; //Keep track of frames in set of 60. (60fps)
		explosionFrame++; //Increment the current frame of explosion. (Animation not implemented yet)
	    if(Gdx.input.isTouched()) {
	    	Space.player.moveToTouch(camera); 
	    	
	    	//System.out.println("X: "+Gdx.input.getX());
	    	//System.out.println("Y: "+Gdx.input.getY());
	    }
	    
	    if(Gdx.input.isKeyPressed(Keys.LEFT)) Space.player.moveLeft();
	    if(Gdx.input.isKeyPressed(Keys.RIGHT)) Space.player.moveRight();
	    if(Gdx.input.isKeyPressed(Keys.UP)) Space.player.moveUp();
	    if(Gdx.input.isKeyPressed(Keys.DOWN)) Space.player.moveDown();
	    if(Gdx.input.isKeyPressed(Keys.SPACE)) {Space.player.fire(); /*System.out.println("Shot fired, shots: " + shots.size());*/}
	    if(!Gdx.input.isKeyPressed(Keys.SPACE)) Space.player.stopFiring();
	    if(Gdx.input.isKeyPressed(Keys.NUM_1)) {if(Space.player.currentForm == -1)Space.player.transform(0);}
	    if(Gdx.input.isKeyPressed(Keys.NUM_2)) {if(Space.player.currentForm == -1)Space.player.transform(1);}
	    if(Gdx.input.isKeyPressed(Keys.NUM_3)) {if(Space.player.currentForm == -1)Space.player.transform(2);}
	    
	    //Debugging Cheats
	    if(Gdx.input.isKeyPressed(Keys.R)){Space.player.currentForm = -1; Space.player.health = Space.player.healthMax;} //Come back to life
	    if(Gdx.input.isKeyPressed(Keys.A)){ //Print out all player stats
	    	//Printout
			System.out.println(Space.player.laserFireRate);
			System.out.println(Space.player.shipLvl);
			System.out.println(Space.player.baseSpeed);
			System.out.println(Space.player.health);
			System.out.println(Space.player.healthMax);
			System.out.println(Space.player.laserDamage);
			System.out.println(Space.player.laserFireRate);

			System.out.println(Space.player.healthCost);
			System.out.println(Space.player.laserDamageCost);
			System.out.println(Space.player.laserFireRateCost);
			System.out.println(Space.player.velocityCost);

			//Fire
			System.out.println(Space.player. fireFormLvl);
			System.out.println(Space.player.fireFormDuration);
			System.out.println(Space.player.fireballDamage);
			System.out.println(Space.player.fireballVelocity);
			System.out.println(Space.player.fireballFireRate);
			System.out.println(Space.player.fireCapacity);

			System.out.println(Space.player.fireFormDurationCost);
			System.out.println(Space.player.fireballDamageCost);
			System.out.println(Space.player.fireballFireRateCost);
			System.out.println(Space.player.fireballVelocityCost);
			System.out.println(Space.player.fireCapacityCost); 

			//Lightning
			System.out.println(Space.player.lightningFormLvl);
			System.out.println(Space.player. lightningBoltDamage);
			System.out.println(Space.player.lightningBoltVelocity);
			System.out.println(Space.player.lightningFormDuration);
			System.out.println(Space.player.lightningBoltFireRate);
			System.out.println(Space.player.lightningCapacity);

			System.out.println(Space.player.lightningFormDurationCost);
			System.out.println(Space.player.lightningDamageCost);

			//Wind
			System.out.println(Space.player.windFormLvl);
			System.out.println(Space.player.windFormDuration);
			System.out.println(Space.player.windBladeFireRate);
			System.out.println(Space.player.windCapacity);
			System.out.println(Space.player.windFormVelocityBoost);

			System.out.println(Space.player.windFormDurationCost);
			System.out.println(Space.player.windBladeDamageCost);
			System.out.println(Space.player.windBladeFireRateCost);
			System.out.println(Space.player.windFormVelocityCost);
			
			
			System.out.println(Space.player.shipXp);
			System.out.println(Space.player.fireFormXp);
			System.out.println(Space.player.windFormXp);
			System.out.println(Space.player.lightningFormXp);
			System.out.println(Space.player.careerKills);

			System.out.println(Space.player.genericOrbs);
			System.out.println(Space.player.spendableFireOrbs);
			System.out.println(Space.player.spendableWindOrbs);
			System.out.println(Space.player.spendableLightningOrbs);
			System.out.println(Space.player.fireOrbs);
			System.out.println(Space.player.windOrbs);
			System.out.println(Space.player.lightningOrbs);
			nextWave(); }
	    if(Gdx.input.isKeyPressed(Keys.S)) {
	    	angle = (angle+1)%360;
	    	testExplosions.add(new Projectile(imageLib, 400, 240, 0, angle));

	    }
	    if(Gdx.input.isKeyPressed(Keys.D)) Space.player.speed--;
	    if(Gdx.input.isKeyPressed(Keys.F)) Space.player.speed++;
	    if(Gdx.input.isKeyPressed(Keys.G)) projectileType = 11;
	    
	    // Update background
	    background1.x -= 40 * Gdx.graphics.getDeltaTime();
	     background2.x -= 40 * Gdx.graphics.getDeltaTime();
	     if(background1.x < -1000)background1.x=1000;
	     if(background2.x < -1000)background2.x=1000;
	     
	      
	    //Spawn Enemy Projectiles
	    if((TimeUtils.nanoTime() - lastShotTime > (enemyShotRate))){
	    	  if(enemies.size()!=0){
	    		  lastShotTime = TimeUtils.nanoTime();
	    	  int randomEnemyNumber = (int) (TimeUtils.nanoTime()%(enemies.size()));
	    	  enemyShots.add(new Projectile(imageLib, enemies.get(randomEnemyNumber).ship.x-4, (enemies.get(randomEnemyNumber).ship.y+enemies.get(randomEnemyNumber).ship.height)-12, 11));
	    	  enemyShots.add(new Projectile(imageLib, enemies.get(randomEnemyNumber).ship.x-4, enemies.get(randomEnemyNumber).ship.y+6, 11));
	    	  }
	      }
	    
	      //Spawn enemies
	      if(TimeUtils.nanoTime() - lastSpawnTime > (enemySpawnRate)) {
	    	  if (enemiesLeft>0)spawnEnemy();
	    	  //Spawn test enemies
	    	  }//enemySpawnRate increases by 1 for every wave
	      
	      enemiesLeft = (20+(wave*5))- enemiesSpawned; 
	      //System.out.println(enemiesLeft);
	      
	      
	      //Enemy Update Loop
	     for(int i = 0; i<enemies.size(); i++){
	    	 boolean removed = false;
	    	 enemies.get(i).getRect().x -= (100+enemyVelocityBoost) * Gdx.graphics.getDeltaTime();// move enemies add (wave%4+1)* to make them speed up per wabe
	         if(enemies.get(i).getRect().x + 48 < 0) {enemies.remove(i); removed = true;}
	         if(enemies.size()!=0 && !removed && enemies.get(i).getRect().overlaps(Space.player.getShip()) && Space.player.currentForm!=4) {
	        	 Space.player.health -= enemies.get(i).collideDamage;
	        	 enemies.remove(i);
	         }// if enemy touching Space.player
	      }
	     
	   //Test Explosions Update Loop
	     //This loop updates according to the physics equation for finding two dimensional position using an angle
	     /**Woot Physics Class! ^.^ 
	      * Y = Y(original)+Velocity*Sin(angle)*time + 1/2*Acceleration*time*time
	      *  X = X(original)+Velocity*Cos(angle)*time + 1/2*Acceleration*time*time
	      * Code version:
	      * 
	      * Y = Y + Speed*Sin(angle)*time + 1/2 * Acceleration*time*time
	      * X = X + Speed*Cos(angle)*time + 1/2 * Acceleration*time*time
	      * 
	      * Or for this particular case Acceleration is 0 for both x and y and we use delta time sooo...
	      * Y+= Speed*Sin(angle)*time
	      * X+= Speed*Cos(angle)*time
	      */
	     
	     //Update the position of each explosion
	     for(int i = 0; i<testExplosions.size(); i++){
	    	 testExplosions.get(i).getRect().x -= (300)*(Math.cos(testExplosions.get(i).angle))*Gdx.graphics.getDeltaTime();// move testEnemies add (wave%4+1)* to make them speed up per wabe
	    	 testExplosions.get(i).getRect().y -= (300)*(Math.sin(testExplosions.get(i).angle))*Gdx.graphics.getDeltaTime();// move testEnemies add (wave%4+1)* to make them speed up per wabe

	    	 if(testExplosions.get(i).getRect().x + 48 < 0||testExplosions.get(i).getRect().y>480) {testExplosions.remove(i);} 
	      }
	     
	     //Space.player Shots update Loop
	     for(int i = 0; i<Space.player.getShots().size(); i++){
	    	 boolean offScreen = false;
	    	 boolean contactEnemy = false;
	    	 Space.player.getShots().get(i).getRect().x += (Space.player.getShots().get(i).getSpeed()) * Gdx.graphics.getDeltaTime(); // update position
	         for (int j = 0; j<enemies.size(); j++){// test to see if the laser is touching any enemy
	         if(Space.player.getShots().get(i).getRect().overlaps(enemies.get(j).getRect())||(Space.player.getShots().get(i).getRect().x + 48 > 840)){
	        	 if(Space.player.getShots().get(i).getRect().x + 48 > 840) {
	        		 //Space.player.getShots().remove(i);
	        		 //System.out.println("Shot " + i + " off screen.");
	        		 offScreen = true;
	        	 }
	        	 else { //Enemy gets hit block
	        		 //Dont remove the enemy or shot here since it has to get cross checked for other objects.
	        		 enemies.get(j).health = enemies.get(j).health - (Space.player.getShots().get(i).getDamage()); // damage enemy equal to damage of projectile
	        		 contactEnemy = true;
	        		 }
	         	}
	         }
	         if (contactEnemy || offScreen)Space.player.getShots().remove(i);
	      }
	     
	     //Check for enemies' death
	     for (int i= 0; i<enemies.size();i++){
	     if (enemies.get(i).health < 0) {
			 destroyEnemy(i);
			 Space.player.gainXp(10);
			 enemiesKilled++; 
			 }
	     }
	     
	     //Enemy Shots update loop
	     for (int i = 0; i<enemyShots.size();i++){ 
	    	 enemyShots.get(i).rectangle.x -= (enemyShots.get(i).getSpeed()+enemyShotVelocityBoost)*Gdx.graphics.getDeltaTime();
	    	 if (enemyShots.get(i).getRect().overlaps(Space.player.ship)){
	    		 Space.player.health -= enemyShots.get(i).getDamage();
	    		 enemyShots.remove(i);
	    	 }
	    	 if (Space.player.health<=0 && Space.player.currentForm!=4){
	    		 Space.player.die();
	    		 explosionFrame = 0;
	    		 //TODO take out this or  modify it. XD
	    	 
	    	 	}
	    	 	if(Space.player.currentForm==4 && explosionFrame<60){testExplosions.add(new Projectile(imageLib, Space.player.getShip().x, Space.player.getShip().y, 0, explosionFrame%360));
	    	  		}
	    	 	}
	     //Wave Finished Check
	     if (enemiesLeft<=0 && enemies.size()==0 && Space.player.currentForm!=4){
			 nextWave();	 
		 }
	     
	     //Drops update loop
	     for (int i = 0; i<drops.size();i++){
	    	 drops.get(i).getRect().x -= (80)*Gdx.graphics.getDeltaTime();
	     if(drops.get(i).getRect().overlaps(Space.player.getShip())||drops.get(i).getRect().x < -50) {
	    	 if(drops.get(i).getRect().overlaps(Space.player.getShip()))Space.player.pickup(drops.get(i));
	    	 drops.remove(i);
	    	 }// if drop hits Space.player 
	     } 
	}