public void checkLevel(){
		if (foodCount==levelLength){

			//calculates the score of each snake
			score1=score1+player1.getSize()-1;
			score2=score2+player2.getSize()-1;

			snake1Alive=true;
			snake2Alive=true;

			//checks if the last level is reached
			if (level.levelNumber==5 && score1>score2){
				JOptionPane.showMessageDialog (null, "The blue snake wins! \n Blue Snake: "+score1+" \n Red Snake: "+score2 , "Game over", 1);
				mainWindow.dispose();
				alive = false;
				Menu.main(null);
			}
			else if (level.levelNumber==5 && score1<score2){
				JOptionPane.showMessageDialog (null, "The red snake wins! \n Blue Snake: "+score1+" \n Red Snake: "+score2 , "Game over", 1);
				mainWindow.dispose();
				alive = false;
				Menu.main(null);
			}
			else if (level.levelNumber==5 && score1==score2){
				JOptionPane.showMessageDialog (null, "Both snakes win! \n Blue Snake: "+score1+" \n Red Snake: "+score2 , "Game over", 1);
				mainWindow.dispose();
				alive = false;
				Menu.main(null);
			}


			else {
				JOptionPane.showMessageDialog (null, "You made it to the next level! \n Blue Snake: "+ score1 +" points and Red Snake: "+score2+" points" , "Level "+(level.levelNumber+1), 1);

				//goes to the next level
				level.moveLevelUp();

				//changes speed of snake
				delay=level.speed;

				foodCount=0;

				//changes the background image
				try {
					background = ImageIO.read(new File("bg"+level.levelNumber+".png"));
				} catch (IOException e) {
				}
				//deletes all black holes
				for(int i=0; i<blackHoleNumber; i++ ){
					tx[i]=0;
					ty[i]=0;
				}
				blackHoleNumber=0;

				//gets start positions for the next level
				xp0=obstacle.getStartPosX(level.levelNumber);
				yp0=obstacle.getStartPosY(level.levelNumber);
				xp20=obstacle.getStartPosX2(level.levelNumber);
				yp20=obstacle.getStartPosY2(level.levelNumber);
				dx=obstacle.getDx(level.levelNumber);
				dy=obstacle.getDy(level.levelNumber);
				dx2=obstacle.getDx2(level.levelNumber);
				dy2=obstacle.getDy2(level.levelNumber);

				player1 = new SnakeHead(initialSize+1, xp0, yp0);
				player1.setPos(player1.first, xp0, yp0, dx, dy);

				player2 = new SnakeHead(initialSize+1, xp20, yp20);
				player2.setPos(player2.first, xp20, yp20, dx2, dy2);

			}
		}
	}