siz atlatmak mermilere zorunda nerede kaçırmak her merminin için, bir oyun oluşturmaTuval oyunu
Sorun 1 puan kazanırlar. Şu anda elime geçen her mermi var, skor yükseliyor.
skor sizi özlüyor her merminin için artar, böylece
Bunu nasıl değiştirebilirim Soru?
Böyle "yakın özlüyor" test edebilirsiniz
function init() {
level = 1;
total_projectiles = 0;
projectiles = [];
c = document.getElementById("c");
ctx = c.getContext("2d");
ctx.fillStyle = "#ff6600";
ctx.fillRect(0, 0, 500, 600);
c.addEventListener("mousemove", function (e) {
//moving over the canvas.
var bounding_box = c.getBoundingClientRect();
player.x = (e.clientX - bounding_box.left) * (c.width/bounding_box.width) - player_img.width/2;
}, false);
setupProjectiles();
requestAnimationFrame(tick);
}
function setupProjectiles() {
var max_projectiles = level * projectiles_per_level;
while (projectiles.length < max_projectiles) {
initProjectile(projectiles.length);
}
}
function initProjectile(index) {
var max_speed = max_speed_per_level * level;
var min_speed = min_speed_per_level * level;
projectiles[index] = {
x: Math.round(Math.random() * (width - 2 * projectile_w)) + projectile_w,
y: -projectile_h,
v: Math.round(Math.random() * (max_speed - min_speed)) + min_speed,
delay: Date.now() + Math.random() * delay
}
total_projectiles++;
}
function collision(projectile) {
if (projectile.y + projectile_img.height < player.y + 74) {
return false;
}
if (projectile.y > player.y + 74) {
return false;
}
if (projectile.x + projectile_img.width < player.x + 177) {
return false;
}
if (projectile.x > player.x + 177) {
return false;
}
return true;
}
function maybeIncreaseDifficulty() {
level = Math.max(1, Math.ceil(player.score/10));
setupProjectiles();
}
function tick() {
var i;
var projectile;
var dateNow = Date.now();
c.width = c.width;
for (i = 0; i < projectiles.length; i++) {
projectile = projectiles[i];
if (dateNow > projectile.delay) {
projectile.y += projectile.v;
if (collision(projectile)) {
initProjectile(i);
player.score++;
} else if (projectile.y > height) {
initProjectile(i);
} else {
ctx.drawImage(projectile_img, projectile.x, projectile.y);
}
}
}
sorun ortaya görünmektedir yere aşağı dahil kodunu daraltmak ediniz. – MattD
Kodunuzu okumayacağım. Fakat oyuncuya vurduğunda mermiyi imha ettiğinizden emin olmalısınız. yok edilmeyen herhangi bir mermi sonunda, oyuncuya asla vurmadığını gösteren bir pozisyona ulaşacaktır (örneğin, mermiler her zaman aşağı inerse ekranın alt kısmı). Skoru artırmak için bu tetiği kullanın. – mjohnsonengr
Sadece mermi kodu ve oyuncu kodu – RushFan2112