1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

自分で作った謎コードを配布したい。

1
Posted at

えっとね、俺が作ったコードは最後に貼るね。
すみません、初心者なのでエラーがたまに出ます。⚠️ 動作環境(物理)についての注意1フレームにつき1000枚の画像をゴリゴリに描写するため、マシンスペックが試されます。優秀なGPUを積んだ「つよつよPC・スマホ」での実行を推奨します。並のスペックの端末だと、高確率でブラウザごと消し飛びます(笑)。

主な機能と「カオス」な特徴

このアプリは、ただ動くだけのゲームから**「七色のデジタルアート(お絵描き)ツール」**へと究極の進化を遂げたカオス作品です。

  • 1000枚の限界突破(超回転モード):1%の壁抜け確率を100%にハック!キャラクター画像が1000枚重ねて超高速回転し、エネルギー球体のような激しい残像を生み出します。
  • 常時噴出する七色の粒子(パーティクル):立ち止まっていても、キャラクターの中心から完全ランダムなカラーの光の粒子が湧き水のように溢れ出続けます。
  • ファイルアプリ連携:インターネット上にアップロードすることなく、スマホやPCのローカルにある「お気に入りの画像」をそのまま読み込ませて動かせます。
  • メモリ負荷への自己責任仕様:粒子が画面上にずっと残り続ける(消えない)ため、放置するとデータが無限に蓄積され、デバイスがバカ重くなるスリルを味わえます。

🛠 遊び方・使い方

以下の手順で、ブラウザさえあれば今すぐ誰でも無料で遊べます!

1. コードを実行する

  1. オンラインテストサイト JSFiddle にアクセスします。
  2. 画面の 「JavaScript」 エリアに、下にあるコードを丸ごと貼り付けます。
  3. 画面左上にある 「Run(実行)」ボタン(再生マークのアイコン)を押します。

2. お気に入りの画像を読み込む

  1. 画面上部に出現した 「ファイルを選択」ボタン を押します。
  2. 自分のスマホやPCのフォルダ(ファイルアプリ)から、動かしたいお気に入りの画像を選びます。

3. 操作方法

※動かす前に、一度白いゲーム画面(Result画面)をタップして選択した状態にしてください。

  • 【移動】:キーボードの 矢印キー(↑ ↓ ← →) または W, A, S, D キー で自由に動かせます。壁(画面の端)を突き抜けてワープも可能です。
  • 【筆の切り替え(Pキー)】「P」ボタン を押すと、溢れ出る粒子を「丸(●)」と「スタイリッシュな横線(━)」で交互に切り替えることができます。
  • 【お掃除(Cキー)】:画面が粒子で埋め尽くされたり、デバイスが重くなってきたら、「C」ボタン を押すと一瞬で全ての粒子が全消去(リセット)されます。

↓コード↓

死ぬほどカオスな謎ゲーム.js
qconst NOCLIP_CHANCE = 100; 

const fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = 'image/*'; 
fileInput.style.marginBottom = '10px';
fileInput.style.display = 'block';
document.body.appendChild(fileInput);

const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = 600;
canvas.height = 400;
canvas.style.backgroundColor = 'white'; 
canvas.style.border = '1px solid #ccc'; 
document.body.appendChild(canvas);

const playerImg = new Image();
const player = {
    x: 275,
    y: 175,
    width: 50,
    height: 50,
    speed: 5,
    angle: 0 
};

let particles = [];
let particleType = 'circle';

fileInput.addEventListener('change', (e) => {
    const file = e.target.files;
    if (file) {
        const reader = new FileReader();
        reader.onload = (event) => { playerImg.src = event.target.result; };
        reader.readAsDataURL(file);
    }
});

playerImg.onload = function() {
    const baseSize = 50;
    if (playerImg.width > playerImg.height) {
        player.width = baseSize;
        player.height = baseSize * (playerImg.height / playerImg.width);
    } else {
        player.height = baseSize;
        player.width = baseSize * (playerImg.width / playerImg.height);
    }
};

const keys = {};
window.addEventListener('keydown', (e) => {
    const pressedKey = e.key.toLowerCase();
    
    if (pressedKey === 'c') {
        particles = []; 
    }
    
    if (pressedKey === 'p') {
        if (particleType === 'circle') {
            particleType = 'line';
        } else {
            particleType = 'circle';
        }
    }
    
    keys[pressedKey] = true;
});
window.addEventListener('keyup', (e) => keys[e.key.toLowerCase()] = false);

let isGhostMode = false;

setInterval(() => {
    const randomNumber = Math.floor(Math.random() * 100);
    if (randomNumber < NOCLIP_CHANCE) { isGhostMode = true; } else { isGhostMode = false; }
}, 1000);

function gameLoop() {
    if (keys['arrowup'] || keys['w']) { if (isGhostMode || player.y > 0) { player.y -= player.speed; } }
    if (keys['arrowdown'] || keys['s']) { if (isGhostMode || player.y < canvas.height - player.height) { player.y += player.speed; } }
    if (keys['arrowleft'] || keys['a']) { if (isGhostMode || player.x > 0) { player.x -= player.speed; } }
    if (keys['arrowright'] || keys['d']) { if (isGhostMode || player.x < canvas.width - player.width) { player.x += player.speed; } }

    if (player.x < -player.width) player.x = canvas.width;
    if (player.x > canvas.width) player.x = -player.width;
    if (player.y < -player.height) player.y = canvas.height;
    if (player.y > canvas.height) player.y = -player.height;

    ctx.clearRect(0, 0, canvas.width, canvas.height);

    const centerX = player.x + player.width / 2;
    const centerY = player.y + player.height / 2;

    if (isGhostMode) {
        for (let i = 0; i < 5; i++) { 
            const isScattering = Math.random() < 0.5;

            particles.push({
                x: centerX + (Math.random() - 0.5) * 20,
                y: centerY + (Math.random() - 0.5) * 20,
                vx: isScattering ? (Math.random() - 1) * 0 : 0,
                vy: isScattering ? (Math.random() - 1) * 0 : 0,
                size: Math.random() * 4 + 2,
                alpha: 1.0,
                color: 'hsl(' + (Math.random() * 360) + ', 100%, 60%)',
                type: particleType
            });
        }
    }

    for (let i = particles.length - 1; i >= 0; i--) {
        let p = particles[i];
        p.x += p.vx;
        p.y += p.vy;
        
        ctx.save();
        ctx.globalAlpha = p.alpha;
        ctx.strokeStyle = p.color; 
        ctx.fillStyle = p.color;   
        
        if (p.type === 'line') {
            ctx.lineWidth = p.size / 2; 
            ctx.beginPath();
            ctx.moveTo(p.x - 15, p.y); 
            ctx.lineTo(p.x + 15, p.y); 
            ctx.stroke();
        } else {
            ctx.beginPath();
            ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
            ctx.fill();
        }
        ctx.restore();
    }

    if (isGhostMode) {
        player.angle += 0.8; 

        const ghostCount = 1000; 
        for (let i = 0; i < ghostCount; i++) {
            ctx.save();
            ctx.translate(centerX, centerY);
            ctx.rotate(player.angle + (i * Math.PI / (ghostCount / 2)));
            ctx.globalAlpha = 0.015; 

            if (playerImg.src) {
                ctx.drawImage(playerImg, -player.width / 2, -player.height / 2, player.width, player.height);
            } else {
                ctx.fillStyle = '#888';
                ctx.fillRect(-player.width / 2, -player.height / 2, player.width, player.height);
            }
            ctx.restore();
        }
    } else {
        ctx.save();
        ctx.translate(centerX, centerY);
        ctx.globalAlpha = 1.0;
        if (playerImg.src) {
            ctx.drawImage(playerImg, -player.width / 2, -player.height / 2, player.width, player.height);
        } else {
            ctx.fillStyle = '#888';
            ctx.fillRect(-player.width / 2, -player.height / 2, player.width, player.height);
        }
        ctx.restore();
    }
    
    requestAnimationFrame(gameLoop);
}

gameLoop();
1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?