我用javascript製作了一個項目的遊戲(這裏是鏈接:https://cams03.github.io/canvus/page_accueil.html)如何在使用javascript製作的遊戲中提升速度?
現在我想通過提高飛行物體的速度來改善遊戲。我嘗試了很多東西,總會遇到問題。這裏是我的代碼示例(如果需要,我可以提供完整的代碼,但它很長)。變量CPT是得分
let planetTimer2, planetTimer3, planetTimer4;
function level() {
if (cpt == 5) {
clearInterval(planetTimer);
planetTimer2 = setInterval(spawnPlanet, 1000);
}
if (cpt == 20) {
clearInterval(planetTimer2);
planetTimer3 = setInterval(spawnPlanet, 0700);
}
if (cpt == 40) {
clearInterval(planetTimer3);
planetTimer4 = setInterval(spawnPlanet, 0500);
}
}
function countdown() {
level();
if (timeLeft < 0) {
clearTimeout(timerId);
clearTimeout(planetTimer);
clearTimeout(planetTimer2);
clearTimeout(planetTimer3);
clearTimeout(planetTimer4);
clearTimeout(bonusTimer);
let paragraph = document.getElementById("result");
if (cpt < 20) {
paragraph.innerHTML = "Ton score est de : " + cpt + ". La honte sur toi Maurice !!";
} else if (cpt < 80) {
paragraph.innerHTML = "Mouais ton score est de : " + cpt + ". Tu peux faire mieux mon vieux !";
} else {
paragraph.innerHTML = "Ton score est de : " + cpt + ". T'es un killer !!";
}
document.querySelector("h1").appendChild(paragraph);
cover.classList.add("visible");
popup.classList.add("visible");
} else {
timer.innerHTML = timeLeft;
timeLeft--;
}
};
let timerId = setInterval(countdown, 1000);
document.addEventListener("DOMContentLoaded", countdown());
rejouer.addEventListener("click", function() {
cover.classList.remove("visible");
popup.classList.remove("visible");
cpt = 0;
timeLeft = 30;
countdown();
timerId = setInterval(countdown, 1000);
spawnPlanet();
spawnBonus();
planetTimer = setInterval(spawnPlanet, 2000);
bonusTimer = setInterval(spawnBonus, 9000);
});
的事情是,if (cpt == 5)
不能使用,因爲如果趕上獎勵你的分數,而不受5通過增加從3到7(例如)這樣的平等贏得」存在並且條件不會被執行。 任何人都可以幫助我嗎?我希望我的解釋很清楚,非常感謝您的幫助!
首先,不要用'0'來加前綴。這讓JavaScript認爲它們是十六進制數字。看看你自己:'console.log(0700,700)' – Cerbrus
你對'0700'和'0500'的使用似乎是可疑的。您是否嘗試使用'700'和'500'? –
不,我不知道我可以使用700,我學會了寫0700,但它可能是錯誤的方式,我要糾正它謝謝! – Cams03