diff --git a/src/components/frontend/minigames/flappy/FlappyBird.tsx b/src/components/frontend/minigames/flappy/FlappyBird.tsx index 36b7bfd7..1cf9cb61 100644 --- a/src/components/frontend/minigames/flappy/FlappyBird.tsx +++ b/src/components/frontend/minigames/flappy/FlappyBird.tsx @@ -34,6 +34,17 @@ const STARS = Array.from({ length: 70 }, (_, i) => ({ r: (i % 3) + 0.5, })); +const CLOUD_MARGIN = 90; +const CLOUD_SEEDS = Array.from({ length: 7 }, (_, i) => ({ + x: ((i * 137) % (CANVAS_W + 160)) - 80, + y: 46 + ((i * 71) % 200), + s: 0.7 + ((i * 37) % 10) / 14, + v: 0.1 + ((i * 53) % 10) / 90, +})); + +const FLOCK_MIN_DELAY = 840; +const FLOCK_MAX_DELAY = 2280; + const DAY_CYCLE_SECONDS = 60; const DAY_SKY_TOP: [number, number, number] = [56, 189, 248]; @@ -57,6 +68,21 @@ interface Pipe { seed: number; } +interface Cloud { + x: number; + y: number; + s: number; + v: number; +} + +interface Flock { + x: number; + y: number; + v: number; + count: number; + t: number; +} + interface GameState { birdY: number; birdVy: number; @@ -66,6 +92,13 @@ interface GameState { groundOffset: number; runTime: number; cycleT: number; + clouds: Cloud[]; + flock: Flock | null; + flockTimer: number; +} + +function makeClouds(): Cloud[] { + return CLOUD_SEEDS.map((c) => ({ ...c })); } function drawTopBuilding(ctx: CanvasRenderingContext2D, p: Pipe, light: number) { @@ -162,6 +195,46 @@ function drawObstacle(ctx: CanvasRenderingContext2D, p: Pipe, light: number) { drawBuilding(ctx, p, light); } +function drawCloud(ctx: CanvasRenderingContext2D, c: Cloud, light: number) { + ctx.save(); + ctx.globalAlpha = 0.32 + 0.34 * light; + ctx.fillStyle = mix([30, 41, 59], [255, 255, 255], light); + const puffs = [ + [0, 0, 26, 12], + [-19, 4, 16, 9], + [19, 3, 18, 10], + [3, -8, 15, 10], + ]; + for (const [dx, dy, rx, ry] of puffs) { + ctx.beginPath(); + ctx.ellipse(c.x + dx * c.s, c.y + dy * c.s, rx * c.s, ry * c.s, 0, 0, Math.PI * 2); + ctx.fill(); + } + ctx.restore(); +} + +function drawFlock(ctx: CanvasRenderingContext2D, f: Flock, light: number) { + const alpha = 0.12 + 0.5 * light; + if (alpha <= 0.05) return; + ctx.save(); + ctx.strokeStyle = `rgba(15, 23, 42, ${alpha.toFixed(2)})`; + ctx.lineWidth = 1.4; + ctx.lineCap = "round"; + for (let i = 0; i < f.count; i++) { + const side = i === 0 ? 0 : Math.ceil(i / 2); + const sign = i % 2 === 1 ? -1 : 1; + const bx = f.x + side * 9; + const by = f.y + sign * side * 5; + const flap = 0.35 + 0.65 * Math.abs(Math.sin(f.t * 0.18 + i * 1.3)); + const w = 4.5; + ctx.beginPath(); + ctx.moveTo(bx - w, by - w * 0.55 * flap); + ctx.quadraticCurveTo(bx, by + w * 0.35 * flap, bx + w, by - w * 0.55 * flap); + ctx.stroke(); + } + ctx.restore(); +} + function drawHelicopter( ctx: CanvasRenderingContext2D, y: number, @@ -349,6 +422,9 @@ export function FlappyBird({ groundOffset: 0, runTime: 0, cycleT: 0, + clouds: makeClouds(), + flock: null, + flockTimer: 480, }); const submittingRef = useRef(false); const statsRef = useRef(serverStats); @@ -381,6 +457,9 @@ export function FlappyBird({ g.groundOffset = 0; g.runTime = 0; g.cycleT = 0; + g.clouds = makeClouds(); + g.flock = null; + g.flockTimer = 480; setScore(0); setPhaseSafe("ready"); }, [setPhaseSafe]); @@ -545,6 +624,32 @@ export function FlappyBird({ } } + for (const c of g.clouds) { + c.x -= c.v * dt; + if (c.x < -CLOUD_MARGIN) { + c.x = CANVAS_W + CLOUD_MARGIN; + c.y = 46 + Math.random() * 200; + } + } + + if (g.flock) { + g.flock.x -= g.flock.v * dt; + g.flock.t += dt; + if (g.flock.x < -90) g.flock = null; + } else { + g.flockTimer -= dt; + if (g.flockTimer <= 0) { + g.flock = { + x: CANVAS_W + 60, + y: 60 + Math.random() * 170, + v: 0.28 + Math.random() * 0.18, + count: 5 + 2 * Math.floor(Math.random() * 3), + t: Math.random() * 100, + }; + g.flockTimer = FLOCK_MIN_DELAY + Math.random() * (FLOCK_MAX_DELAY - FLOCK_MIN_DELAY); + } + } + ctx.clearRect(0, 0, CANVAS_W, CANVAS_H); const cycle = (g.cycleT / DAY_CYCLE_SECONDS) * Math.PI * 2; @@ -613,6 +718,9 @@ export function FlappyBird({ ctx.restore(); } + for (const c of g.clouds) drawCloud(ctx, c, light); + if (g.flock) drawFlock(ctx, g.flock, light); + for (const pipe of g.pipes) drawObstacle(ctx, pipe, light); ctx.fillStyle = mix([11, 15, 20], [100, 116, 139], light);