From 7e1305ef42d6a63b158d39976ad41919a34bb6b3 Mon Sep 17 00:00:00 2001 From: He4eT Date: Fri, 6 Jun 2025 17:34:06 +0200 Subject: [PATCH] game: verticalLine effect --- game.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/game.js b/game.js index 3127f38..babdd3f 100644 --- a/game.js +++ b/game.js @@ -118,7 +118,7 @@ function handleMorse() { if (btnp(BTN_B, 100, 100)) { if (enemies.length > 0) { effects.unshift({ - type: 'laser', + type: 'verticalLine', from: { x: player.x, y: player.y, @@ -127,7 +127,7 @@ function handleMorse() { x: enemies[0].x[0], y: enemies[0].y[0], }, - frames: [1, 2, 3, 4, 7, 7, 7, 6, 5, 4, 3, 2, 1], + frames: [4, 5, 6, 7, 7, 6, 5, 4], }) enemies.shift() trace(enemies.length) @@ -202,7 +202,7 @@ function drawFX() { .forEach((effect) => ({ laser: ({ from, to, frames }) => { - // frames: [1, 2, 3, 4, 7, 7, 7, 6, 5, 4, 3, 2, 1], + // [1, 2, 3, 4, 7, 7, 7, 6, 5, 4, 3, 2, 1] const color = frames.shift() line(from.x, from.y, to.x, to.y, color) circ(from.x, from.y, frames.length / 3, color) @@ -210,10 +210,16 @@ function drawFX() { circb(to.x, to.y, frames.length, color + 3) }, nuke: ({ to, frames }) => { - // frames: [6, 5, 4, 3, 2], + // [6, 5, 4, 3, 2] const color = frames.shift() circ(to.x, to.y, Math.pow(frames.length, 5), color) }, + verticalLine: ({ to, frames }) => { + // [4, 5, 6, 7, 7, 6, 5, 4] + const color = frames.shift() + + rect(0, to.y - frames.length, SCREEN_W, frames.length * 2, color) + }, })[effect.type](effect), ) @@ -230,8 +236,18 @@ function drawPlayer() { drawSprite(player.sprite, player.x, player.y) } +// Utils + +function rnd(from, to) { + return Math.floor(Math.random() * (to - from + 1)) + from; +} + // Constants +// Screen +const SCREEN_W = 240 +const SCREEN_H = 136 + // Buttons const [BTN_U, BTN_D, BTN_L, BTN_R, BTN_A, BTN_B, BTN_X, BTN_Y] = [ ...Array(8).keys(),