n/open-sourceu/Furry · 4 个月前
注册 登录
n/open-source · 4 个月前 · 已编辑 · 270 次浏览
u/Furry王者

做了个很有意思的输入

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Type!</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            user-select: none;
        }
        @import url('https://fonts.googleapis.com/css2?family=VT323&display=swap');

        body {
            background: #1a1410;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            font-family: 'VT323', 'Courier New', monospace;
            overflow: hidden;
        }

        .crt-container {
            background: #2a1f18;
            padding: 30px 30px 40px 30px;
            border-radius: 30px;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9), inset 0 2px 0 rgba(255, 255, 255, 0.05), 0 0 0 2px #1a120e, 0 0 0 6px
                    #2d221c;
            position: relative;
        }

        .crt-screen-wrapper {
            background: #0a0f0a;
            padding: 18px;
            border-radius: 16px;
            box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.8);
            position: relative;
        }

        .crt-screen {
            background: #1a2a1a;
            border-radius: 8px;
            position: relative;
            overflow: hidden;
            box-shadow: inset 0 0 60px rgba(0, 20, 0, 0.6), 0 0 40px rgba(0, 255, 100, 0.04);
        }

        canvas {
            display: block;
            width: 820px;
            height: 620px;
            border-radius: 6px;
            image-rendering: pixelated;
        }

        .scanlines {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: repeating-linear-gradient(0deg,
                    transparent,
                    transparent 2px,
                    rgba(0, 0, 0, 0.08) 2px,
                    rgba(0, 0, 0, 0.08) 4px);
            pointer-events: none;
            border-radius: 6px;
            z-index: 10;
            mix-blend-mode: multiply;
        }

        .vignette {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: radial-gradient(ellipse at center, transparent 60%, rgba(0, 0, 0, 0.5) 100%);
            pointer-events: none;
            border-radius: 6px;
            z-index: 11;
            mix-blend-mode: multiply;
        }

        .crt-curve {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: radial-gradient(ellipse at center, transparent 65%, rgba(0, 0, 0, 0.15) 100%);
            pointer-events: none;
            border-radius: 6px;
            z-index: 12;
            mix-blend-mode: multiply;
        }

        .power-led {
            position: absolute;
            bottom: -22px;
            right: 40px;
            display: flex;
            align-items: center;
            gap: 10px;
            color: rgba(0, 255, 100, 0.2);
            font-size: 12px;
            letter-spacing: 2px;
            font-family: 'VT323', monospace;
        }
        .power-led .dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: #00ff66;
            box-shadow: 0 0 12px rgba(0, 255, 100, 0.3);
            animation: pulse-led 2s ease-in-out infinite;
        }
        @keyframes pulse-led {
            0%,
            100% {
                opacity: 1;
            }
            50% {
                opacity: 0.3;
            }
        }

        .crt-footer {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-top: 16px;
            padding: 0 10px;
            color: rgba(0, 255, 100, 0.15);
            font-family: 'VT323', monospace;
            font-size: 14px;
            letter-spacing: 1px;
        }
        .crt-footer .brand {
            color: rgba(0, 255, 100, 0.2);
        }
        .crt-footer .brand span {
            color: rgba(0, 255, 100, 0.4);
        }
    </style>
</head>
<body>

    <div class="crt-container">
        <div class="crt-screen-wrapper">
            <div class="crt-screen">
                <canvas id="gameCanvas" width="820" height="620"></canvas>
                <div class="scanlines"></div>
                <div class="vignette"></div>
                <div class="crt-curve"></div>
            </div>
            <div class="power-led">
                <span class="dot"></span>
                <span>PWR</span>
            </div>
        </div>
        <div class="crt-footer">
            <span class="brand">✦ <span>Typing</span>  v1.2</span>
            <span>← → 移动 &nbsp;│&nbsp; A-Z / 0-9 / - 发射 &nbsp;│&nbsp; ENTER 提交 &nbsp;│&nbsp; BS 清空</span>
        </div>
    </div>

    <script>
    
        const canvas = document.getElementById('gameCanvas');
        const ctx = canvas.getContext('2d');
        const W = 820,
            H = 620;

        const COLORS = {
            bg: '#0f1a0f',
            text: '#33cc66',
            textDim: 'rgba(51, 204, 102, 0.2)',
            textBright: '#66ff99',
            textWarn: '#ff8844',
            textError: '#ff4466',
            obstacle: 'rgba(51, 204, 102, 0.10)',
            obstacleBorder: 'rgba(51, 204, 102, 0.15)',
            line: 'rgba(51, 204, 102, 0.25)',
            cursor: '#33cc66',
            enterColor: '#66ff99',
            backspaceColor: '#ff8844',
        };

     
        const CONFIG = {
            gravity: 0.38,
            bounce: 0.22,
            friction: 0.99,
            maxLetters: 5,
            cursorY: 70,
            lineY: 490,
            lineLeft: 60,
            lineRight: 760,
            cursorBlinkSpeed: 500,
            subSteps: 6,
            stickThreshold: 0.5,
            letterBounce: 0.5,
        };

   
        const obstacles = [
            { x: 100, y: 180, w: 120, h: 12, type: 'ramp', angle: 0.35 },
            { x: 350, y: 150, w: 130, h: 12, type: 'ramp', angle: -0.30 },
            { x: 580, y: 190, w: 110, h: 12, type: 'ramp', angle: 0.28 },
            { x: 250, y: 370, w: 140, h: 12, type: 'ramp', angle: -0.25 },
            { x: 470, y: 270, radius: 20, type: 'circle' },
            { x: 190, y: 320, radius: 16, type: 'circle' },
        ];

    
        let cursorX = 200;
        let letters = [];
        let activeIcons = [];
        let landedLetters = [];
        let cursorVisible = true;
        let cursorBlinkTimer = 0;
        let validationMessage = '';
        let validationMessageTimer = 0;
        const keys = { left: false, right: false };

        const ALLOWED_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-';

     
        function validateDomain(text) {
            if (text.length === 0) {
                return { valid: false, msg: ' 输入不能为空' };
            }

            // 规则1: 不能以 - 开头
            if (text.startsWith('-')) {
                return { valid: false, msg: ' 连字符不能放在开头' };
            }

            // 规则2: 不能以 - 结尾
            if (text.endsWith('-')) {
                return { valid: false, msg: ' 连字符不能放在结尾' };
            }

            // 规则3: 不能在第3位(索引2)或第4位(索引3)
            // 注意:索引从0开始,第3位 = index 2,第4位 = index 3
            for (let i = 0; i < text.length; i++) {
                if (text[i] === '-') {
                    if (i === 2 || i === 3) {
                        return { valid: false, msg: ` 连字符不能放在第${i+1}位` };
                    }
                }
            }

            return { valid: true, msg: ' 输入有效!' };
        }

        
        function dist(x1, y1, x2, y2) {
            return Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2);
        }

        function clamp(v, min, max) { return Math.max(min, Math.min(max, v)); }

        function pointToSegmentDist(px, py, ax, ay, bx, by) {
            const dx = bx - ax,
                dy = by - ay;
            const lenSq = dx * dx + dy * dy;
            if (lenSq === 0) return { dist: dist(px, py, ax, ay), nearX: ax, nearY: ay, nx: px - ax, ny: py - ay };
            let t = ((px - ax) * dx + (py - ay) * dy) / lenSq;
            t = clamp(t, 0, 1);
            const nearX = ax + t * dx,
                nearY = ay + t * dy;
            return { dist: dist(px, py, nearX, nearY), nearX, nearY, nx: px - nearX, ny: py - nearY, t };
        }


        function resolveLetterCollisions() {
            const allActive = [];

            for (const l of letters) {
                if (l.isActive) allActive.push(l);
            }

            for (const landed of landedLetters) {
                if (landed.ref && landed.ref.isActive !== false) {
                    allActive.push({
                        x: landed.x,
                        y: landed.y,
                        radius: landed.radius || 16,
                        vx: 0,
                        vy: 0,
                        isLanded: true,
                        ref: landed.ref,
                        char: landed.char,
                    });
                }
            }

            for (let i = 0; i < allActive.length; i++) {
                for (let j = i + 1; j < allActive.length; j++) {
                    const a = allActive[i];
                    const b = allActive[j];
                    const dx = a.x - b.x;
                    const dy = a.y - b.y;
                    const d = Math.sqrt(dx * dx + dy * dy);
                    const minDist = a.radius + b.radius;

                    if (d < minDist && d > 0.001) {
                        const overlap = (minDist - d) / 2;
                        const nx = dx / d;
                        const ny = dy / d;

                        if (!a.isLanded) { a.x += nx * overlap;
                            a.y += ny * overlap; }
                        if (!b.isLanded) { b.x -= nx * overlap;
                            b.y -= ny * overlap; }

                        if (a.isLanded && a.ref) {
                            const rec = landedLetters.find(l => l.ref === a.ref);
                            if (rec) { rec.x = a.x;
                                rec.y = a.y; }
                        }
                        if (b.isLanded && b.ref) {
                            const rec = landedLetters.find(l => l.ref === b.ref);
                            if (rec) { rec.x = b.x;
                                rec.y = b.y; }
                        }

                        if (!a.isLanded && !b.isLanded) {
                            const relVx = a.vx - b.vx;
                            const relVy = a.vy - b.vy;
                            const relVn = relVx * nx + relVy * ny;
                            if (relVn < 0) {
                                const impulse = relVn * CONFIG.letterBounce;
                                a.vx -= impulse * nx;
                                a.vy -= impulse * ny;
                                b.vx += impulse * nx;
                                b.vy += impulse * ny;
                            }
                        } else if (!a.isLanded && b.isLanded) {
                            const relVx = a.vx;
                            const relVy = a.vy;
                            const relVn = relVx * nx + relVy * ny;
                            if (relVn < 0) {
                                a.vx -= 2 * relVn * nx * CONFIG.letterBounce * 0.6;
                                a.vy -= 2 * relVn * ny * CONFIG.letterBounce * 0.6;
                            }
                        } else if (a.isLanded && !b.isLanded) {
                            const relVx = b.vx;
                            const relVy = b.vy;
                            const relVn = relVx * nx + relVy * ny;
                            if (relVn > 0) {
                                b.vx -= 2 * relVn * nx * CONFIG.letterBounce * 0.6;
                                b.vy -= 2 * relVn * ny * CONFIG.letterBounce * 0.6;
                            }
                        }
                    }
                }
            }
        }

        function updatePhysics(obj) {
            const steps = CONFIG.subSteps;
            const dt = 1 / steps;

            for (let step = 0; step < steps; step++) {
                obj.vy += CONFIG.gravity * dt;
                obj.vx *= Math.pow(CONFIG.friction, dt);
                obj.vy *= Math.pow(CONFIG.friction, dt);
                obj.x += obj.vx * dt;
                obj.y += obj.vy * dt;
                obj.rotation += obj.vx * 0.025 * dt;

                const r = obj.radius;

                if (obj.x - r < 0) { obj.x = r;
                    obj.vx = -obj.vx * 0.4; }
                if (obj.x + r > W) { obj.x = W - r;
                    obj.vx = -obj.vx * 0.4; }
                if (obj.y - r < 0) { obj.y = r;
                    obj.vy = -obj.vy * 0.4; }

                for (const obs of obstacles) {
                    if (obs.type === 'circle') collideCircle(obj, obs);
                    else if (obs.type === 'ramp') collideRamp(obj, obs);
                }

                const lineY = CONFIG.lineY;
                const lineL = CONFIG.lineLeft;
                const lineR = CONFIG.lineRight;

                if (obj.x > lineL && obj.x < lineR) {
                    if (obj.y + r > lineY && obj.y + r < lineY + 12 && obj.vy > 0) {
                        obj.y = lineY - r;
                        if (Math.abs(obj.vy) < CONFIG.stickThreshold) {
                            obj.vy = 0;
                            obj.vx = 0;
                            obj.isActive = false;
                            const alreadyLanded = landedLetters.some(l => l.ref === obj);
                            if (!alreadyLanded && obj.type === 'letter') {
                                landedLetters.push({
                                    char: obj.char,
                                    x: obj.x,
                                    y: obj.y,
                                    rotation: obj.rotation || 0,
                                    radius: obj.radius,
                                    ref: obj,
                                });
                                landedLetters.sort((a, b) => a.x - b.x);
                            }
                            if (obj.type === 'enter') {
                                obj.isActive = false;
                                handleEnterLanded();
                            }
                            if (obj.type === 'backspace') {
                                obj.isActive = false;
                                handleBackspaceLanded();
                            }
                        } else {
                            obj.vy = -obj.vy * CONFIG.bounce;
                            obj.y = lineY - r;
                            obj.vx *= 0.88;
                        }
                    }
                }

                if (obj.y > H + 50) {
                    obj.isActive = false;
                    const idx = landedLetters.findIndex(l => l.ref === obj);
                    if (idx !== -1) landedLetters.splice(idx, 1);
                }
            }
        }


        function collideCircle(obj, circle) {
            const r = obj.radius;
            const dx = obj.x - circle.x,
                dy = obj.y - circle.y;
            const d = Math.sqrt(dx * dx + dy * dy);
            if (d < r + circle.radius && d > 0.001) {
                const overlap = r + circle.radius - d;
                obj.x += (dx / d) * overlap;
                obj.y += (dy / d) * overlap;
                const nx = dx / d,
                    ny = dy / d;
                const dot = obj.vx * nx + obj.vy * ny;
                if (dot < 0) {
                    obj.vx -= 2 * dot * nx * 0.45;
                    obj.vy -= 2 * dot * ny * 0.45;
                }
            }
        }

        function collideRamp(obj, ramp) {
            const r = obj.radius;
            const cx = ramp.x + ramp.w / 2,
                cy = ramp.y + ramp.h / 2;
            const halfW = ramp.w / 2,
                halfH = ramp.h / 2;
            const angle = ramp.angle || 0;
            const cosA = Math.cos(angle),
                sinA = Math.sin(angle);

            const corners = [
                { x: -halfW, y: -halfH }, { x: halfW, y: -halfH },
                { x: halfW, y: halfH }, { x: -halfW, y: halfH }
            ];
            const worldCorners = corners.map(c => ({
                x: cx + c.x * cosA - c.y * sinA,
                y: cy + c.x * sinA + c.y * cosA,
            }));

            let minDist = Infinity;
            let bestEdge = null;
            for (let i = 0; i < 4; i++) {
                const j = (i + 1) % 4;
                const a = worldCorners[i],
                    b = worldCorners[j];
                const result = pointToSegmentDist(obj.x, obj.y, a.x, a.y, b.x, b.y);
                if (result.dist < minDist) {
                    minDist = result.dist;
                    bestEdge = result;
                }
            }

            if (bestEdge && minDist < r) {
                const overlap = r - minDist;
                const nx = bestEdge.nx / (bestEdge.dist || 1);
                const ny = bestEdge.ny / (bestEdge.dist || 1);
                obj.x += nx * overlap;
                obj.y += ny * overlap;
                const dot = obj.vx * nx + obj.vy * ny;
                if (dot < 0) {
                    obj.vx -= 2 * dot * nx * 0.45;
                    obj.vy -= 2 * dot * ny * 0.45;
                    obj.vx += (Math.random() - 0.5) * 0.2;
                }
            }
        }

   
        function handleEnterLanded() {
            if (landedLetters.length === 0) return;

            if (landedLetters.length > CONFIG.maxLetters) {
                validationMessage = ' 超过5个字符,不能提交';
                validationMessageTimer = Date.now();
                console.log('超过5个字符');
                return;
            }

            const text = landedLetters.map(l => l.char).join('');
            const result = validateDomain(text);

            if (result.valid) {
                console.log(' 提交: ' + text);
                alert(' 提交: "' + text + '" ');
                clearAll();
                validationMessage = '';
            } else {
                validationMessage = result.msg;
                validationMessageTimer = Date.now();
                console.log(' ' + result.msg);
             
            }
        }

        function handleBackspaceLanded() {
            if (landedLetters.length === 0) return;
            console.log(' 清空');
            clearAll();
            validationMessage = '';
        }

        function clearAll() {
            for (const l of letters) { l.isActive = false; }
            letters = [];
            for (const icon of activeIcons) { icon.isActive = false; }
            activeIcons = [];
            for (const l of landedLetters) {
                if (l.ref) l.ref.isActive = false;
            }
            landedLetters = [];
        }

       
        function fireLetter(char) {
            const obj = {
                type: 'letter',
                char: char,
                x: cursorX,
                y: CONFIG.cursorY + 10,
                vx: (Math.random() - 0.5) * 1.8,
                vy: -2.5 - Math.random() * 1.2,
                radius: 16,
                rotation: (Math.random() - 0.5) * 0.3,
                isActive: true,
            };
            letters.push(obj);
        }

        function fireEnterIcon() {
            const obj = {
                type: 'enter',
                x: cursorX,
                y: CONFIG.cursorY + 10,
                vx: (Math.random() - 0.5) * 0.6,
                vy: -2.0,
                radius: 18,
                rotation: (Math.random() - 0.5) * 0.2,
                isActive: true,
            };
            activeIcons.push(obj);
        }

        function fireBackspaceIcon() {
            const obj = {
                type: 'backspace',
                x: cursorX,
                y: CONFIG.cursorY + 10,
                vx: (Math.random() - 0.5) * 0.6,
                vy: -2.0,
                radius: 18,
                rotation: (Math.random() - 0.5) * 0.2,
                isActive: true,
            };
            activeIcons.push(obj);
        }

     
        function draw() {
            ctx.fillStyle = COLORS.bg;
            ctx.fillRect(0, 0, W, H);

           
            ctx.strokeStyle = 'rgba(51, 204, 102, 0.025)';
            ctx.lineWidth = 1;
            for (let x = 0; x < W; x += 30) {
                ctx.beginPath();
                ctx.moveTo(x, 0);
                ctx.lineTo(x, H);
                ctx.stroke();
            }
            for (let y = 0; y < H; y += 30) {
                ctx.beginPath();
                ctx.moveTo(0, y);
                ctx.lineTo(W, y);
                ctx.stroke();
            }

        
            for (const obs of obstacles) {
                ctx.save();
                if (obs.type === 'circle') {
                    ctx.fillStyle = COLORS.obstacle;
                    ctx.strokeStyle = COLORS.obstacleBorder;
                    ctx.lineWidth = 1.5;
                    ctx.beginPath();
                    ctx.arc(obs.x, obs.y, obs.radius, 0, Math.PI * 2);
                    ctx.fill();
                    ctx.stroke();
                } else if (obs.type === 'ramp') {
                    ctx.save();
                    ctx.translate(obs.x + obs.w / 2, obs.y + obs.h / 2);
                    ctx.rotate(obs.angle || 0);
                    ctx.fillStyle = COLORS.obstacle;
                    ctx.strokeStyle = COLORS.obstacleBorder;
                    ctx.lineWidth = 1.5;
                    ctx.fillRect(-obs.w / 2, -obs.h / 2, obs.w, obs.h);
                    ctx.strokeRect(-obs.w / 2, -obs.h / 2, obs.w, obs.h);
                    ctx.fillStyle = 'rgba(51,204,102,0.03)';
                    ctx.fillRect(-obs.w / 2 + 6, -obs.h / 2 + 2, obs.w - 12, 2);
                    ctx.restore();
                }
                ctx.restore();
            }

         
            const lineY = CONFIG.lineY;
            const lineL = CONFIG.lineLeft;
            const lineR = CONFIG.lineRight;

            const grad = ctx.createLinearGradient(0, lineY - 10, 0, lineY + 10);
            grad.addColorStop(0, 'rgba(51,204,102,0)');
            grad.addColorStop(0.4, 'rgba(51,204,102,0.04)');
            grad.addColorStop(0.6, 'rgba(51,204,102,0.04)');
            grad.addColorStop(1, 'rgba(51,204,102,0)');
            ctx.fillStyle = grad;
            ctx.fillRect(lineL, lineY - 10, lineR - lineL, 20);

            ctx.shadowColor = 'rgba(51,204,102,0.08)';
            ctx.shadowBlur = 12;
            ctx.strokeStyle = COLORS.line;
            ctx.lineWidth = 2;
            ctx.beginPath();
            ctx.moveTo(lineL, lineY);
            ctx.lineTo(lineR, lineY);
            ctx.stroke();
            ctx.shadowBlur = 0;

         
            for (const l of landedLetters) {
                ctx.save();
                ctx.translate(l.x, l.y);
                ctx.rotate(l.rotation || 0);
                ctx.shadowColor = 'rgba(51,204,102,0.12)';
                ctx.shadowBlur = 12;
                ctx.fillStyle = COLORS.textBright;
                ctx.font = '22px "VT323", "Courier New", monospace';
                ctx.textAlign = 'center';
                ctx.textBaseline = 'middle';
                ctx.fillText(l.char, 0, 1);
                ctx.restore();
            }

        
            for (const l of letters) {
                if (!l.isActive) continue;
                ctx.save();
                ctx.translate(l.x, l.y);
                ctx.rotate(l.rotation || 0);
                ctx.shadowColor = 'rgba(51,204,102,0.08)';
                ctx.shadowBlur = 10;
                ctx.fillStyle = COLORS.text;
                ctx.font = 'bold 22px "VT323", "Courier New", monospace';
                ctx.textAlign = 'center';
                ctx.textBaseline = 'middle';
                ctx.fillText(l.char, 0, 1);
                ctx.restore();
            }

            for (const icon of activeIcons) {
                if (!icon.isActive) continue;
                ctx.save();
                ctx.translate(icon.x, icon.y);
                ctx.rotate(icon.rotation || 0);
                const col = icon.type === 'enter' ? COLORS.enterColor : COLORS.backspaceColor;
                ctx.shadowColor = icon.type === 'enter' ? 'rgba(102,255,153,0.1)' : 'rgba(255,136,68,0.1)';
                ctx.shadowBlur = 14;
                ctx.fillStyle = col;
                ctx.font = '26px "VT323", "Courier New", monospace';
                ctx.textAlign = 'center';
                ctx.textBaseline = 'middle';
                ctx.fillText(icon.type === 'enter' ? '↵' : '⌫', 0, 1);
                ctx.restore();
            }

      
            if (cursorVisible) {
                ctx.save();
                ctx.fillStyle = COLORS.cursor;
                ctx.shadowColor = 'rgba(51,204,102,0.2)';
                ctx.shadowBlur = 10;
                ctx.font = '28px "VT323", "Courier New", monospace';
                ctx.textAlign = 'center';
                ctx.textBaseline = 'middle';
                ctx.fillText('_', cursorX, CONFIG.cursorY + 2);
                ctx.restore();
            }

      
            const count = landedLetters.length;
            const isOver = count > CONFIG.maxLetters;
            ctx.fillStyle = isOver ? COLORS.textWarn : COLORS.textDim;
            ctx.font = '14px "VT323", "Courier New", monospace';
            ctx.textAlign = 'left';
            ctx.textBaseline = 'top';
            ctx.fillText(`[${count}/${CONFIG.maxLetters}]${isOver ? ' 输入超限' : ''}`, 16, 14);

            if (count > 0) {
                const orderText = landedLetters.map(l => l.char).join(' ');
                ctx.fillStyle = COLORS.textDim;
                ctx.textAlign = 'center';
                ctx.textBaseline = 'top';
                ctx.fillText(orderText, W / 2, 14);
            }

            
            if (validationMessage) {
                const isError = validationMessage.startsWith('❌');
                ctx.fillStyle = isError ? COLORS.textError : COLORS.textBright;
                ctx.font = '16px "VT323", "Courier New", monospace';
                ctx.textAlign = 'center';
                ctx.textBaseline = 'bottom';
                ctx.fillText(validationMessage, W / 2, CONFIG.lineY - 16);
            }

            ctx.textAlign = 'right';
            ctx.textBaseline = 'bottom';
            ctx.fillStyle = COLORS.textDim;
            ctx.fillText('A-Z  0-9  -  ↵  ⌫', W - 16, H - 12);
        }

 
        function gameLoop(timestamp) {
            if (timestamp - cursorBlinkTimer > CONFIG.cursorBlinkSpeed) {
                cursorVisible = !cursorVisible;
                cursorBlinkTimer = timestamp;
            }

          
            if (validationMessage && timestamp - validationMessageTimer > 5000) {
                validationMessage = '';
            }

            if (keys.left) cursorX = Math.max(40, cursorX - 3.5);
            if (keys.right) cursorX = Math.min(W - 40, cursorX + 3.5);

            for (const l of letters) {
                if (l.isActive) updatePhysics(l);
            }

            for (const icon of activeIcons) {
                if (icon.isActive) updatePhysics(icon);
            }

            resolveLetterCollisions();

            letters = letters.filter(l => l.isActive);
            activeIcons = activeIcons.filter(i => i.isActive);

            draw();
            requestAnimationFrame(gameLoop);
        }

     
        document.addEventListener('keydown', (e) => {
            const key = e.key;
            if (key === 'ArrowLeft') { e.preventDefault();
                keys.left = true; return; }
            if (key === 'ArrowRight') { e.preventDefault();
                keys.right = true; return; }
            if (key === 'Enter') { e.preventDefault();
                fireEnterIcon(); return; }
            if (key === 'Backspace') { e.preventDefault();
                fireBackspaceIcon(); return; }

            const upperKey = key.toUpperCase();
            const isLetter = key.length === 1 && upperKey >= 'A' && upperKey <= 'Z';
            const isNumber = key.length === 1 && key >= '0' && key <= '9';
            const isHyphen = key === '-';

            if (isLetter || isNumber || isHyphen) {
                e.preventDefault();
                fireLetter(isHyphen ? '-' : upperKey);
            }
        });

        document.addEventListener('keyup', (e) => {
            if (e.key === 'ArrowLeft') keys.left = false;
            if (e.key === 'ArrowRight') keys.right = false;
        });

        canvas.addEventListener('click', () => canvas.focus());
        canvas.setAttribute('tabindex', '0');
        canvas.focus();


        requestAnimationFrame(gameLoop);
    </script>
</body>
</html>

我就不说明了,因为不知道可以用在哪
这个代码开源,随便用
demo地址: https://nodeloc.netlify.app
规则其实是按照域名的规则定的,也可以去掉

7
17
登录后参与讨论。

17 条回复

排序
  1. lmogaxmhiqrp 铂金 3 YEARS 4 个月前

    过来看看

    2
  2. Wbuildings 白银 4 个月前

    可以可以,来点个赞

    2
  3. user68 💬 铂金 3 YEARS 4 个月前

    这是啥,我试试开源代码!

    2
  4. user94 富可敌国 钻石 4 个月前

    我去CC0大佬

    1
  5. NoahCarter 黄金 4 个月前

    有点意思~

    0
  6. Clina 钻石 钻石会员 4 个月前

    Furry:
    这个代码开源,随便用

    啥协议?

    1
  7. user94 富可敌国 钻石 4 个月前

    随便用就CC0

    0
  8. Serendipity1 钻石 4 个月前

    好长~~~~~

    1
  9. clearlee33 青铜 4 个月前

    看看不说话

    1
  10. 1751140932 黄金 4 个月前

    可以可以

    0
  11. pizixi 白银 4 个月前

    这是啥,我试试

    0
  12. Struhaqi 黄金 4 个月前

    :ac31:

    0
  13. wszxzjd 白银 4 个月前

    看看,什么用?

    0
  14. 2965224604 白银 4 个月前

    其实我建议可以做成品的

    0
  15. Trevor_Philips 黄金 3 YEARS 4 个月前

    玩了半天, 好玩是好玩, 就是不知道能干啥 :ac01:

    0
  16. 51518 白银 4 个月前

    有点意思

    0
  17. MSaZs 黄金 4 个月前

    看看能干什么

    0