Double missile
This commit is contained in:
parent
82ffa5cbed
commit
7cc449240f
75
Script.js
75
Script.js
@ -178,7 +178,6 @@ function keyDownPressed(e) {
|
||||
if (e.keyCode === 80) togglePause();
|
||||
|
||||
if (e.keyCode === 16) {
|
||||
// --- FIX DI SINI: Tambahkan pengecekan !player1.dead ---
|
||||
if (abilityCharges > 0 && !game.gameOver && !gamePaused && !player1.dead) {
|
||||
useAbility();
|
||||
abilityCharges--;
|
||||
@ -194,10 +193,31 @@ function keyUpPressed(e) {
|
||||
if (e.keyCode === 32) keys.fire = false;
|
||||
}
|
||||
|
||||
// --- UPDATE FIRE BULLET: Cek Skill Double Laser ---
|
||||
function fireBullet() {
|
||||
missilesArray.push(
|
||||
new LaserBullet(player1.x + player1.width, player1.y + player1.height / 2)
|
||||
);
|
||||
if (player1.doubleLaserTimer > 0) {
|
||||
// --- SKILL AKTIF: TEMBAK 2 PELURU ---
|
||||
// Atas
|
||||
missilesArray.push(
|
||||
new LaserBullet(
|
||||
player1.x + player1.width,
|
||||
player1.y + player1.height / 2 - 15
|
||||
)
|
||||
);
|
||||
// Bawah
|
||||
missilesArray.push(
|
||||
new LaserBullet(
|
||||
player1.x + player1.width,
|
||||
player1.y + player1.height / 2 + 15
|
||||
)
|
||||
);
|
||||
} else {
|
||||
// --- NORMAL: TEMBAK 1 PELURU ---
|
||||
missilesArray.push(
|
||||
new LaserBullet(player1.x + player1.width, player1.y + player1.height / 2)
|
||||
);
|
||||
}
|
||||
|
||||
laser.currentTime = 0;
|
||||
laser.volume = 0.4;
|
||||
laser.play();
|
||||
@ -242,6 +262,8 @@ function updateGame() {
|
||||
player1.y = canvasHeight / 2 - player1.height / 2;
|
||||
player1.vx = 0;
|
||||
player1.vy = 0;
|
||||
// Reset skill jika mati
|
||||
player1.doubleLaserTimer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -262,6 +284,7 @@ function drawGame() {
|
||||
|
||||
drawParticles();
|
||||
|
||||
// --- LOGIKA PICKUP ORB ---
|
||||
for (let i = 0; i < abilityTokens.length; i++) {
|
||||
const t = abilityTokens[i];
|
||||
t.draw();
|
||||
@ -276,9 +299,19 @@ function drawGame() {
|
||||
height: t.height,
|
||||
})
|
||||
) {
|
||||
abilityCharges++;
|
||||
// Cek Tipe Orb
|
||||
if (t.type === "bomb") {
|
||||
// --- ORB KUNING (Bomb) ---
|
||||
abilityCharges++;
|
||||
createParticles(t.x, t.y, 15, "#ffff00"); // Partikel Kuning
|
||||
} else if (t.type === "double") {
|
||||
// --- ORB MERAH (Double Laser) ---
|
||||
// 10 Detik = 60 FPS * 10 = 600 Frames
|
||||
player1.doubleLaserTimer = 600;
|
||||
createParticles(t.x, t.y, 15, "#ff0000"); // Partikel Merah
|
||||
}
|
||||
|
||||
abilityTokens.splice(i, 1);
|
||||
createParticles(t.x, t.y, 15, "#00ffea");
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
@ -454,6 +487,9 @@ function drawUI() {
|
||||
}
|
||||
drawNewText(livesText, 30, canvasHeight - 50, "#ff3366");
|
||||
drawNewText("Bombs: " + abilityCharges, 30, 50, "#ffffff");
|
||||
|
||||
// --- (HAPUS) INDIKATOR TIMER DOUBLE LASER ---
|
||||
// Teks tidak lagi ditampilkan, tapi durasi skill tetap berjalan di update()
|
||||
}
|
||||
|
||||
class PlayerObject {
|
||||
@ -476,6 +512,9 @@ class PlayerObject {
|
||||
this.invincible = 0;
|
||||
this.dead = false;
|
||||
|
||||
// --- SKILL TIMER ---
|
||||
this.doubleLaserTimer = 0; // Timer dalam frame
|
||||
|
||||
this.totalFrames = 5;
|
||||
this.frameIndex = 2;
|
||||
this.spriteWidth = 0;
|
||||
@ -580,6 +619,11 @@ class PlayerObject {
|
||||
} else {
|
||||
this.frameIndex = 2;
|
||||
}
|
||||
|
||||
// --- KURANGI TIMER SKILL ---
|
||||
if (this.doubleLaserTimer > 0) {
|
||||
this.doubleLaserTimer--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -913,6 +957,7 @@ function spawnEnemyFromWave(wave) {
|
||||
enemyShipArray.push(enemy);
|
||||
}
|
||||
|
||||
// --- CLASS ORB UPDATE: Support Type ---
|
||||
class AbilityToken {
|
||||
constructor(x, y) {
|
||||
this.x = x;
|
||||
@ -920,6 +965,8 @@ class AbilityToken {
|
||||
this.width = 32;
|
||||
this.height = 32;
|
||||
this.speed = 4;
|
||||
// Random Type saat spawn: "bomb" atau "double"
|
||||
this.type = Math.random() < 0.5 ? "bomb" : "double";
|
||||
}
|
||||
|
||||
draw() {
|
||||
@ -928,10 +975,21 @@ class AbilityToken {
|
||||
const cx = this.x + this.width / 2;
|
||||
const cy = this.y + this.height / 2;
|
||||
ctx.arc(cx, cy, 12, 0, Math.PI * 2);
|
||||
|
||||
// --- WARNA ORB BERDASARKAN TIPE ---
|
||||
const g = ctx.createRadialGradient(cx, cy, 0, cx, cy, 12);
|
||||
g.addColorStop(0, "#ffffff");
|
||||
g.addColorStop(0.5, "#00ffea");
|
||||
g.addColorStop(1, "#0066ff");
|
||||
|
||||
if (this.type === "bomb") {
|
||||
// Kuning (Bomb)
|
||||
g.addColorStop(0.5, "#ffff00");
|
||||
g.addColorStop(1, "#ff9900");
|
||||
} else {
|
||||
// Merah (Double Laser)
|
||||
g.addColorStop(0.5, "#ff3333");
|
||||
g.addColorStop(1, "#990000");
|
||||
}
|
||||
|
||||
ctx.fillStyle = g;
|
||||
ctx.fill();
|
||||
ctx.restore();
|
||||
@ -943,6 +1001,7 @@ class AbilityToken {
|
||||
}
|
||||
|
||||
function maybeSpawnAbilityToken() {
|
||||
// --- KEMBALI KE 0.2% (0.002) ---
|
||||
if (Math.random() < 0.002 && abilityTokens.length < 3) {
|
||||
const y = Math.random() * (canvasHeight - 120) + 60;
|
||||
abilityTokens.push(new AbilityToken(canvasWidth + 40, y));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user