Liveweave: Generative AI Web Editor & HTML/CSS/JS Playground
Initializing
Liveweave
Web
expand_more
home
Home
Palette
Color Explorer
arrow_outward
Polyline
Graphics Editor
arrow_outward
frame_source
Python Playground
arrow_outward
build
Tools
expand_more
restart_alt
Load "Hello Weaver!"
post_add
Generate Lorem ipsum...
code
Format HTML
code_blocks
Format CSS
data_object
Format JavaScript
library_add
Library
expand_more
A
Algolia JS
Animate CSS
Apex Charts JS
B
Bulma CSS
Bootstrap
C
Chart JS
Chartist
Create JS
D
D3
Dojo
F
Foundation
Fullpage JS
G
Granim JS
Google Charts
H
Halfmoon
J
jQuery
M
Materialize
Moment JS
Masonry JS
Milligram CSS
P
Pure CSS
Primer CSS
Popper JS
Pattern CSS
Picnic CSS
R
React JS
Raphael JS
Raisin CSS
S
Semantic UI
Skeleton CSS
Spectre CSS
Tachyons CSS
T
Tailwind
Three JS
U
UI Kit
Vis JS
W
Water CSS
download
Download
expand_more
developer_mode
Download as HTML
folder_zip
Download as .ZIP
cloud_upload
Fork
account_circle
Login
settings
Settings
expand_more
Editor font
14
px
A
A
Night mode
Line number
Mini map
Word wrap
sync_alt
Reset Settings
smart_display
Run
left_panel_close
AI Assistant
dashboard
All
HTML
CSS
JS
visibility
Preview
bolt
Live Preview
terminal
JS Console
<!DOCTYPE html> <html> <head> <title>Turkey run game</title> </head> <body> <!-- Start your code here --> <div class="game-shell"> <header class="game-header"> <div class="game-brand"> <div class="brand-icon">π¦</div> <div> <div class="brand-title">TURKEY RUN</div> <div class="brand-subtitle">THE GREAT THANKSGIVING ESCAPE</div> </div> </div> <div class="header-tag">THANKSGIVING EDITION <span>β¦</span></div> </header> <main class="game-main"> <section class="game-stage"> <div class="hud"> <div class="hud-item"> <span class="hud-label">SCORE</span> <strong id="score">00000</strong> </div> <div class="hud-item corn-hud"> <span class="hud-label">CORN</span> <strong>π½ <span id="corn">0</span></strong> </div> <div class="hud-item best-hud"> <span class="hud-label">BEST</span> <strong id="best">00000</strong> </div> </div> <canvas id="gameCanvas" aria-label="Turkey Run game. Jump over obstacles and collect corn."></canvas> <div class="game-overlay" id="overlay"> <div class="overlay-card"> <div class="overlay-turkey" id="overlayTurkey">π¦</div> <div class="overlay-kicker" id="overlayKicker">A THANKSGIVING ADVENTURE</div> <h1 id="overlayTitle">TURKEY RUN</h1> <p id="overlayText">The farm has other plans for Thanksgiving dinner. Time to make a run for it!</p> <button class="play-button" id="playButton">LET'S ESCAPE <span>β</span></button> <div class="overlay-help">SPACE / β / TAP TO JUMP</div> </div> </div> <div class="toast" id="toast">π½ NICE CATCH!</div> </section> <footer class="game-footer"> <div class="controls-hint"> <span class="keycap">SPACE</span> <span class="keycap">β</span> <span>JUMP</span> <span class="hint-divider">Β·</span> <span>DOUBLE TAP NOT REQUIRED</span> </div> <div class="footer-message">RUN, TURKEY, RUN! <span>β₯</span></div> </footer> </main> <div class="mobile-controls"> <button id="jumpButton" aria-label="Jump">JUMP <span>β</span></button> </div> <div class="bottom-note">A LITTLE THANKSGIVING CHAOS Β· MADE FOR FUN</div> </div> <!-- End your code here --> </body> </html>
@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&family=Nunito:wght@400;600;700;800;900&display=swap'); :root { --cream: #fff5df; --orange: #e87835; --brown: #49301f; --dark: #30251e; --muted: #947d69; } * { box-sizing: border-box; } body { margin: 0; min-height: 100vh; background: radial-gradient(ellipse at 50% 0%, #fff0d4 0%, transparent 65%), #f4e4c8; color: var(--brown); font-family: 'Nunito', sans-serif; } button { font: inherit; cursor: pointer; } .game-shell { width: min(1040px, calc(100% - 32px)); margin: 26px auto; } .game-header { display: flex; justify-content: space-between; align-items: center; padding: 0 5px 20px; } .game-brand { display: flex; align-items: center; gap: 12px; } .brand-icon { width: 47px; height: 47px; display: grid; place-items: center; background: #f4a24c; border: 3px solid #fff8e9; border-radius: 15px; box-shadow: 0 4px 0 #d27b37; font-size: 27px; } .brand-title { font: 700 21px 'Fredoka', sans-serif; letter-spacing: 1.5px; } .brand-subtitle { margin-top: 2px; color: #a17c5d; font-size: 9px; font-weight: 900; letter-spacing: 1.4px; } .header-tag { padding: 9px 13px; background: #f8e7ca; border: 1px solid #ead4b2; border-radius: 30px; color: #9a6940; font-size: 9px; font-weight: 900; letter-spacing: 1px; } .header-tag span { color: #df8c3c; } .game-main { overflow: hidden; border: 7px solid #fff9ec; border-radius: 19px; background: #fff9ed; box-shadow: 0 14px 35px #74502a20, 0 3px 0 #e3cba7; } .game-stage { position: relative; width: 100%; overflow: hidden; background: #f5d8a8; } #gameCanvas { display: block; width: 100%; height: auto; aspect-ratio: 900 / 430; touch-action: manipulation; } .hud { position: absolute; z-index: 2; top: 15px; left: 16px; right: 16px; display: flex; align-items: flex-start; justify-content: space-between; pointer-events: none; } .hud-item { min-width: 82px; padding: 7px 12px 8px; border: 1px solid #ffffffa8; border-radius: 11px; background: #fff8e8dd; box-shadow: 0 3px 9px #714b2710; } .hud-label { display: block; color: #9b795a; font-size: 8px; font-weight: 900; letter-spacing: 1.5px; } .hud-item strong { display: block; margin-top: 1px; color: #573921; font: 700 17px 'Fredoka', sans-serif; } .corn-hud strong { color: #b66c24; } .best-hud { text-align: right; } .game-overlay { position: absolute; z-index: 4; inset: 0; display: grid; place-items: center; padding: 20px; background: #38291b40; transition: opacity .25s; } .game-overlay.hidden { opacity: 0; pointer-events: none; } .overlay-card { width: min(380px, 90%); padding: 23px 27px 20px; border: 3px solid #fff; border-radius: 23px; background: #fff8e9; text-align: center; box-shadow: 0 10px 30px #53371c30; animation: card-in .4s ease both; } @keyframes card-in { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } } .overlay-turkey { font-size: 45px; line-height: 1.2; margin-bottom: 5px; animation: turkey-bob 1.3s ease-in-out infinite; } @keyframes turkey-bob { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-5px) rotate(4deg); } } .overlay-kicker { color: #b47a45; font-size: 8px; font-weight: 900; letter-spacing: 2px; } .overlay-card h1 { margin: 5px 0 7px; color: #613b24; font: 700 clamp(28px, 5vw, 39px) 'Fredoka', sans-serif; letter-spacing: 1px; } .overlay-card p { max-width: 290px; margin: 0 auto 17px; color: #8e745c; font-size: 12px; line-height: 1.55; font-weight: 700; } .play-button { width: 100%; padding: 13px 16px; border: 0; border-radius: 11px; background: #e87835; color: white; font: 700 13px 'Fredoka', sans-serif; letter-spacing: 1px; box-shadow: 0 4px 0 #b95324; transition: transform .15s, background .15s; } .play-button:hover { background: #f18a42; transform: translateY(-2px); } .play-button:active { transform: translateY(2px); box-shadow: 0 1px 0 #b95324; } .play-button span { margin-left: 9px; } .overlay-help { margin-top: 14px; color: #b69b7b; font-size: 8px; font-weight: 900; letter-spacing: 1.4px; } .game-footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 13px 18px; background: #fff9ed; } .controls-hint { display: flex; align-items: center; gap: 7px; color: #a58b70; font-size: 9px; font-weight: 900; letter-spacing: .7px; } .keycap { min-width: 25px; padding: 4px 6px; border: 1px solid #e6d4b8; border-radius: 5px; background: #f8eddb; color: #76583c; text-align: center; font-size: 9px; box-shadow: 0 2px 0 #e5d2b5; } .hint-divider { color: #d2b58e; } .footer-message { color: #a47a52; font: 700 10px 'Fredoka', sans-serif; letter-spacing: 1px; } .footer-message span { color: #e87835; } .mobile-controls { display: none; justify-content: center; margin-top: 14px; } .mobile-controls button { width: 100%; padding: 15px; border: 0; border-radius: 12px; background: #e87835; color: white; font: 700 15px 'Fredoka', sans-serif; letter-spacing: 2px; box-shadow: 0 4px 0 #b95324; touch-action: manipulation; } .mobile-controls button span { margin-left: 8px; font-size: 20px; } .mobile-controls button:active { transform: translateY(3px); box-shadow: 0 1px 0 #b95324; } .bottom-note { padding: 18px 0; color: #ad9070; text-align: center; font-size: 8px; font-weight: 900; letter-spacing: 2px; } .toast { position: absolute; z-index: 3; top: 76px; left: 50%; padding: 8px 15px; border-radius: 30px; background: #fff8e8; color: #a96c2d; font: 700 11px 'Fredoka', sans-serif; letter-spacing: .8px; opacity: 0; transform: translate(-50%, -8px); pointer-events: none; transition: .2s; } .toast.show { opacity: 1; transform: translate(-50%, 0); } @media (max-width: 600px) { .game-shell { width: calc(100% - 16px); margin: 12px auto; } .game-header { padding: 0 3px 14px; } .brand-icon { width: 40px; height: 40px; font-size: 23px; } .brand-title { font-size: 17px; } .brand-subtitle { font-size: 7px; } .header-tag { padding: 7px 9px; font-size: 7px; } .game-main { border-width: 4px; border-radius: 14px; } .hud { top: 9px; left: 9px; right: 9px; } .hud-item { min-width: 65px; padding: 5px 8px; border-radius: 8px; } .hud-label { font-size: 7px; } .hud-item strong { font-size: 14px; } .overlay-card { padding: 14px 17px; } .overlay-turkey { font-size: 32px; } .overlay-card p { font-size: 10px; margin-bottom: 11px; } .overlay-help { margin-top: 10px; } .game-footer { padding: 10px 8px; } .controls-hint { gap: 5px; font-size: 7px; } .keycap { min-width: 21px; padding: 3px 5px; } .footer-message { font-size: 8px; } .mobile-controls { display: flex; } .bottom-note { font-size: 7px; } }
(() => { const canvas = document.getElementById('gameCanvas'); const ctx = canvas.getContext('2d'); const $ = id => document.getElementById(id); const W = 900; const H = 430; const GROUND = 350; let state = 'ready'; let lastTime = 0; let elapsed = 0; let score = 0; let cornCount = 0; let best = 0; let speed = 320; let obstacleTimer = 1.2; let cornTimer = 1.8; let toastTimer = 0; let shake = 0; const player = { x: 135, y: GROUND, vy: 0, jumping: false, runTime: 0, rotation: 0 }; let obstacles = []; let cornItems = []; let leaves = []; let clouds = []; try { best = Number(localStorage.getItem('turkeyRunBest')) || 0; } catch (e) {} $('best').textContent = String(best).padStart(5, '0'); function resizeCanvas() { const dpr = Math.min(window.devicePixelRatio || 1, 2); canvas.width = W * dpr; canvas.height = H * dpr; ctx.setTransform(dpr, 0, 0, dpr, 0, 0); } window.addEventListener('resize', resizeCanvas); resizeCanvas(); // Background elements function initEnvironment() { clouds = [ { x: 120, y: 85, scale: 1 }, { x: 470, y: 120, scale: .7 }, { x: 760, y: 68, scale: .85 } ]; leaves = Array.from({ length: 22 }, () => ({ x: Math.random() * W, y: Math.random() * GROUND, size: 3 + Math.random() * 5, speed: 12 + Math.random() * 28, drift: Math.random() * 2 - 1, phase: Math.random() * 6.28, color: ['#d77c32', '#e8a144', '#b85b30', '#d7a34b'][Math.floor(Math.random() * 4)] })); } function drawCloud(x, y, s) { ctx.save(); ctx.translate(x, y); ctx.scale(s, s); ctx.fillStyle = '#fff0d1'; ctx.beginPath(); ctx.arc(0, 0, 19, 0, Math.PI * 2); ctx.arc(22, -9, 25, 0, Math.PI * 2); ctx.arc(48, 1, 18, 0, Math.PI * 2); ctx.rect(-2, 0, 52, 18); ctx.fill(); ctx.restore(); } function drawBackground(dt) { // Sky const sky = ctx.createLinearGradient(0, 0, 0, H); sky.addColorStop(0, '#e9ad6c'); sky.addColorStop(.56, '#f5d5a0'); sky.addColorStop(1, '#f7dfa9'); ctx.fillStyle = sky; ctx.fillRect(0, 0, W, H); // Sun ctx.fillStyle = '#ffe7a5'; ctx.beginPath(); ctx.arc(720, 105, 43, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = '#ffedbd55'; ctx.beginPath(); ctx.arc(720, 105, 57, 0, Math.PI * 2); ctx.fill(); // Clouds clouds.forEach(cloud => { if (state === 'playing') { cloud.x -= speed * dt * .055; if (cloud.x < -90) cloud.x = W + 70; } drawCloud(cloud.x, cloud.y, cloud.scale); }); // Distant hills ctx.fillStyle = '#c6a36c'; ctx.beginPath(); ctx.moveTo(0, 268); ctx.quadraticCurveTo(140, 170, 310, 257); ctx.quadraticCurveTo(470, 185, 620, 254); ctx.quadraticCurveTo(790, 175, 900, 248); ctx.lineTo(900, GROUND); ctx.lineTo(0, GROUND); ctx.fill(); ctx.fillStyle = '#a9a06b'; ctx.beginPath(); ctx.moveTo(0, 298); ctx.quadraticCurveTo(190, 230, 380, 290); ctx.quadraticCurveTo(620, 225, 900, 291); ctx.lineTo(900, GROUND); ctx.lineTo(0, GROUND); ctx.fill(); // Trees drawTree(45, 288, 1.05, '#a75c36'); drawTree(250, 297, .72, '#bc6d37'); drawTree(640, 286, .92, '#9d6239'); drawTree(845, 295, 1.15, '#b85c30'); // Barn drawBarn(520, 260); // Ground ctx.fillStyle = '#7c934f'; ctx.fillRect(0, GROUND, W, H - GROUND); ctx.fillStyle = '#a6a45e'; ctx.fillRect(0, GROUND, W, 7); // Ground texture ctx.strokeStyle = '#657e44'; ctx.lineWidth = 2; for (let i = 0; i < 34; i++) { const x = (i * 73 - (elapsed * speed * .35) % 73 + W) % W; ctx.beginPath(); ctx.moveTo(x, GROUND + 17 + (i % 4) * 12); ctx.lineTo(x + 9, GROUND + 14 + (i % 4) * 12); ctx.stroke(); } // Scrolling autumn leaves leaves.forEach(leaf => { if (state === 'playing') { leaf.x -= leaf.speed * dt; leaf.y += Math.sin(elapsed * 2 + leaf.phase) * 7 * dt; if (leaf.x < -10) { leaf.x = W + Math.random() * 100; leaf.y = Math.random() * 250; } } ctx.save(); ctx.translate(leaf.x, leaf.y); ctx.rotate(Math.sin(elapsed + leaf.phase) * .6); ctx.fillStyle = leaf.color; ctx.beginPath(); ctx.ellipse(0, 0, leaf.size, leaf.size * .55, 0, 0, Math.PI * 2); ctx.fill(); ctx.restore(); }); } function drawTree(x, y, scale, color) { ctx.save(); ctx.translate(x, y); ctx.scale(scale, scale); ctx.fillStyle = '#72503a'; ctx.fillRect(-5, -55, 10, 57); ctx.fillStyle = color; ctx.beginPath(); ctx.arc(-13, -57, 24, 0, Math.PI * 2); ctx.arc(12, -67, 28, 0, Math.PI * 2); ctx.arc(0, -88, 22, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = '#e9a14c'; ctx.beginPath(); ctx.arc(-12, -77, 10, 0, Math.PI * 2); ctx.arc(15, -55, 9, 0, Math.PI * 2); ctx.fill(); ctx.restore(); } function drawBarn(x, y) { ctx.save(); ctx.translate(x, y); ctx.fillStyle = '#a34e37'; ctx.fillRect(0, 0, 100, 73); ctx.fillStyle = '#7e3d30'; ctx.beginPath(); ctx.moveTo(-10, 4); ctx.lineTo(50, -39); ctx.lineTo(110, 4); ctx.closePath(); ctx.fill(); ctx.fillStyle = '#f2d5a3'; ctx.fillRect(35, 31, 31, 42); ctx.strokeStyle = '#fff0cf'; ctx.lineWidth = 3; ctx.beginPath(); ctx.moveTo(35, 31); ctx.lineTo(66, 73); ctx.moveTo(66, 31); ctx.lineTo(35, 73); ctx.stroke(); ctx.restore(); } // Draw our hero function drawTurkey() { const running = state === 'playing' && !player.jumping; const bounce = running ? Math.sin(player.runTime * 16) * 2.8 : 0; const legSwing = running ? Math.sin(player.runTime * 16) * 8 : 0; const x = player.x; const y = player.y + bounce; ctx.save(); ctx.translate(x, y); ctx.rotate(player.rotation); // Shadow ctx.fillStyle = '#39402b40'; ctx.beginPath(); ctx.ellipse(18, 1, 32, 6, 0, 0, Math.PI * 2); ctx.fill(); // Tail feathers const featherColors = ['#b64f32', '#d77c36', '#e5aa48', '#98503b', '#d19a49']; for (let i = 0; i < 5; i++) { ctx.save(); ctx.translate(-13, -31); ctx.rotate((-0.65 + i * .32) + (running ? Math.sin(player.runTime * 12) * .04 : 0)); ctx.fillStyle = featherColors[i]; ctx.beginPath(); ctx.ellipse(-10, -20, 10, 24, 0, 0, Math.PI * 2); ctx.fill(); ctx.restore(); } // Body ctx.fillStyle = '#815039'; ctx.beginPath(); ctx.ellipse(9, -29, 27, 28, -.12, 0, Math.PI * 2); ctx.fill(); // Belly ctx.fillStyle = '#e7bd8d'; ctx.beginPath(); ctx.ellipse(18, -21, 17, 17, .2, 0, Math.PI * 2); ctx.fill(); // Wing ctx.fillStyle = '#a96b43'; ctx.beginPath(); ctx.ellipse(-1, -31, 14, 9, -.35, 0, Math.PI * 2); ctx.fill(); ctx.strokeStyle = '#e2b58b'; ctx.lineWidth = 2; ctx.beginPath(); ctx.moveTo(-10, -31); ctx.quadraticCurveTo(-1, -37, 8, -29); ctx.stroke(); // Neck ctx.fillStyle = '#815039'; ctx.beginPath(); ctx.ellipse(27, -51, 11, 18, -.12, 0, Math.PI * 2); ctx.fill(); // Head ctx.fillStyle = '#815039'; ctx.beginPath(); ctx.arc(29, -67, 15, 0, Math.PI * 2); ctx.fill(); // Eye ctx.fillStyle = '#fff7e8'; ctx.beginPath(); ctx.arc(34, -70, 5.5, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = '#30251e'; ctx.beginPath(); ctx.arc(36, -70, 2.5, 0, Math.PI * 2); ctx.fill(); // Beak ctx.fillStyle = '#e9a33f'; ctx.beginPath(); ctx.moveTo(42, -64); ctx.lineTo(57, -59); ctx.lineTo(42, -56); ctx.closePath(); ctx.fill(); // Wattle ctx.fillStyle = '#c64b39'; ctx.beginPath(); ctx.moveTo(34, -56); ctx.quadraticCurveTo(42, -50, 37, -43); ctx.quadraticCurveTo(31, -46, 34, -56); ctx.fill(); // Feet ctx.strokeStyle = '#d68b38'; ctx.lineWidth = 3.5; ctx.lineCap = 'round'; ctx.beginPath(); ctx.moveTo(3, -5); ctx.lineTo(3 + legSwing, -1); ctx.lineTo(10 + legSwing, 0); ctx.moveTo(3 + legSwing, -1); ctx.lineTo(0 + legSwing, 3); ctx.moveTo(20, -5); ctx.lineTo(20 - legSwing, -1); ctx.lineTo(27 - legSwing, 0); ctx.moveTo(20 - legSwing, -1); ctx.lineTo(17 - legSwing, 3); ctx.stroke(); // Small red comb ctx.fillStyle = '#c64b39'; ctx.beginPath(); ctx.arc(24, -82, 4, Math.PI, Math.PI * 2); ctx.fill(); ctx.restore(); } function drawPumpkin(x, y, w = 35) { ctx.save(); ctx.translate(x, y); ctx.fillStyle = '#e47d30'; ctx.beginPath(); ctx.ellipse(0, 0, w * .5, w * .35, 0, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = '#f29b40'; ctx.beginPath(); ctx.ellipse(-w * .15, 0, w * .16, w * .33, 0, 0, Math.PI * 2); ctx.ellipse(w * .15, 0, w * .16, w * .33, 0, 0, Math.PI * 2); ctx.fill(); ctx.strokeStyle = '#648044'; ctx.lineWidth = 3; ctx.beginPath(); ctx.moveTo(0, -w * .3); ctx.lineTo(2, -w * .47); ctx.stroke(); ctx.restore(); } // Obstacles function spawnObstacle() { const types = ['pumpkin', 'hay', 'fence', 'log']; const type = types[Math.floor(Math.random() * types.length)]; const obstacle = { x: W + 30, type, passed: false }; if (type === 'pumpkin') { obstacle.w = 39; obstacle.h = 28; } else if (type === 'hay') { obstacle.w = 48; obstacle.h = 36; } else if (type === 'fence') { obstacle.w = 48; obstacle.h = 51; } else { obstacle.w = 54; obstacle.h = 21; } obstacles.push(obstacle); } function drawObstacle(obstacle) { const x = obstacle.x; const y = GROUND; if (obstacle.type === 'pumpkin') { drawPumpkin(x + 19, y - 14, 39); } if (obstacle.type === 'hay') { ctx.fillStyle = '#d6a44e'; ctx.fillRect(x, y - 34, 48, 34); ctx.strokeStyle = '#a77c3e'; ctx.lineWidth = 2; ctx.strokeRect(x + 2, y - 32, 44, 30); ctx.strokeStyle = '#f1d18b'; ctx.beginPath(); ctx.moveTo(x + 7, y - 34); ctx.lineTo(x + 7, y); ctx.moveTo(x + 40, y - 34); ctx.lineTo(x + 40, y); ctx.stroke(); } if (obstacle.type === 'fence') { ctx.fillStyle = '#85583a'; ctx.fillRect(x + 5, y - 48, 8, 48); ctx.fillRect(x + 35, y - 48, 8, 48); ctx.fillRect(x, y - 42, 49, 9); ctx.fillRect(x, y - 20, 49, 8); ctx.fillStyle = '#a7764c'; ctx.fillRect(x + 7, y - 46, 3, 43); ctx.fillRect(x + 37, y - 46, 3, 43); } if (obstacle.type === 'log') { ctx.fillStyle = '#81553a'; ctx.beginPath(); ctx.roundRect(x, y - 19, 54, 19, 9); ctx.fill(); ctx.fillStyle = '#c39a6b'; ctx.beginPath(); ctx.ellipse(x + 7, y - 9, 4, 6, 0, 0, Math.PI * 2); ctx.fill(); } } function spawnCorn() { const height = 90 + Math.random() * 65; cornItems.push({ x: W + 20, y: GROUND - height, phase: Math.random() * 6.28, collected: false }); } function drawCorn(item) { const bob = Math.sin(elapsed * 5 + item.phase) * 4; ctx.save(); ctx.translate(item.x, item.y + bob); ctx.rotate(-.45); // Corn cob ctx.fillStyle = '#f4c84c'; ctx.beginPath(); ctx.ellipse(0, 0, 7, 14, 0, 0, Math.PI * 2); ctx.fill(); // Kernels ctx.fillStyle = '#ffe27b'; for (let i = -8; i <= 8; i += 5) { ctx.beginPath(); ctx.arc(-2, i, 2, 0, Math.PI * 2); ctx.arc(3, i + 2, 2, 0, Math.PI * 2); ctx.fill(); } // Leaves ctx.fillStyle = '#648d43'; ctx.beginPath(); ctx.moveTo(-4, 8); ctx.quadraticCurveTo(-17, 12, -13, 21); ctx.quadraticCurveTo(-6, 17, 0, 10); ctx.fill(); ctx.beginPath(); ctx.moveTo(4, 7); ctx.quadraticCurveTo(17, 10, 14, 20); ctx.quadraticCurveTo(5, 16, 0, 10); ctx.fill(); ctx.restore(); } function intersects(a, b) { return ( a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top ); } function showToast(message) { $('toast').textContent = message; $('toast').classList.add('show'); toastTimer = 1; } function update(dt) { elapsed += dt; speed = Math.min(650, 320 + score * .13); score += dt * speed * .035; $('score').textContent = String(Math.floor(score)).padStart(5, '0'); player.runTime += dt; // Jump physics if (player.jumping) { player.vy += 1750 * dt; player.y += player.vy * dt; if (player.y >= GROUND) { player.y = GROUND; player.vy = 0; player.jumping = false; player.rotation = 0; } else { player.rotation = Math.max(-.25, Math.min(.25, -player.vy * .0004)); } } // Spawn obstacles obstacleTimer -= dt; if (obstacleTimer <= 0) { spawnObstacle(); obstacleTimer = Math.max(0.85, 1.5 + Math.random() * 1.1 - score * .0004); } // Spawn corn cornTimer -= dt; if (cornTimer <= 0) { spawnCorn(); cornTimer = 1.8 + Math.random() * 1.7; } obstacles.forEach(obstacle => { obstacle.x -= speed * dt; }); obstacles = obstacles.filter(obstacle => obstacle.x > -100); cornItems.forEach(item => { item.x -= speed * dt; }); cornItems = cornItems.filter(item => item.x > -40 && !item.collected); // Turkey collision box const turkeyBox = { left: player.x - 13, right: player.x + 43, top: player.y - 84, bottom: player.y - 4 }; // Obstacle collision for (const obstacle of obstacles) { const obstacleBox = { left: obstacle.x + 3, right: obstacle.x + obstacle.w - 3, top: GROUND - obstacle.h + 4, bottom: GROUND }; if (intersects(turkeyBox, obstacleBox)) { endGame(); return; } } // Corn collection for (const item of cornItems) { const cornBox = { left: item.x - 12, right: item.x + 12, top: item.y - 16, bottom: item.y + 16 }; if (!item.collected && intersects(turkeyBox, cornBox)) { item.collected = true; cornCount++; score += 35; $('corn').textContent = cornCount; showToast('π½ NICE CATCH! +35'); } } if (toastTimer > 0) { toastTimer -= dt; if (toastTimer <= 0) $('toast').classList.remove('show'); } if (shake > 0) shake = Math.max(0, shake - dt * 30); } function render() { ctx.save(); if (shake > 0) { ctx.translate( (Math.random() - .5) * shake, (Math.random() - .5) * shake ); } drawBackground(0); // Corn behind obstacles cornItems.forEach(drawCorn); obstacles.forEach(drawObstacle); drawTurkey(); ctx.restore(); } function jump() { if (state === 'ready' || state === 'over') { startGame(); return; } if (state !== 'playing' || player.jumping) return; player.vy = -650; player.jumping = true; } function startGame() { state = 'playing'; score = 0; cornCount = 0; speed = 320; elapsed = 0; obstacleTimer = 1.25; cornTimer = 1.8; obstacles = []; cornItems = []; player.y = GROUND; player.vy = 0; player.jumping = false; player.rotation = 0; player.runTime = 0; $('score').textContent = '00000'; $('corn').textContent = '0'; $('overlay').classList.add('hidden'); $('toast').classList.remove('show'); } function endGame() { state = 'over'; shake = 10; const finalScore = Math.floor(score); if (finalScore > best) { best = finalScore; try { localStorage.setItem('turkeyRunBest', best); } catch (e) {} } $('best').textContent = String(best).padStart(5, '0'); $('overlayTurkey').textContent = 'π΅'; $('overlayKicker').textContent = 'OH NO! THE FARM CAUGHT UP!'; $('overlayTitle').textContent = 'GAME OVER'; $('overlayText').innerHTML = `You scored <strong>${finalScore}</strong> points and collected <strong>${cornCount}</strong> corn. ` + (finalScore >= best ? 'That was a great escape!' : 'Ready for another escape?'); $('playButton').innerHTML = 'TRY AGAIN <span>β»</span>'; $('overlay').classList.remove('hidden'); } function showStartScreen() { $('overlayTurkey').textContent = 'π¦'; $('overlayKicker').textContent = 'A THANKSGIVING ADVENTURE'; $('overlayTitle').textContent = 'TURKEY RUN'; $('overlayText').textContent = 'The farm has other plans for Thanksgiving dinner. Time to make a run for it!'; $('playButton').innerHTML = 'LET\'S ESCAPE <span>β</span>'; $('overlay').classList.remove('hidden'); } // Keyboard controls window.addEventListener('keydown', event => { if (event.code === 'Space' || event.code === 'ArrowUp' || event.code === 'KeyW') { event.preventDefault(); if (!event.repeat) jump(); } }); // Mobile controls $('jumpButton').addEventListener('pointerdown', event => { event.preventDefault(); jump(); }); // Tap the game itself to jump canvas.addEventListener('pointerdown', () => { jump(); }); $('playButton').addEventListener('click', startGame); // Main loop function loop(timestamp) { const dt = Math.min((timestamp - lastTime) / 1000 || 0, 0.035); lastTime = timestamp; if (state === 'playing') { update(dt); } else { elapsed += dt * .3; } render(); requestAnimationFrame(loop); } initEnvironment(); showStartScreen(); requestAnimationFrame(loop); })();
terminal
JavaScript Console
Preview
Clear
close
βΊ
Run