function initTimer() {
  var TimerElem = document.querySelector(".timer_bar");
  TimerElem.style.width = "0%";
  let seconds = timeEnd;
  document.getElementById("timerend").innerHTML = " / "  + seconds + " s";
}

function move() {
  var lapsPerSecond = 100 / timeEnd;
  var TimerElem = document.querySelector(".timer_bar");
  TimerElem.style.width = (parseInt(TimerElem.style.width) + lapsPerSecond) + "%";
}



var timer = new easytimer.Timer();
timer.start();
timer.addEventListener('secondsUpdated', function (e) {
  if (timer.getTimeValues().seconds <= timeEnd) {
    document.getElementById("timer").innerHTML = timer.getTimeValues().seconds.toString() + " s";
    move();
  } else {
    timeTot = timeTot + timer.getTimeValues().seconds;
    endTime();
    timer.stop();
  }
});
function endTime() {
  if(!isTuto){
    closeGame();
    var score = (niveauActuel * (50 / timeTot)).toFixed(2);
    document.querySelector("#scoreTotGameOver").innerHTML = score;
    document.querySelector("#niveauGameOver").innerHTML = niveauActuel;
    document.querySelector("#TempsTotGameOver").innerHTML = timeTot;
  //calcul stars
  resetStar();
  if(score < 10){
    document.querySelector("#star1").style.color = "#fe8a71";
  }else if(score > 10 || score < 50){
    document.querySelector("#star1").style.color = "#fe8a71";
    document.querySelector("#star2").style.color = "#fe8a71";
  }else if(score > 50 || score < 200){
    document.querySelector("#star1").style.color = "#fe8a71";
    document.querySelector("#star2").style.color = "#fe8a71";
    document.querySelector("#star3").style.color = "#fe8a71";
  }
  else if(score > 200 || score < 400){
    document.querySelector("#star1").style.color = "#fe8a71";
    document.querySelector("#star2").style.color = "#fe8a71";
    document.querySelector("#star3").style.color = "#fe8a71";
    document.querySelector("#star4").style.color = "#fe8a71";
  }else{
    document.querySelector("#star1").style.color = "#fe8a71";
    document.querySelector("#star2").style.color = "#fe8a71";
    document.querySelector("#star3").style.color = "#fe8a71";
    document.querySelector("#star4").style.color = "#fe8a71";
    document.querySelector("#star5").style.color = "#fe8a71";
  }
  openModal('gameOver');
  } 
}

function resetStar(){
  document.querySelector("#star1").style.color = document.body.style.color;
    document.querySelector("#star2").style.color = document.body.style.color;
    document.querySelector("#star3").style.color = document.body.style.color;
    document.querySelector("#star4").style.color = document.body.style.color;
    document.querySelector("#star5").style.color = document.body.style.color;
}