Untitled
unknown
plain_text
23 days ago
1.4 kB
2
Indexable
const canvas = document.createElement("canvas"); const ctx = canvas.getContext("2d"); document.body.appendChild(canvas); canvas.width = 600; canvas.height = 400; type Spider = { x: number; y: number; speed: number; }; const spider: Spider = { x: 300, y: 200, speed: 3 }; const wisdom = [ "Life is a web, and we are all connected.", "The key to existence is patience, little spider.", "Even the smallest thread can change fate.", "Sometimes, the best path is to simply observe.", "Hunger, fear, survival… is that all there is?" ]; let message = "Find the wisdom of life..."; document.addEventListener("keydown", (event) => { if (event.key === "ArrowRight") spider.x += spider.speed; if (event.key === "ArrowLeft") spider.x -= spider.speed; if (event.key === "ArrowUp") spider.y -= spider.speed; if (event.key === "ArrowDown") spider.y += spider.speed; if (Math.random() < 0.2) { message = wisdom[Math.floor(Math.random() * wisdom.length)]; } }); function draw() { ctx.fillStyle = "#000"; ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.fillStyle = "#fff"; ctx.font = "16px Arial"; ctx.fillText("🕷️", spider.x, spider.y); ctx.fillText(message, 20, 380); } function gameLoop() { draw(); requestAnimationFrame(gameLoop); } gameLoop();
Editor is loading...
Leave a Comment