Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files1 unmodified line234567856710891011121314151617181920212223242526272829301314153132333435363738394041424317444546474820495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164303116516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522633227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265363738394041424344454647482662672685051522692702712722732742752765455565758596061622772782792802812826465662832842852862872882892902912926970712932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244257677784264277980818242884858687888990919293949596979899100429430431432433434435436437438439440104105106107108109110111112113114441442443444445446447448449450451452453454455116117118456457458459460461462463464465120121122466467468469470471472473124125126474475476477478479480481130131132482483484485486487488489490491492136137138139140141142143493494495496497498499500501502503504145146147505506507508509150151152153154155156510511512513160161162163164165514515516517167168169170171172173174175176177178179180181518519520521522523524525526527528529530531532533534535536537538539540541184185186542543544545546547548549550551552188189190191192193194195196197198199200201202203204205206207208209553554555556557558559560561562563564565566567568569570571572573574213575576577578579580581582583584585586587588589590591592593594595596597598216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251599600601602603604605606607608609610611612613614615616617618619620621622623624625253254255256257626627628629630631632633634635636637261262638639640641642643644645646264265266267268647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703272273274275276704705706707708709710711281282283284712713714715716717718289290291719720721722723724295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330725726727728729730731732733734333334335336337338339340341735736737738739343740741346347348349350351742743744745746747353354748749750751752753754755356756757758759760761359360361362363762763764765766767768769770771772773774775776366367368369370371372373374375376377378777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813380381382814815816817818819820821822823824384385386387388389390391392393394395396397398399825401402826827828404405406407829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901409410411412413414902903904905417418419420421422423424425426906907908909910911912913428429430431432433434435436437438914915916917918919920921922923924925926927928929930931932933934935936937938441442939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968447448449450969970971972973974975976977452453454455978979980981982459460461462463464465466467468469470983984985986987988989990991992993994995996997998472473474475476477478479999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102448448510251026102710281029103010311032103310341035103610371038103948748848910401041104210431044104510464914924934944954964974984995005015025035045055065075085095105115125135145155161047104810491050518519520521522523524525526527528529530531532533534535536537538539540541542543105110521053105410551056105710581059106010615465475485495501062106310641065106610671068106910701071107210731074107510761077107810791080108110825545555565575585595605615625635645655665675685695705715725735745751083108457857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463510851086108710881089109010911092637638639640641109310946446456466476486496506516526536546556566576586596606616626636641095109610971098109911001101110211031104668669670671672673110511061107110811091110111111121113111467567667767867911151116111711181119681682683684685686687688112011211122112311241125112669169269311271128112911301131695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785113211331134113511367881137113811391140114111421143114479179279379479579679779879980080180280380480580680780880981081181281381481581681781881911451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176821117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862121612171218121912201221122286486586686786886987087187287387487587687787887988088112231224122512261227122812291230123112321233123412351236123712381239124012411242124388588688788888989089189289389489589689712441245124612471248124912501251125212539009019021254125512561257125812591260905906907126112621263909910126412651266126712681269915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964127012711272127312741275127612771278127912809679689699709719729731281128212831284128512861287976977978979980981982983984985986987988989990991992993994995996997998999100010011002128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221 unmodified line<html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <title>₿itcoin Dino Run</title> <script src="https://cdn.tailwindcss.com"></script> <link href="https://fonts.googleapis.com/css2?family=Fredoka+One&family=VT323&display=swap" rel="stylesheet"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <title>Dino Run - Bitcoin Edition</title> <style> body { @import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Exo+2:wght@300;400;600;700&display=swap');
* { margin: 0; padding: 0; box-sizing: border-box; }
:root { --primary: #F7931A; --primary-dark: #E88A0C; --secondary: #4CAF50; --accent: #00E5FF; --dark: #1a1a2e; --light: #ffffff; --glass: rgba(255, 255, 255, 0.1); --glass-border: rgba(255, 255, 255, 0.2); }
body { font-family: 'Exo 2', sans-serif; background: var(--dark); overflow: hidden; background-color: #1a202c; font-family: 'Fredoka One', cursive; touch-action: none; /* Prevent pull-to-refresh on mobile */ touch-action: none; user-select: none; }
#gameContainer { position: relative; width: 100vw; height: 100vh; display: flex; justify-content: center; align-items: center; background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%); } canvas {
#gameCanvas { display: block; background: transparent; } .ui-layer {
.ui-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 10; }
.screen { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; background: rgba(26, 26, 46, 0.95); backdrop-filter: blur(10px); transition: opacity 0.5s ease, transform 0.5s ease; pointer-events: auto; }
.screen.hidden { opacity: 0; transform: scale(1.1); pointer-events: none; }
.title { font-family: 'Orbitron', monospace; font-size: clamp(2rem, 8vw, 5rem); font-weight: 900; background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 50%, var(--secondary) 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; text-shadow: 0 0 60px rgba(247, 147, 26, 0.5); margin-bottom: 1rem; animation: titleGlow 2s ease-in-out infinite; }
@keyframes titleGlow { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.3); } }
.subtitle { font-size: clamp(1rem, 3vw, 1.5rem); color: rgba(255, 255, 255, 0.7); margin-bottom: 3rem; letter-spacing: 0.3em; text-transform: uppercase; }
.btn { font-family: 'Orbitron', monospace; font-size: clamp(1rem, 2.5vw, 1.3rem); font-weight: 700; padding: 1rem 3rem; border: 2px solid var(--primary); background: transparent; color: var(--primary); cursor: pointer; position: relative; overflow: hidden; transition: all 0.3s ease; text-transform: uppercase; letter-spacing: 0.1em; margin: 0.5rem; }
.btn::before { content: ''; position: absolute; top: 0; left: -100%; width: 100%; height: 100%; background: linear-gradient(90deg, transparent, var(--primary), transparent); transition: left 0.5s ease; }
.btn:hover::before { left: 100%; }
.btn:hover { background: var(--primary); color: var(--dark); box-shadow: 0 0 30px rgba(247, 147, 26, 0.5); transform: scale(1.05); }
.btn-secondary { border-color: var(--accent); color: var(--accent); }
.btn-secondary:hover { background: var(--accent); box-shadow: 0 0 30px rgba(0, 229, 255, 0.5); }
.hud { position: absolute; top: 0; left: 0; width: 100%; padding: 1rem 2rem; display: flex; justify-content: space-between; padding: 20px; box-sizing: border-box; align-items: flex-start; pointer-events: none; }
.hud-left, .hud-right { display: flex; flex-direction: column; gap: 0.5rem; }
.hud-item { background: var(--glass); border: 1px solid var(--glass-border); padding: 0.5rem 1rem; border-radius: 8px; backdrop-filter: blur(5px); }
.hud-label { font-size: 0.7rem; color: rgba(255, 255, 255, 0.6); text-transform: uppercase; letter-spacing: 0.1em; }
.hud-value { font-family: 'Orbitron', monospace; font-size: 1.2rem; font-weight: 700; color: var(--light); }
.hud-value.btc { color: var(--primary); }
.hud-value.speed { color: var(--accent); }
.hud-center { position: absolute; top: 1rem; left: 50%; transform: translateX(-50%); display: flex; gap: 1rem; }
.powerup-indicator { width: 50px; height: 50px; border-radius: 50%; display: flex; justify-content: center; align-items: center; font-size: 1.5rem; opacity: 0.3; transition: all 0.3s ease; background: var(--glass); border: 2px solid var(--glass-border); } .interactive {
.powerup-indicator.active { opacity: 1; animation: pulse 1s ease-in-out infinite; }
.powerup-indicator.magnet { border-color: var(--accent); color: var(--accent); } .powerup-indicator.shield { border-color: #E91E63; color: #E91E63; } .powerup-indicator.multiplier { border-color: var(--primary); color: var(--primary); } .powerup-indicator.speed { border-color: var(--secondary); color: var(--secondary); }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }
.pause-btn { position: absolute; top: 1rem; right: 1rem; width: 50px; height: 50px; border-radius: 50%; background: var(--glass); border: 2px solid var(--glass-border); color: white; font-size: 1.5rem; cursor: pointer; pointer-events: auto; transition: all 0.3s ease; display: flex; justify-content: center; align-items: center; }
.pause-btn:hover { background: var(--primary); border-color: var(--primary); } .hidden { display: none !important; } /* Retro Scanline Effect */ .scanlines { background: linear-gradient( to bottom, rgba(255,255,255,0), rgba(255,255,255,0) 50%, rgba(0,0,0,0.1) 50%, rgba(0,0,0,0.1) ); background-size: 100% 4px;
.controls-hint { position: absolute; top: 0; left: 0; right: 0; bottom: 0; pointer-events: none; z-index: 10; bottom: 2rem; left: 50%; transform: translateX(-50%); display: flex; gap: 2rem; color: rgba(255, 255, 255, 0.5); font-size: 0.8rem; } /* Glitch Text Animation */ @keyframes glitch { 0% { transform: translate(0) } 20% { transform: translate(-2px, 2px) } 40% { transform: translate(-2px, -2px) } 60% { transform: translate(2px, 2px) } 80% { transform: translate(2px, -2px) } 100% { transform: translate(0) }
.control-key { display: flex; align-items: center; gap: 0.5rem; } .glitch-hover:hover { animation: glitch 0.3s cubic-bezier(.25, .46, .45, .94) both infinite; color: #F7931A;
.key { background: var(--glass); border: 1px solid var(--glass-border); padding: 0.3rem 0.6rem; border-radius: 4px; font-family: 'Orbitron', monospace; font-size: 0.7rem; }
.hud-text { font-family: 'VT323', monospace; text-shadow: 2px 2px 0px #000; .final-score { font-family: 'Orbitron', monospace; font-size: clamp(1.5rem, 5vw, 3rem); color: var(--primary); margin: 1rem 0; }
.final-btc { font-family: 'Orbitron', monospace; font-size: clamp(1rem, 3vw, 1.5rem); color: var(--accent); margin-bottom: 2rem; }
.game-over-stats { display: flex; gap: 2rem; margin-bottom: 2rem; }
.stat-item { text-align: center; }
.stat-value { font-family: 'Orbitron', monospace; font-size: 1.5rem; color: white; }
.stat-label { font-size: 0.8rem; color: rgba(255, 255, 255, 0.6); }
.new-record { color: var(--secondary); font-family: 'Orbitron', monospace; animation: recordPulse 0.5s ease-in-out infinite; }
@keyframes recordPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.mobile-controls { display: none; position: absolute; bottom: 2rem; left: 0; width: 100%; justify-content: space-between; padding: 0 2rem; pointer-events: auto; }
@media (max-width: 768px) { .mobile-controls { display: flex; } .controls-hint { display: none; } }
.mobile-btn { width: 70px; height: 70px; border-radius: 50%; background: var(--glass); border: 2px solid var(--glass-border); color: white; font-size: 1.5rem; display: flex; justify-content: center; align-items: center; transition: all 0.2s ease; }
.mobile-btn:active { transform: scale(0.9); background: var(--primary); border-color: var(--primary); }
.mobile-btn.vertical { flex-direction: column; gap: 0.5rem; }
.powered-by { position: absolute; bottom: 1rem; left: 50%; transform: translateX(-50%); font-size: 0.8rem; color: rgba(255, 255, 255, 0.4); text-decoration: none; transition: color 0.3s ease; }
.powered-by:hover { color: var(--primary); }
.combo-display { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-family: 'Orbitron', monospace; font-size: 2rem; color: var(--primary); text-shadow: 0 0 20px var(--primary); opacity: 0; transition: all 0.3s ease; pointer-events: none; }
.combo-display.show { opacity: 1; animation: comboAnim 0.5s ease-out; }
@keyframes comboAnim { 0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; } 50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; } 100% { transform: translate(-50%, -50%) scale(1); opacity: 0; } } </style></head><body>
<!-- Canvas Layer --> <canvas id="gameCanvas"></canvas> <div id="gameContainer"> <canvas id="gameCanvas"></canvas> <div class="scanlines"></div>
<!-- UI Layer --> <div id="uiLayer" class="ui-layer"> <!-- HUD (Top) --> <div id="hud" class="hidden w-full flex justify-between items-start z-20"> <div class="flex flex-col gap-1"> <div class="text-yellow-400 text-3xl hud-text tracking-wider"> <span class="text-white">SCORE:</span> <span id="scoreDisplay">0</span> </div> <div class="text-orange-500 text-2xl hud-text tracking-wider flex items-center gap-2"> <span class="text-white">BTC:</span> <span id="btcDisplay">0.00000000</span> ₿ </div> </div> <div class="flex flex-col items-end gap-1"> <div class="text-cyan-400 text-2xl hud-text"> SPEED: <span id="speedDisplay">0</span> km/h </div> <div id="powerupStatus" class="flex gap-2"> <!-- Icons injected via JS --> </div> <!-- Start Screen --> <div id="startScreen" class="screen"> <h1 class="title">DINO RUN</h1> <p class="subtitle">Bitcoin Edition</p> <button class="btn" id="startBtn">START GAME</button> <div class="controls-hint"> <div class="control-key"><span class="key">←</span><span class="key">→</span> Move</div> <div class="control-key"><span class="key">↑</span> Jump</div> <div class="control-key"><span class="key">↓</span> Slide</div> </div> </div>
<!-- Start Screen --> <div id="startScreen" class="absolute inset-0 flex flex-col items-center justify-center bg-black/80 backdrop-blur-sm z-30 interactive"> <h1 class="text-6xl md:text-8xl text-green-400 mb-2 tracking-tighter drop-shadow-[0_5px_5px_rgba(0,0,0,0.8)]" style="font-family: 'Fredoka One'"> DINO <span class="text-orange-500">₿</span> RUN </h1> <p class="text-gray-300 mb-8 text-xl font-sans">Collect Sats. Dodge Obstacles. To the Moon.</p> <div class="flex gap-4 mb-8"> <div class="flex flex-col items-center bg-gray-800 p-4 rounded-lg border border-gray-700"> <div class="w-8 h-8 border-2 border-white rounded mb-2 flex items-center justify-center text-white">←</div> <span class="text-xs text-gray-400">LEFT</span> <!-- HUD --> <div id="hud" class="ui-overlay" style="display: none;"> <div class="hud"> <div class="hud-left"> <div class="hud-item"> <div class="hud-label">Distance</div> <div class="hud-value" id="distanceDisplay">0m</div> </div> </div> <div class="hud-center"> <div class="powerup-indicator magnet" id="magnetIndicator">🧲</div> <div class="powerup-indicator shield" id="shieldIndicator">🛡️</div> <div class="powerup-indicator multiplier" id="multiplierIndicator">×2</div> <div class="powerup-indicator speed" id="speedIndicator">⚡</div> </div> <div class="flex flex-col items-center bg-gray-800 p-4 rounded-lg border border-gray-700"> <div class="w-8 h-8 border-2 border-white rounded mb-2 flex items-center justify-center text-white">→</div> <span class="text-xs text-gray-400">RIGHT</span> <div class="hud-right"> <div class="hud-item"> <div class="hud-label">Balance</div> <div class="hud-value btc" id="btcDisplay">₿ 0.00000000</div> </div> <div class="hud-item"> <div class="hud-label">Speed</div> <div class="hud-value speed" id="speedDisplay">0 km/h</div> </div> </div> <div class="flex flex-col items-center bg-gray-800 p-4 rounded-lg border border-gray-700"> <div class="w-8 h-8 border-2 border-white rounded mb-2 flex items-center justify-center text-white">↑</div> <span class="text-xs text-gray-400">JUMP</span> </div> <button class="pause-btn" id="pauseBtn">⏸</button> <div class="mobile-controls"> <div class="mobile-btn vertical"> <span id="mobileJump">↑</span> <span>Jump</span> </div> <div class="flex flex-col items-center bg-gray-800 p-4 rounded-lg border border-gray-700"> <div class="w-8 h-8 border-2 border-white rounded mb-2 flex items-center justify-center text-white">↓</div> <span class="text-xs text-gray-400">SLIDE</span> <div class="mobile-btn" id="mobileLeft">←</div> <div class="mobile-btn" id="mobileRight">→</div> <div class="mobile-btn vertical"> <span id="mobileSlide">↓</span> <span>Slide</span> </div> </div>
<button id="startBtn" class="glitch-hover bg-green-500 hover:bg-green-400 text-black text-2xl px-12 py-4 rounded-full shadow-[0_0_20px_rgba(74,222,128,0.6)] transition-all transform hover:scale-105 font-bold border-4 border-green-700"> START RUNNING </button> <div class="combo-display" id="comboDisplay"></div> </div>
<!-- Pause Screen --> <div id="pauseScreen" class="screen hidden"> <h1 class="title">PAUSED</h1> <button class="btn" id="resumeBtn">RESUME</button> <button class="btn btn-secondary" id="quitBtn">QUIT</button> </div>
<!-- Game Over Screen --> <div id="gameOverScreen" class="hidden absolute inset-0 flex flex-col items-center justify-center bg-red-900/90 backdrop-blur-md z-40 interactive"> <h2 class="text-6xl text-white mb-2 drop-shadow-lg">CRASHED!</h2> <div class="bg-black/50 p-6 rounded-xl border border-red-500 mb-8 text-center min-w-[300px]"> <div class="text-gray-300 text-lg mb-1">Distance</div> <div class="text-4xl text-white mb-4" id="finalScore">0m</div> <div class="text-gray-300 text-lg mb-1">Total BTC Mined</div> <div class="text-4xl text-orange-400 font-mono" id="finalBTC">0.00000000</div> <div id="gameOverScreen" class="screen hidden"> <h1 class="title">GAME OVER</h1> <div class="game-over-stats"> <div class="stat-item"> <div class="stat-value" id="finalDistance">0m</div> <div class="stat-label">Distance</div> </div> <div class="stat-item"> <div class="stat-value" id="finalBtc">₿ 0.00000000</div> <div class="stat-label">Earned</div> </div> </div> <button id="restartBtn" class="glitch-hover bg-white text-red-600 text-2xl px-10 py-3 rounded-full shadow-lg hover:bg-gray-100 transition-all font-bold"> TRY AGAIN </button> <div class="final-score" id="newRecordText" style="display: none;">NEW RECORD!</div> <button class="btn" id="restartBtn">PLAY AGAIN</button> <button class="btn btn-secondary" id="homeBtn">HOME</button> </div>
<!-- Mobile Controls (Visible only on touch devices via logic, but here for structure) --> <div id="mobileControls" class="hidden w-full h-full absolute top-0 left-0 z-10"> <div class="w-1/2 h-full absolute left-0" id="touchLeft"></div> <div class="w-1/2 h-full absolute right-0" id="touchRight"></div> <div class="absolute bottom-10 left-10 w-20 h-20 bg-white/10 rounded-full backdrop-blur" id="btnJump">JUMP</div> <div class="absolute bottom-10 right-10 w-20 h-20 bg-white/10 rounded-full backdrop-blur" id="btnSlide">SLIDE</div> </div> <a href="https://huggingface.co/spaces/akhaliq/anycoder" class="powered-by" target="_blank">Built with anycoder</a> </div>
<script> /** * BITCOIN DINO RUN * A high-performance HTML5 Canvas Endless Runner */
// --- Configuration --- // ============================================ // GAME CONFIGURATION // ============================================ const CONFIG = { lanes: 3, laneWidth: 0, // Calculated dynamically baseSpeed: 600, // Pixels per second maxSpeed: 1400, acceleration: 5, // Speed increase per second gravity: 2500, jumpForce: -900, colors: { dino: '#4ade80', // Tailwind green-400 dinoDark: '#166534', headband: '#ef4444', // Red btc: '#F7931A', ground: '#374151', groundLight: '#4b5563' } CANVAS_WIDTH: 1200, CANVAS_HEIGHT: 700, LANE_COUNT: 3, LANE_WIDTH: 200, PLAYER_WIDTH: 80, PLAYER_HEIGHT: 100, BASE_SPEED: 400, MAX_SPEED: 1200, SPEED_INCREMENT: 10, GRAVITY: 1800, JUMP_FORCE: -650, SLIDE_DURATION: 600, COIN_VALUE: 0.00000001, BONUS_COIN_VALUE: 0.00000005, SPAWN_INTERVAL_BASE: 1500, POWERUP_CHANCE: 0.08, MAGNET_DURATION: 8000, SHIELD_DURATION: 10000, MULTIPLIER_DURATION: 10000, SPEED_BOOST_DURATION: 5000, COIN_SPIN_SPEED: 3, PARTICLE_COUNT: 5 };
// --- State Management --- const state = { screen: 'start', // start, playing, gameover // ============================================ // GAME STATE // ============================================ const game = { canvas: null, ctx: null, width: 0, height: 0, state: 'start', // start, playing, paused, gameover deltaTime: 0, lastTime: 0, score: 0, // Distance btc: 0.00000000, speed: 0, lane: 1, // 0, 1, 2 isJumping: false, isSliding: false, jumpVelocity: 0, y: 0, // Vertical position (0 is ground) slideTimer: 0, magnetTimer: 0, multiplierTimer: 0, shieldTimer: 0, multiplier: 1, frame: 0, cameraShake: 0 };
// --- Assets & Objects --- const canvas = document.getElementById('gameCanvas'); const ctx = canvas.getContext('2d'); let entities = { distance: 0, btcBalance: 0, speed: CONFIG.BASE_SPEED, currentLane: 1, targetLane: 1, player: { x: 0, y: 0, width: CONFIG.PLAYER_WIDTH, height: CONFIG.PLAYER_HEIGHT, velocityY: 0, isJumping: false, isSliding: false, slideTimer: 0, animFrame: 0, animTimer: 0, runCycle: 0 }, obstacles: [], coins: [], powerups: [], particles: [], bgLayers: [] background: { layers: [], groundOffset: 0 }, effects: { shake: 0, speedLines: [] }, powerups: { magnet: { active: false, timer: 0 }, shield: { active: false, timer: 0 }, multiplier: { active: false, timer: 0 }, speedBoost: { active: false, timer: 0 } }, combo: { count: 0, timer: 0, multiplier: 1 }, spawnTimer: 0, highScore: 0, keys: {} };
// --- Input Handling --- const keys = { ArrowUp: false, ArrowDown: false, ArrowLeft: false, ArrowRight: false, w: false, s: false, a: false, d: false, Space: false }; window.addEventListener('keydown', (e) => { if(keys.hasOwnProperty(e.key) || e.code === 'Space') keys[e.key] = true; handleInput(e.key, true); }); window.addEventListener('keyup', (e) => { if(keys.hasOwnProperty(e.key) || e.code === 'Space') keys[e.key] = false; handleInput(e.key, false); });
// Touch controls let touchStartX = 0; let touchStartY = 0; canvas.addEventListener('touchstart', e => { touchStartX = e.changedTouches[0].screenX; touchStartY = e.changedTouches[0].screenY; }, {passive: false}); canvas.addEventListener('touchend', e => { const touchEndX = e.changedTouches[0].screenX; const touchEndY = e.changedTouches[0].screenY; handleSwipe(touchStartX, touchStartY, touchEndX, touchEndY); }, {passive: false});
function handleSwipe(sx, sy, ex, ey) { const dx = ex - sx; const dy = ey - sy; if (Math.abs(dx) > Math.abs(dy)) { // Horizontal if (Math.abs(dx) > 30) { if (dx > 0) changeLane(1); else changeLane(-1); } // ============================================ // INITIALIZATION // ============================================ function init() { game.canvas = document.getElementById('gameCanvas'); game.ctx = game.canvas.getContext('2d'); resizeCanvas(); window.addEventListener('resize', resizeCanvas); setupEventListeners(); initBackground(); game.lastTime = performance.now(); requestAnimationFrame(gameLoop); }
function resizeCanvas() { const container = document.getElementById('gameContainer'); const aspectRatio = CONFIG.CANVAS_WIDTH / CONFIG.CANVAS_HEIGHT; let width = container.clientWidth; let height = container.clientHeight; if (width / height > aspectRatio) { width = height * aspectRatio; } else { // Vertical if (Math.abs(dy) > 30) { if (dy < 0) jump(); else slide(); } height = width / aspectRatio; } game.canvas.width = CONFIG.CANVAS_WIDTH; game.canvas.height = CONFIG.CANVAS_HEIGHT; game.canvas.style.width = width + 'px'; game.canvas.style.height = height + 'px'; game.width = CONFIG.CANVAS_WIDTH; game.height = CONFIG.CANVAS_HEIGHT; }
function handleInput(key, isDown) { if (state.screen !== 'playing') return; function setupEventListeners() { // Keyboard window.addEventListener('keydown', (e) => { game.keys[e.code] = true; if (game.state === 'playing') { handleInput(e.code); } }); if (isDown) { if (key === 'ArrowLeft' || key === 'a') changeLane(-1); if (key === 'ArrowRight' || key === 'd') changeLane(1); if (key === 'ArrowUp' || key === 'w' || key === ' ') jump(); if (key === 'ArrowDown' || key === 's') slide(); window.addEventListener('keyup', (e) => { game.keys[e.code] = false; });
// Buttons document.getElementById('startBtn').addEventListener('click', startGame); document.getElementById('pauseBtn').addEventListener('click', pauseGame); document.getElementById('resumeBtn').addEventListener('click', resumeGame); document.getElementById('quitBtn').addEventListener('click', quitToMenu); document.getElementById('restartBtn').addEventListener('click', restartGame); document.getElementById('homeBtn').addEventListener('click', quitToMenu);
// Mobile controls document.getElementById('mobileLeft').addEventListener('touchstart', () => { if (game.state === 'playing') changeLane(-1); }); document.getElementById('mobileRight').addEventListener('touchstart', () => { if (game.state === 'playing') changeLane(1); }); document.getElementById('mobileJump').parentElement.addEventListener('touchstart', (e) => { e.preventDefault(); if (game.state === 'playing') jump(); }); document.getElementById('mobileSlide').parentElement.addEventListener('touchstart', (e) => { e.preventDefault(); if (game.state === 'playing') slide(); }); }
// ============================================ // INPUT HANDLING // ============================================ function handleInput(code) { switch(code) { case 'ArrowLeft': case 'KeyA': changeLane(-1); break; case 'ArrowRight': case 'KeyD': changeLane(1); break; case 'ArrowUp': case 'KeyW': case 'Space': jump(); break; case 'ArrowDown': case 'KeyS': slide(); break; case 'Escape': pauseGame(); break; } }
function changeLane(dir) { const newLane = state.lane + dir; if (newLane >= 0 && newLane < CONFIG.lanes) { state.lane = newLane; createDust(state.lane, 0, 5); function changeLane(direction) { const newLane = game.targetLane + direction; if (newLane >= 0 && newLane < CONFIG.LANE_COUNT) { game.targetLane = newLane; } }
function jump() { if (!state.isJumping && !state.isSliding) { state.isJumping = true; state.jumpVelocity = CONFIG.jumpForce; createDust(state.lane, 0, 10); if (!game.player.isJumping && !game.player.isSliding) { game.player.isJumping = true; game.player.velocityY = CONFIG.JUMP_FORCE; } }
function slide() { if (!state.isSliding && !state.isJumping) { state.isSliding = true; state.slideTimer = 0.8; // seconds if (!game.player.isJumping && !game.player.isSliding) { game.player.isSliding = true; game.player.slideTimer = CONFIG.SLIDE_DURATION; } }
// --- Game Loop --- function resize() { canvas.width = window.innerWidth; canvas.height = window.innerHeight; CONFIG.laneWidth = canvas.width / CONFIG.lanes; } window.addEventListener('resize', resize); resize();
function initGame() { state.score = 0; state.btc = 0.00000000; state.speed = CONFIG.baseSpeed; state.lane = 1; state.isJumping = false; state.isSliding = false; state.y = 0; state.multiplier = 1; state.magnetTimer = 0; state.shieldTimer = 0; state.multiplierTimer = 0; entities.obstacles = []; entities.coins = []; entities.particles = []; // Initialize Background Layers entities.bgLayers = [ { speedMod: 0.1, color: '#111827', elements: generateBgElements(20, 50) }, // Far { speedMod: 0.3, color: '#1f2937', elements: generateBgElements(10, 100) }, // Mid { speedMod: 0.6, color: '#374151', elements: generateBgElements(5, 200) } // Near ];
state.screen = 'playing'; state.lastTime = performance.now(); requestAnimationFrame(loop); // ============================================ // GAME STATE MANAGEMENT // ============================================ function startGame() { document.getElementById('startScreen').classList.add('hidden'); document.getElementById('hud').style.display = 'block'; resetGame(); game.state = 'playing'; }
function generateBgElements(count, heightVar) { let arr = []; for(let i=0; i<count; i++) { arr.push({ x: Math.random() * canvas.width * 2, y: canvas.height - 150 - Math.random() * heightVar, w: 50 + Math.random() * 100, h: 50 + Math.random() * heightVar }); function pauseGame() { if (game.state === 'playing') { game.state = 'paused'; document.getElementById('pauseScreen').classList.remove('hidden'); } return arr; }
function loop(timestamp) { if (state.screen !== 'playing') return;
const dt = Math.min((timestamp - state.lastTime) / 1000, 0.1); // Cap dt state.lastTime = timestamp; state.frame++; function resumeGame() { game.state = 'playing'; document.getElementById('pauseScreen').classList.add('hidden'); game.lastTime = performance.now(); }
update(dt); draw(); function quitToMenu() { game.state = 'start'; document.getElementById('pauseScreen').classList.add('hidden'); document.getElementById('gameOverScreen').classList.add('hidden'); document.getElementById('hud').style.display = 'none'; document.getElementById('startScreen').classList.remove('hidden'); }
requestAnimationFrame(loop); function restartGame() { document.getElementById('gameOverScreen').classList.add('hidden'); resetGame(); game.state = 'playing'; }
// --- Update Logic --- function update(dt) { // Speed progression if (state.speed < CONFIG.maxSpeed) { state.speed += CONFIG.acceleration * dt; function gameOver() { game.state = 'gameover'; const isNewRecord = game.distance > game.highScore; if (isNewRecord) { game.highScore = Math.floor(game.distance); } document.getElementById('finalDistance').textContent = Math.floor(game.distance) + 'm'; document.getElementById('finalBtc').textContent = '₿ ' + game.btcBalance.toFixed(8); document.getElementById('newRecordText').style.display = isNewRecord ? 'block' : 'none'; document.getElementById('gameOverScreen').classList.remove('hidden'); }
// Score state.score += (state.speed * dt) / 100;
// Physics if (state.isJumping) { state.y += state.jumpVelocity * dt; state.jumpVelocity += CONFIG.gravity * dt; if (state.y >= 0) { state.y = 0; state.isJumping = false; createDust(state.lane, 0, 5); } } function resetGame() { game.distance = 0; game.btcBalance = 0; game.speed = CONFIG.BASE_SPEED; game.currentLane = 1; game.targetLane = 1; game.spawnTimer = 0; game.effects.shake = 0; game.combo = { count: 0, timer: 0, multiplier: 1 }; game.player = { x: getLaneX(1), y: game.height - 180, width: CONFIG.PLAYER_WIDTH, height: CONFIG.PLAYER_HEIGHT, velocityY: 0, isJumping: false, isSliding: false, slideTimer: 0, animFrame: 0, animTimer: 0, runCycle: 0 }; game.obstacles = []; game.coins = []; game.powerups = { magnet: { active: false, timer: 0 }, shield: { active: false, timer: 0 }, multiplier: { active: false, timer: 0 }, speedBoost: { active: false, timer: 0 } }; game.particles = []; updateHUD(); }
if (state.isSliding) { state.slideTimer -= dt; if (state.slideTimer <= 0) state.isSliding = false; // ============================================ // GAME LOOP // ============================================ function gameLoop(timestamp) { game.deltaTime = Math.min((timestamp - game.lastTime) / 1000, 0.1); game.lastTime = timestamp; if (game.state === 'playing') { update(); render(); }
// Timers if (state.magnetTimer > 0) state.magnetTimer -= dt; if (state.multiplierTimer > 0) state.multiplierTimer -= dt; if (state.shieldTimer > 0) state.shieldTimer -= dt; else state.multiplier = 1;
// Camera Shake decay if (state.cameraShake > 0) state.cameraShake *= 0.9; if (state.cameraShake < 0.5) state.cameraShake = 0;
// Spawning spawnManager(dt);
// Entity Updates & Collision updateEntities(dt); // Particles updateParticles(dt); requestAnimationFrame(gameLoop); }
// UI Update document.getElementById('scoreDisplay').innerText = Math.floor(state.score); document.getElementById('speedDisplay').innerText = Math.floor(state.speed / 10); document.getElementById('btcDisplay').innerText = state.btc.toFixed(8); function update() { // Update speed if (game.powerups.speedBoost.active) { game.speed = CONFIG.MAX_SPEED * 1.3; } else { game.speed = Math.min(CONFIG.MAX_SPEED, CONFIG.BASE_SPEED + game.distance * 0.5); } // Update distance game.distance += game.speed * game.deltaTime / 60; // Update player updatePlayer(); // Update lane position const targetX = getLaneX(game.targetLane); game.player.x += (targetX - game.player.x) * 10 * game.deltaTime; game.currentLane = game.player.x; // Spawn objects game.spawnTimer -= game.deltaTime * 1000; if (game.spawnTimer <= 0) { spawnObjects(); const spawnInterval = Math.max(800, CONFIG.SPAWN_INTERVAL_BASE - game.distance * 0.5); game.spawnTimer = spawnInterval; } // Update objects updateObstacles(); updateCoins(); updatePowerups(); updateParticles(); // Update powerup timers updatePowerupTimers(); // Update combo if (game.combo.timer > 0) { game.combo.timer -= game.deltaTime * 1000; } else { game.combo.count = 0; game.combo.multiplier = 1; } // Update background updateBackground(); // Update screen shake if (game.effects.shake > 0) { game.effects.shake *= 0.9; } // Speed lines if (game.speed > CONFIG.BASE_SPEED * 1.5) { if (Math.random() < 0.3) { game.effects.speedLines.push({ x: game.width, y: Math.random() * game.height, length: 50 + Math.random() * 100, speed: 1500 + Math.random() * 500, alpha: 0.3 + Math.random() * 0.4 }); } } game.effects.speedLines = game.effects.speedLines.filter(line => { line.x -= line.speed * game.deltaTime; return line.x + line.length > 0; }); // Check collisions checkCollisions(); // Update Powerup Icons const pContainer = document.getElementById('powerupStatus'); pContainer.innerHTML = ''; if (state.magnetTimer > 0) pContainer.innerHTML += '<div class="w-6 h-6 rounded-full bg-blue-500 border-2 border-white shadow-lg animate-pulse"></div>'; if (state.multiplierTimer > 0) pContainer.innerHTML += '<div class="w-6 h-6 rounded-full bg-yellow-500 border-2 border-white shadow-lg animate-pulse">x2</div>'; if (state.shieldTimer > 0) pContainer.innerHTML += '<div class="w-6 h-6 rounded-full bg-purple-500 border-2 border-white shadow-lg animate-pulse">S</div>'; // Update HUD updateHUD(); }
function spawnManager(dt) { // Simple spawn logic based on distance traveled // We track a virtual "distance since last spawn" if (!state.spawnTimer) state.spawnTimer = 0; state.spawnTimer -= state.speed * dt;
if (state.spawnTimer <= 0) { // Determine what to spawn const r = Math.random(); const lane = Math.floor(Math.random() * 3); function updatePlayer() { const groundY = game.height - 180; // Jump physics if (game.player.isJumping) { game.player.velocityY += CONFIG.GRAVITY * game.deltaTime; game.player.y += game.player.velocityY * game.deltaTime; // 30% chance for coin row, 40% obstacle, 30% mixed if (r < 0.3) { spawnCoinRow(lane); } else if (r < 0.7) { spawnObstacle(lane); } else { spawnCoinRow(lane); // Spawn obstacle in different lane let otherLane = (lane + 1) % 3; if(Math.random() > 0.5) otherLane = (lane + 2) % 3; spawnObstacle(otherLane); if (game.player.y >= groundY) { game.player.y = groundY; game.player.isJumping = false; game.player.velocityY = 0; } } else { game.player.y = groundY; } // Slide if (game.player.isSliding) { game.player.slideTimer -= game.deltaTime * 1000; if (game.player.slideTimer <= 0) { game.player.isSliding = false; } } // Animation game.player.animTimer += game.deltaTime * 1000; if (game.player.animTimer > 100) { game.player.animTimer = 0; game.player.runCycle = (game.player.runCycle + 0.2) % (Math.PI * 2); } }
// Reset timer (random interval based on speed) state.spawnTimer = 400 + Math.random() * 600; function getLaneX(lane) { const totalWidth = CONFIG.LANE_COUNT * CONFIG.LANE_WIDTH; const startX = (game.width - totalWidth) / 2; return startX + lane * CONFIG.LANE_WIDTH + CONFIG.LANE_WIDTH / 2; }
// ============================================ // SPAWNING // ============================================ function spawnObjects() { const lane = Math.floor(Math.random() * CONFIG.LANE_COUNT); const type = Math.random(); // Spawn obstacle if (type < 0.6) { spawnObstacle(lane); } // Spawn coins if (Math.random() < 0.7) { spawnCoinPattern(lane); } // Spawn powerup if (Math.random() < CONFIG.POWERUP_CHANCE) { spawnPowerup(lane); } }
function spawnObstacle(lane) { const type = Math.random() > 0.5 ? 'barrier' : 'train'; // simplified types entities.obstacles.push({ x: canvas.width + 100, lane: lane, const obstacleTypes = ['barrier', 'barrier_tall', 'gap']; const type = obstacleTypes[Math.floor(Math.random() * obstacleTypes.length)]; game.obstacles.push({ x: getLaneX(lane), y: game.height - 180, width: type === 'barrier_tall' ? 60 : 80, height: type === 'barrier_tall' ? 120 : 80, type: type, width: type === 'train' ? 300 : 80, height: type === 'train' ? 140 : 80, z: 0, // Ground level active: true lane: lane, passed: false }); }
function spawnCoinRow(lane) { const count = 5 + Math.floor(Math.random() * 5); const startX = canvas.width + 100; for (let i = 0; i < count; i++) { // Check for powerup spawn let isPowerup = Math.random() < 0.05; let type = 'btc'; if (isPowerup) { const pType = Math.random(); if (pType < 0.33) type = 'magnet'; else if (pType < 0.66) type = 'multiplier'; else type = 'shield'; function spawnCoinPattern(lane) { const pattern = Math.floor(Math.random() * 3); const startX = getLaneX(lane); if (pattern === 0) { // Horizontal line for (let i = 0; i < 5; i++) { game.coins.push({ x: startX + (i - 2) * 50, y: game.height - 200 - Math.random() * 100, radius: 25, value: CONFIG.COIN_VALUE, rotation: Math.random() * Math.PI * 2, glow: 0 }); }
entities.coins.push({ x: startX + (i * 80), lane: lane, y: 0, // Ground relative type: type, active: true, rot: 0 } else if (pattern === 1) { // Arc for (let i = 0; i < 5; i++) { const angle = (i / 4) * Math.PI - Math.PI / 2; game.coins.push({ x: startX + Math.cos(angle) * 80, y: game.height - 200 + Math.sin(angle) * 50, radius: 25, value: CONFIG.COIN_VALUE, rotation: Math.random() * Math.PI * 2, glow: 0 }); } } else { // Single bonus coin game.coins.push({ x: startX, y: game.height - 250, radius: 35, value: CONFIG.BONUS_COIN_VALUE, rotation: Math.random() * Math.PI * 2, glow: 1 }); } }
function updateEntities(dt) { const moveDist = state.speed * dt; function spawnPowerup(lane) { const types = ['magnet', 'shield', 'multiplier', 'speedBoost']; const type = types[Math.floor(Math.random() * types.length)]; game.powerups.push({ x: getLaneX(lane), y: game.height - 250, width: 50, height: 50, type: type, rotation: 0, bounce: 0 }); }
// Update Obstacles entities.obstacles.forEach(obs => { obs.x -= moveDist; // ============================================ // UPDATE OBJECTS // ============================================ function updateObstacles() { game.obstacles = game.obstacles.filter(obs => { obs.x -= game.speed * game.deltaTime; // Collision if (obs.active && obs.x < getLaneCenter(state.lane) + 40 && obs.x > getLaneCenter(state.lane) - 40) { // Check Z depth (simple Y check here) // Obstacles are on ground (y=0) unless we had aerial ones. // Player Y is negative when jumping. let hit = false; if (state.isJumping) { // Jumping over barrier is okay, train is too high? Let's say train hits jumpers. if (obs.type === 'train' && state.y > -100) hit = true; } else if (state.isSliding) { // Sliding under train is okay? Let's say yes. if (obs.type === 'barrier') hit = true; } else { // Running hit = true; }
if (hit) { if (state.shieldTimer > 0) { obs.active = false; // Break obstacle createExplosion(obs.x, canvas.height/2 + 50, '#fff'); } else { gameOver(); } } // Remove if off screen if (obs.x < -100) { return false; } });
// Cleanup Obstacles entities.obstacles = entities.obstacles.filter(o => o.x > -200);
// Update Coins const playerX = getLaneCenter(state.lane); const playerY = canvas.height/2 + 100 + state.y; // Approx player screen Y
entities.coins.forEach(coin => { coin.x -= moveDist; coin.rot += dt * 5;
// Magnet Logic let magnetRange = 300; let cx = coin.x; let cy = getLaneY(coin.lane) - 50; // Coin height offset
// Simple magnet pull if (state.magnetTimer > 0) { const dist = Math.hypot(cx - playerX, cy - playerY); if (dist < magnetRange) { coin.x += (playerX - cx) * dt * 5; // Adjust lane visually for magnet effect? Hard with lane system. // Just pull X for now. } // Check if passed if (!obs.passed && obs.x < game.player.x - 50) { obs.passed = true; addCombo(); } return true; }); }
// Collection if (coin.active && Math.abs(coin.x - playerX) < 50 && coin.lane === state.lane) { // Check height (can collect while jumping) if (Math.abs(state.y) < 100) { collectCoin(coin); function updateCoins() { game.coins = game.coins.filter(coin => { coin.x -= game.speed * game.deltaTime; coin.rotation += CONFIG.COIN_SPIN_SPEED * game.deltaTime; coin.glow = (coin.glow + 0.1) % (Math.PI * 2); // Magnet effect if (game.powerups.magnet.active) { const dx = game.player.x - coin.x; const dy = (game.player.y + game.player.height / 2) - coin.y; const dist = Math.sqrt(dx * dx + dy * dy); if (dist < 300) { coin.x += dx * 0.1; coin.y += dy * 0.1; } } // Remove if off screen return coin.x > -50; }); entities.coins = entities.coins.filter(c => c.x > -100); }
function collectCoin(coin) { coin.active = false; if (coin.type === 'btc') { const val = 0.00000001 * state.multiplier; state.btc += val; createFloatingText(coin.x, getLaneY(coin.lane) - 50, `+${val.toFixed(8)}`); createSparkle(coin.x, getLaneY(coin.lane) - 50, CONFIG.colors.btc); } else if (coin.type === 'magnet') { state.magnetTimer = 10; createFloatingText(coin.x, getLaneY(coin.lane) - 50, "MAGNET!"); } else if (coin.type === 'multiplier') { state.multiplierTimer = 10; state.multiplier = 2; createFloatingText(coin.x, getLaneY(coin.lane) - 50, "x2 BTC!"); } else if (coin.type === 'shield') { state.shieldTimer = 10; createFloatingText(coin.x, getLaneY(coin.lane) - 50, "SHIELD!"); } }
// --- Rendering --- function draw() { // Clear ctx.fillStyle = '#111827'; // Dark bg ctx.fillRect(0, 0, canvas.width, canvas.height);
// Camera Shake ctx.save(); if (state.cameraShake > 0) { const dx = (Math.random() - 0.5) * state.cameraShake; const dy = (Math.random() - 0.5) * state.cameraShake; ctx.translate(dx, dy); }
// Draw Background (Parallax) drawBackground();
// Draw Ground drawGround();
// Draw Entities // Sort by Y for pseudo-depth const renderList = [ ...entities.obstacles.map(o => ({...o, t: 'obs', y: 0})), ...entities.coins.map(c => ({...c, t: 'coin', y: 0})) ]; // Player Y is relative to ground. Ground is at canvas.height/2 + 100. const groundY = canvas.height / 2 + 100;
// Draw Player Shadow const playerX = getLaneCenter(state.lane); const playerY = groundY + state.y; ctx.fillStyle = 'rgba(0,0,0,0.3)'; ctx.beginPath(); ctx.ellipse(playerX, groundY, 30 * (1 - Math.abs(state.y)/500), 10 * (1 - Math.abs(state.y)/500), 0, 0, Math.PI*2); ctx.fill();
// Draw Player drawDino(playerX, playerY, state.isSliding);
// Draw Coins & Obstacles // We need to interleave them based on their "depth" (which is just lane order for now, or simple Z) // Since it's a runner, things just come towards camera. // Draw order: Back lane -> Front lane? Or just Y position. // Let's draw everything at their lane Y. entities.obstacles.forEach(obs => { const x = obs.x; const y = groundY; drawObstacle(x, y, obs); });
entities.coins.forEach(coin => { const x = coin.x; const y = groundY - 50; // Float drawCoin(x, y, coin); function updatePowerups() { game.powerups = game.powerups.filter(pu => { pu.x -= game.speed * game.deltaTime; pu.rotation += 2 * game.deltaTime; pu.bounce += 5 * game.deltaTime; return pu.x > -50; });
// Particles drawParticles();
ctx.restore(); }
function drawBackground() { // Sky gradient const grad = ctx.createLinearGradient(0, 0, 0, canvas.height); grad.addColorStop(0, '#0f172a'); grad.addColorStop(1, '#1e293b'); ctx.fillStyle = grad; ctx.fillRect(0,0, canvas.width, canvas.height);
// Parallax Layers entities.bgLayers.forEach(layer => { ctx.fillStyle = layer.color; layer.elements.forEach(el => { // Move element el.x -= (state.speed * 0.1) * layer.speedMod; // Slow movement if (el.x < -200) el.x = canvas.width + Math.random() * 200; // Draw simple building/rock shape ctx.beginPath(); ctx.roundRect(el.x, el.y, el.w, canvas.height - el.y, 10); ctx.fill(); }); function updateParticles() { game.particles = game.particles.filter(p => { p.x += p.vx * game.deltaTime; p.y += p.vy * game.deltaTime; p.life -= game.deltaTime; p.vy += 500 * game.deltaTime; return p.life > 0; }); }
function drawGround() { const horizon = canvas.height / 2 + 100; // Road ctx.fillStyle = '#374151'; ctx.fillRect(0, horizon, canvas.width, canvas.height - horizon); function updatePowerupTimers() { const updatePowerup = (name, duration) => { if (game.powerups[name].active) { game.powerups[name].timer -= game.deltaTime * 1000; if (game.powerups[name].timer <= 0) { game.powerups[name].active = false; } } }; // Lane markings ctx.strokeStyle = '#4b5563'; ctx.lineWidth = 4; ctx.setLineDash([40, 40]); ctx.lineDashOffset = -state.score * 2; // Animate lines updatePowerup('magnet', CONFIG.MAGNET_DURATION); updatePowerup('shield', CONFIG.SHIELD_DURATION); updatePowerup('multiplier', CONFIG.MULTIPLIER_DURATION); updatePowerup('speedBoost', CONFIG.SPEED_BOOST_DURATION); for(let i=1; i<CONFIG.lanes; i++) { const x = i * CONFIG.laneWidth; ctx.beginPath(); ctx.moveTo(x, horizon); ctx.lineTo(x, canvas.height); ctx.stroke(); } ctx.setLineDash([]); // Update indicators document.getElementById('magnetIndicator').classList.toggle('active', game.powerups.magnet.active); document.getElementById('shieldIndicator').classList.toggle('active', game.powerups.shield.active); document.getElementById('multiplierIndicator').classList.toggle('active', game.powerups.multiplier.active); document.getElementById('speedIndicator').classList.toggle('active', game.powerups.speedBoost.active); }
function drawDino(x, y, sliding) { ctx.save(); ctx.translate(x, y); function addCombo() { game.combo.count++; game.combo.timer = 2000; game.combo.multiplier = Math.min(5, 1 + Math.floor(game.combo.count / 5)); // Bounce animation if (!state.isJumping && !sliding) { const bounce = Math.sin(state.frame * 0.2) * 5; ctx.translate(0, -bounce); }
if (sliding) { ctx.rotate(-Math.PI / 2); // Rotate to slide ctx.translate(0, -20); }
// Shadow/Glow ctx.shadowColor = 'rgba(74, 222, 128, 0.4)'; ctx.shadowBlur = 20;
// Body (Rounded Rect) ctx.fillStyle = CONFIG.colors.dino; ctx.beginPath(); ctx.roundRect(-30, -80, 60, 70, 15); ctx.fill();
// Head ctx.beginPath(); ctx.arc(0, -90, 35, 0, Math.PI * 2); ctx.fill();
// Headband ctx.fillStyle = CONFIG.colors.headband; ctx.fillRect(-36, -100, 72, 15); // Knot ctx.beginPath(); ctx.moveTo(30, -95); ctx.lineTo(50, -105); ctx.lineTo(50, -85); ctx.fill();
// Bitcoin Symbol on Headband ctx.fillStyle = '#F7931A'; ctx.font = 'bold 20px monospace'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText('₿', 0, -92);
// Eyes ctx.fillStyle = 'white'; ctx.beginPath(); ctx.ellipse(-10, -95, 10, 12, 0, 0, Math.PI*2); ctx.ellipse(10, -95, 10, 12, 0, 0, Math.PI*2); ctx.fill(); // Pupils (look forward, or at coins?) ctx.fillStyle = 'black'; ctx.beginPath(); ctx.arc(-8, -95, 4, 0, Math.PI*2); ctx.arc(12, -95, 4, 0, Math.PI*2); ctx.fill();
// Arms ctx.fillStyle = CONFIG.colors.dino; if (sliding) { // Arms tucked } else { // Running arms const armAngle = Math.sin(state.frame * 0.3) * 0.5; ctx.beginPath(); ctx.ellipse(-25, -50, 10, 25, armAngle, 0, Math.PI*2); ctx.ellipse(25, -50, 10, 25, -armAngle, 0, Math.PI*2); ctx.fill(); }
// Legs (if not sliding) if (!sliding) { const legOffset = Math.sin(state.frame * 0.3) * 15; ctx.fillStyle = CONFIG.colors.dinoDark; // Left Leg ctx.beginPath(); ctx.roundRect(-20 + legOffset, -10, 15, 30, 5); ctx.fill(); // Right Leg ctx.beginPath(); ctx.roundRect(5 - legOffset, -10, 15, 30, 5); ctx.fill(); }
// Shield Effect if (state.shieldTimer > 0) { ctx.strokeStyle = `rgba(168, 85, 247, ${Math.abs(Math.sin(state.frame * 0.1))})`; ctx.lineWidth = 5; ctx.beginPath(); ctx.arc(0, -60, 60, 0, Math.PI*2); ctx.stroke(); if (game.combo.count > 0 && game.combo.count % 5 === 0) { showCombo(game.combo.multiplier + 'x COMBO!'); } }
ctx.restore(); function showCombo(text) { const comboEl = document.getElementById('comboDisplay'); comboEl.textContent = text; comboEl.classList.remove('show'); void comboEl.offsetWidth; comboEl.classList.add('show'); }
function drawObstacle(x, y, obs) { ctx.save(); ctx.translate(x, y); if (obs.type === 'barrier') { ctx.fillStyle = '#ef4444'; // Red barrier // 3D-ish box ctx.fillRect(-40, -obs.height, obs.width, obs.height); // Stripe ctx.fillStyle = '#fca5a5'; ctx.beginPath(); ctx.moveTo(-40, -obs.height); ctx.lineTo(40, -obs.height); ctx.lineTo(-40, 0); ctx.fill(); // Border ctx.strokeStyle = '#7f1d1d'; ctx.lineWidth = 3; ctx.strokeRect(-40, -obs.height, obs.width, obs.height); } else { // Train ctx.fillStyle = '#1e3a8a'; // Blue ctx.fillRect(-obs.width/2, -obs.height, obs.width, obs.height); // Windows ctx.fillStyle = '#93c5fd'; ctx.fillRect(-obs.width/2 + 10, -obs.height + 10, obs.width - 20, 40); // Detail ctx.fillStyle = '#172554'; ctx.fillRect(-obs.width/2, -20, obs.width, 10); // ============================================ // COLLISION DETECTION // ============================================ function checkCollisions() { const playerBox = { x: game.player.x - game.player.width / 2, y: game.player.y, width: game.player.width, height: game.player.isSliding ? game.player.height / 2 : game.player.height }; // Check obstacle collisions for (const obs of game.obstacles) { const obsBox = { x: obs.x - obs.width / 2, y: obs.y - obs.height, width: obs.width, height: obs.height }; if (boxCollision(playerBox, obsBox)) { if (game.powerups.shield.active) { // Use shield game.powerups.shield.active = false; game.effects.shake = 10; createParticles(obs.x, obs.y - obs.height / 2, '#E91E63', 10); } else { gameOver(); return; } } } ctx.restore(); // Check coin collisions game.coins = game.coins.filter(coin => { const dx = coin.x - game.player.x; const dy = coin.y - (game.player.y + game.player.height / 2); const dist = Math.sqrt(dx * dx + dy * dy); if (dist < coin.radius + 40) { // Collect coin let value = coin.value; if (game.powerups.multiplier.active) { value *= 2; } value *= game.combo.multiplier; game.btcBalance += value; createParticles(coin.x, coin.y, '#F7931A', CONFIG.PARTICLE_COUNT); return false; } return true; }); // Check powerup collisions game.powerups = game.powerups.filter(pu => { const dx = pu.x - game.player.x; const dy = pu.y - (game.player.y + game.player.height / 2); const dist = Math.sqrt(dx * dx + dy * dy); if (dist < 50) { activatePowerup(pu.type); createParticles(pu.x, pu.y, getPowerupColor(pu.type), 15); return false; } return true; }); }
function drawCoin(x, y, coin) { if (!coin.active) return; ctx.save(); ctx.translate(x, y); // Spin effect (scale X) const scaleX = Math.abs(Math.sin(coin.rot)); ctx.scale(scaleX, 1);
if (coin.type === 'btc') { ctx.fillStyle = CONFIG.colors.btc; ctx.shadowColor = CONFIG.colors.btc; ctx.shadowBlur = 15; ctx.beginPath(); ctx.arc(0, 0, 20, 0, Math.PI*2); ctx.fill(); ctx.fillStyle = '#fff'; ctx.font = 'bold 20px sans-serif'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText('₿', 0, 2); } else { // Powerups ctx.fillStyle = coin.type === 'magnet' ? '#3b82f6' : (coin.type === 'shield' ? '#a855f7' : '#eab308'); ctx.shadowColor = ctx.fillStyle; ctx.shadowBlur = 15; ctx.beginPath(); ctx.arc(0, 0, 15, 0, Math.PI*2); ctx.fill(); ctx.fillStyle = 'white'; ctx.font = '16px sans-serif'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; let icon = '?'; if(coin.type === 'magnet') icon = 'M'; if(coin.type === 'shield') icon = 'S'; if(coin.type === 'multiplier') icon = 'x2'; ctx.fillText(icon, 0, 2); } function boxCollision(a, b) { return a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.y + a.height > b.y; }
ctx.restore(); }
// --- Particle System --- function createDust(lane, y, count) { const cx = getLaneCenter(lane); const cy = getLaneY(lane); for(let i=0; i<count; i++) { entities.particles.push({ x: cx + (Math.random()-0.5)*40, y: cy, vx: (Math.random()-0.5)*100, vy: -Math.random()*100, life: 0.5, color: 'rgba(255,255,255,0.5)', size: Math.random()*5+2, type: 'dust' }); function activatePowerup(type) { switch(type) { case 'magnet': game.powerups.magnet.active = true; game.powerups.magnet.timer = CONFIG.MAGNET_DURATION; break; case 'shield': game.powerups.shield.active = true; game.powerups.shield.timer = CONFIG.SHIELD_DURATION; break; case 'multiplier': game.powerups.multiplier.active = true; game.powerups.multiplier.timer = CONFIG.MULTIPLIER_DURATION; break; case 'speedBoost': game.powerups.speedBoost.active = true; game.powerups.speedBoost.timer = CONFIG.SPEED_BOOST_DURATION; break; } }
function createSparkle(x, y, color) { for(let i=0; i<10; i++) { entities.particles.push({ x: x, y: y, vx: (Math.random()-0.5)*300, vy: (Math.random()-0.5)*300, life: 0.8, color: color, size: Math.random()*4+2, type: 'sparkle' }); } function getPowerupColor(type) { const colors = { magnet: '#00E5FF', shield: '#E91E63', multiplier: '#F7931A', speedBoost: '#4CAF50' }; return colors[type] || '#ffffff'; }
function createExplosion(x, y, color) { for(let i=0; i<20; i++) { entities.particles.push({ function createParticles(x, y, color, count) { for (let i = 0; i < count; i++) { const angle = (Math.PI * 2 * i) / count + Math.random() * 0.5; const speed = 200 + Math.random() * 300; game.particles.push({ x: x, y: y, vx: (Math.random()-0.5)*400, vy: (Math.random()-0.5)*400, life: 1.0, vx: Math.cos(angle) * speed, vy: Math.sin(angle) * speed - 200, color: color, size: Math.random()*6+3, type: 'debris' size: 3 + Math.random() * 5, life: 1 }); } }
function createFloatingText(x, y, text) { entities.particles.push({ x: x, y: y, vx: 0, vy: -50, life: 1.5, text: text, type: 'text' }); }
function updateParticles(dt) { entities.particles.forEach(p => { p.x += p.vx * dt; p.y += p.vy * dt; p.life -= dt; if (p.type === 'dust' || p.type === 'sparkle') { p.vy += 100 * dt; // gravity } }); entities.particles = entities.particles.filter(p => p.life > 0); }
function drawParticles() { entities.particles.forEach(p => { ctx.save(); ctx.globalAlpha = Math.max(0, p.life); if (p.type === 'text') { ctx.fillStyle = '#F7931A'; ctx.font = 'bold 20px Fredoka One'; ctx.fillText(p.text, p.x, p.y); } else { ctx.fillStyle = p.color; ctx.beginPath(); ctx.arc(p.x, p.y, p.size, 0, Math.PI*2); ctx.fill(); } ctx.restore(); }); }
// --- Helpers --- function getLaneCenter(laneIndex) { return (laneIndex * CONFIG.laneWidth) + (CONFIG.laneWidth / 2); }
function getLaneY(laneIndex) { // In this perspective, all lanes are same Y on screen return canvas.height / 2 + 100; // ============================================ // BACKGROUND // ============================================ function initBackground() { game.background.layers = [ { color: '#1a1a3e', speed: 0.2, y: 0, height: game.height }, { color: '#252550', speed: 0.4, y: game.height * 0.3, height: game.height * 0.7 }, { color: '#2d2d5a', speed: 0.6, y: game.height * 0.5, height: game.height * 0.5 } ]; }
function gameOver() { state.screen = 'gameover'; state.cameraShake = 20; document.getElementById('hud').classList.add('hidden'); document.getElementById('gameOverScreen').classList.remove('hidden'); document.getElementById('finalScore').innerText = Math.floor(state.score) + "m"; document.getElementById('finalBTC').innerText = state.btc.toFixed(8); function updateBackground() { game.background.groundOffset += game.speed * game.deltaTime; if (game.background.groundOffset > 100) { game.background.groundOffset = 0; } }
// --- Initialization --- document.getElementById('startBtn').addEventListener('click', () => { document.getElementById('startScreen').classList.add('hidden'); document.getElementById('hud').classList.remove('hidden'); initGame(); });
document.getElementById('restartBtn').addEventListener('click', () => { document.getElementById('gameOverScreen').classList.add('hidden'); document.getElementById('hud').classList.remove('hidden'); initGame(); });
// Initial Render resize(); drawBackground(); // Draw a static dino for the start screen background ctx.fillStyle = '#111827'; ctx.fillRect(0, 0, canvas.width, canvas.height); drawBackground(); drawGround(); drawDino(canvas.width/2, canvas.height/2 + 100, false);
</script></body></html> // ============================================ // RENDERING // ============================================ function render() { const ctx = game.ctx; // Apply screen shake ctx.save(); if (game.effects.shake > 0.5) { ctx.translate( (Math.random() - 0.5) * game.effects.shake, (Math.random() - 0.5) * game.effects.shake ); } // Clear ctx.fillStyle = '#1a1a2e'; ctx.fillRect(0, 0, game.width, game.height); // Draw background renderBackground(ctx); // Draw lanes renderLanes(ctx); // Draw ground renderGround(ctx); // Draw obstacles renderObstacles(ctx); // Draw coins renderCoins(ctx); // Drawindex.html+1165-845