From 807dbe828b9477b2a3bba78821baea20427f5191 Mon Sep 17 00:00:00 2001 From: Bluwww Date: Tue, 2 Dec 2025 09:24:45 +0700 Subject: [PATCH] laser bullet --- Script.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/Script.js b/Script.js index 3bff911..3ada49b 100644 --- a/Script.js +++ b/Script.js @@ -119,9 +119,8 @@ function keyDownPressed(e) { if (e.keyCode == 32) { keys.fire = true; - missilesArray.push( - new Missile(player1.x + 120, player1.y + 50, "white", 12) - ); + missilesArray.push(new LaserBullet(player1.x + 150, player1.y + 50)); + laser.currentTime = 0; laser.play(); @@ -287,22 +286,30 @@ function addStarField() { background1a.update(); } -class Missile { - constructor(x, y, color, speed) { +class LaserBullet { + constructor(x, y) { this.x = x; this.y = y; - this.width = 3; - this.height = 10; - this.color = color; - this.speed = speed; + this.width = 14; + this.height = 4; + this.speed = 16; } draw() { - ctx.save(); - ctx.fillStyle = this.color; + let g = ctx.createLinearGradient( + this.x, + this.y, + this.x + this.width, + this.y + ); + g.addColorStop(0, "#00e1ff"); + g.addColorStop(0.5, "#ffffff"); + g.addColorStop(1, "#00e1ff"); + ctx.fillStyle = g; + ctx.shadowColor = "#00ffff"; + ctx.shadowBlur = 15; ctx.fillRect(this.x, this.y, this.width, this.height); - ctx.fill(); - ctx.restore(); + ctx.shadowBlur = 0; } update() { @@ -310,6 +317,7 @@ class Missile { } } + class EnemyObj { constructor(x, y, speed) { this.x = x;