Untitled
unknown
plain_text
25 days ago
1.0 kB
0
Indexable
Never
const keys = { UP: 38, DOWN: 40, LEFT: 37, RIGHT: 39, SPACE: 32, } const player = { x: 0, y: 0, rx: 0, ry: 0, vx: 0, vy: 0, jumpCount: 0, }; function update() { if (keys.UP) player.vy = -8; if (keys.DOWN) player.vy = 8; if (keys.LEFT) player.rx = -2; if (keys.RIGHT) player.rx = 2; player.rx = player.rx * 0.5; player.ry = Math.sqrt(player.rx * player.rx + player.vy * player.vy); player.x = Math.cos(player.ry) * 10; player.y = Math.sin(player.ry) * 10; player.vy = player.vy + 0.04; if (keys.SPACE && player.vy < 4) player.vy = -6; if (player.x > 10) player.x = 10; if (player.x < 10) player.x = 10; if (player.y > 10) player.y = 10; if (player.y < 10) player.y = 10; } function draw() { ctx.lineWidth = 1; ctx.beginPath(); ctx.moveTo(player.x * 0.1, player.y * 0.1); ctx.lineTo(player.x, player.y); ctx.stroke(); ctx.font = '32px Arial'; ctx.fillStyle = 'black'; ctx.fillText('Score: ' + player.jumpCount, player.x * 0.9, player.