Za pierwszym razem odejmuje się tyle ile powinno a potem więcej. Nie wiem czemu. Co mam zrobić i dlaczego tak się robi? Proszę o pomoc.
za zyciepostaci.style.width jest 100 px;
Kod
function ruch(){
if (parseInt(klocek.style.left) - 120 <= parseInt(cos12.style.left) && parseInt(klocek.style.left) + 120 >= parseInt(cos12.style.left)){
var hp = 200;
var obr = 50;
var z = parseInt(zyciepostaci.style.width);
var jednaliczba = hp / 100;
var wynik = z * jednaliczba;
wynik = wynik - obr;
wynik = parseInt((wynik / hp) * z);
document.getElementById("zyciepostaci").style.width = wynik+"px";
if (wynik >= 0 && wynik < 2){
alert("ded");
}
}else{
g = parseInt(cos12.style.left);
g -= 20;
document.getElementById("cos12").style.left = g+"px";
}
}
ruchpotwora = window.setInterval("ruch()", 600);
if (parseInt(klocek.style.left) - 120 <= parseInt(cos12.style.left) && parseInt(klocek.style.left) + 120 >= parseInt(cos12.style.left)){
var hp = 200;
var obr = 50;
var z = parseInt(zyciepostaci.style.width);
var jednaliczba = hp / 100;
var wynik = z * jednaliczba;
wynik = wynik - obr;
wynik = parseInt((wynik / hp) * z);
document.getElementById("zyciepostaci").style.width = wynik+"px";
if (wynik >= 0 && wynik < 2){
alert("ded");
}
}else{
g = parseInt(cos12.style.left);
g -= 20;
document.getElementById("cos12").style.left = g+"px";
}
}
ruchpotwora = window.setInterval("ruch()", 600);