laser bullet

This commit is contained in:
Bluwww 2025-12-02 09:24:45 +07:00
parent 75262316b5
commit 807dbe828b

View File

@ -119,9 +119,8 @@ function keyDownPressed(e) {
if (e.keyCode == 32) { if (e.keyCode == 32) {
keys.fire = true; keys.fire = true;
missilesArray.push( missilesArray.push(new LaserBullet(player1.x + 150, player1.y + 50));
new Missile(player1.x + 120, player1.y + 50, "white", 12)
);
laser.currentTime = 0; laser.currentTime = 0;
laser.play(); laser.play();
@ -287,22 +286,30 @@ function addStarField() {
background1a.update(); background1a.update();
} }
class Missile { class LaserBullet {
constructor(x, y, color, speed) { constructor(x, y) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.width = 3; this.width = 14;
this.height = 10; this.height = 4;
this.color = color; this.speed = 16;
this.speed = speed;
} }
draw() { draw() {
ctx.save(); let g = ctx.createLinearGradient(
ctx.fillStyle = this.color; 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.fillRect(this.x, this.y, this.width, this.height);
ctx.fill(); ctx.shadowBlur = 0;
ctx.restore();
} }
update() { update() {
@ -310,6 +317,7 @@ class Missile {
} }
} }
class EnemyObj { class EnemyObj {
constructor(x, y, speed) { constructor(x, y, speed) {
this.x = x; this.x = x;