-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.html
More file actions
490 lines (452 loc) · 25.5 KB
/
Copy pathrunner.html
File metadata and controls
490 lines (452 loc) · 25.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<!DOCTYPE html>
<!--
════════════════════════════════════════════════════════════════
ВСАДНИК АРЦАХА — аркадная игра-бегалка
Скачи по горам Арцаха, перепрыгивай камни, собирай гранаты.
КАК ИГРАТЬ: дважды кликни по этому файлу — откроется в браузере.
УПРАВЛЕНИЕ: Пробел / стрелка ↑ / клик / тап = прыжок (можно дважды).
── ХОЧЕШЬ СВОИ ФОТО? ──
Сейчас всё нарисовано кодом (горы, конь, гранаты), чтобы было красиво
без файлов. Когда захочешь — заменим фон на настоящие фото Арцаха,
а коня и гранаты на рисунки. Просто скажи.
════════════════════════════════════════════════════════════════
-->
<html lang="ru">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ctext y='.9em' font-size='88'%3E🏔️%3C/text%3E%3C/svg%3E" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Всадник Арцаха</title>
<meta name="theme-color" content="#0b0e18" />
<meta name="description" content="Аркадная игра «Всадник Арцаха»: скачи по горам Арцаха, перепрыгивай камни и собирай гранаты. Часть приложения об Арцахе." />
<link rel="canonical" href="https://hrahatyesayan-stack.github.io/artsakh/runner.html" />
<meta property="og:type" content="website" />
<meta property="og:title" content="Всадник Арцаха" />
<meta property="og:description" content="Аркадная игра «Всадник Арцаха»: скачи по горам Арцаха, перепрыгивай камни и собирай гранаты. Часть приложения об Арцахе." />
<meta property="og:image" content="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d0/DJI_-Gandzasar.jpg/1280px-DJI_-Gandzasar.jpg" />
<meta property="og:url" content="https://hrahatyesayan-stack.github.io/artsakh/runner.html" />
<meta name="twitter:card" content="summary_large_image" />
<style>
* { margin:0; padding:0; box-sizing:border-box; }
html, body { height:100%; overflow:hidden; background:#0b1020;
font-family:"Iowan Old Style","Palatino Linotype",Palatino,Georgia,serif;
color:#fff; user-select:none; -webkit-tap-highlight-color:transparent;
overscroll-behavior:none; touch-action:none; }
#game { display:block; position:fixed; inset:0; width:100%; height:100%; }
/* HUD */
#hud { position:fixed; top:0; left:0; right:0; z-index:8; display:flex;
justify-content:space-between; align-items:flex-start;
padding:16px 22px; pointer-events:none; text-shadow:0 2px 12px rgba(0,0,0,.55); }
#hud .label { display:block; opacity:.6; font-size:11px; letter-spacing:.25em;
text-transform:uppercase; margin-bottom:2px; }
#hud b { font-weight:500; font-size:clamp(22px,4vw,32px); }
.pom { color:#ff9a9a; }
/* Экраны */
.overlay { position:fixed; inset:0; z-index:10; display:flex; flex-direction:column;
align-items:center; justify-content:center; text-align:center; padding:7vw;
background:radial-gradient(120% 90% at 50% 38%, rgba(12,16,34,.25), rgba(7,8,16,.74)); }
.overlay.hidden { display:none; }
.am { font-size:clamp(14px,2vw,19px); letter-spacing:.32em; opacity:.72; margin-bottom:12px; }
h1 { font-size:clamp(36px,8vw,82px); font-weight:500; letter-spacing:.02em;
text-shadow:0 4px 50px rgba(0,0,0,.6); line-height:1; }
.desc { font-size:clamp(15px,2.1vw,20px); opacity:.9; margin-top:18px; max-width:560px; line-height:1.65; }
.cta { margin-top:32px; font-size:clamp(14px,1.9vw,18px); letter-spacing:.18em;
text-transform:uppercase; color:#f2c879; border:1px solid rgba(242,200,121,.65);
padding:14px 28px; border-radius:40px; animation:glow 2.4s ease-in-out infinite; }
@keyframes glow { 0%,100%{box-shadow:0 0 0 rgba(242,200,121,0);opacity:.82} 50%{box-shadow:0 0 28px rgba(242,200,121,.4);opacity:1} }
.small { margin-top:16px; font-size:13px; letter-spacing:.1em; opacity:.55; }
.score-big { font-size:clamp(52px,12vw,118px); color:#f2c879; line-height:1; margin:4px 0 2px;
text-shadow:0 4px 40px rgba(242,200,121,.25); }
.sub { font-size:13px; letter-spacing:.25em; text-transform:uppercase; opacity:.6; }
/* Уважение к настройке «меньше движения» (вестибулярная доступность) */
@media (prefers-reduced-motion: reduce){ *{animation-duration:.001ms !important; animation-iteration-count:1 !important; transition-duration:.001ms !important; scroll-behavior:auto !important;} }
#langs{position:fixed;right:14px;bottom:12px;z-index:9999;display:flex;gap:5px;}
#langs button{font-family:Georgia,serif;font-size:12px;letter-spacing:.06em;color:rgba(255,255,255,.78);background:rgba(0,0,0,.4);border:1px solid rgba(255,255,255,.22);padding:7px 9px;border-radius:16px;cursor:pointer;-webkit-backdrop-filter:blur(4px);backdrop-filter:blur(4px);transition:.15s;}
#langs button.on{color:#0b0e18;background:#f2c879;border-color:#f2c879;font-weight:700;}
#langs button:focus-visible{outline:2px solid #f2c879;outline-offset:2px;}
</style>
</head>
<body>
<a href="index.html" style="position:fixed;left:14px;bottom:12px;z-index:9999;font-family:Georgia,serif;font-size:13px;letter-spacing:.08em;color:rgba(255,255,255,.78);background:rgba(0,0,0,.4);padding:8px 14px;border-radius:20px;border:1px solid rgba(255,255,255,.22);text-decoration:none;-webkit-backdrop-filter:blur(4px);backdrop-filter:blur(4px);">← Արցախ</a>
<div id="langs"><button data-l="hy">ՀԱՅ</button><button data-l="ru">РУС</button><button data-l="en">ENG</button></div>
<canvas id="game"></canvas>
<div id="hud">
<div><span class="label" data-t="score">Очки</span><b id="score">0</b></div>
<div style="text-align:center"><span class="label" data-t="poms">Гранаты</span><b class="pom" id="poms">0</b></div>
<div style="text-align:right"><span class="label" data-t="best">Рекорд</span><b id="best">0</b></div>
</div>
<div class="overlay" id="startScreen">
<div class="am" data-t="am">Արцախ · «край всадников»</div>
<h1 data-t="title">Всадник Арцаха</h1>
<div class="desc" data-t="desc">Скачи по родным горам, перепрыгивай камни и собирай гранаты. Чем дальше — тем быстрее.</div>
<div class="cta" data-t="cta">Нажми ПРОБЕЛ или тапни</div>
<div class="small" data-t="hint">Пробел · ↑ · клик · тап — прыжок (двойной прыжок в воздухе)</div>
</div>
<div class="overlay hidden" id="overScreen">
<div class="sub" data-t="overSub">Конец пути</div>
<div class="score-big" id="finalScore">0</div>
<div class="desc" id="finalLine">Хорошая скачка!</div>
<div class="cta" data-t="restart">Скакать снова</div>
</div>
<script>
"use strict";
const cv = document.getElementById('game');
const ctx = cv.getContext('2d');
const $ = id => document.getElementById(id);
/* ════════════ ЯЗЫК (3 языка) ════════════ */
function getLang(){ try{const v=localStorage.getItem('artsakh_lang'); if(v==='hy'||v==='ru'||v==='en')return v;}catch(e){} const n=(navigator.language||'ru').toLowerCase(); return n.startsWith('hy')?'hy':n.startsWith('en')?'en':'ru'; }
let lang=getLang();
const UI={
ru:{ score:'Очки', poms:'Гранаты', best:'Рекорд', am:'Արցախ · «край всадников»', title:'Всадник Арцаха',
desc:'Скачи по родным горам, перепрыгивай камни и собирай гранаты. Чем дальше — тем быстрее.',
cta:'Нажми ПРОБЕЛ или тапни', hint:'Пробел · ↑ · клик · тап — прыжок (двойной прыжок в воздухе)',
overSub:'Конец пути', restart:'Скакать снова', record:'Новый рекорд! Մենք ենք մեր սարերը 🇦🇲', gemsPre:'Гранатов собрано: ', gemsPost:'. Ещё разок?' },
hy:{ score:'Միավոր', poms:'Նուռ', best:'Ռեկորդ', am:'Արցախ · «հեծյալների երկիր»', title:'Արցախի հեծյալը',
desc:'Սլացի՛ր հայրենի սարերով, ցատկի՛ր քարերի վրայով և հավաքի՛ր նռներ։ Որքան հեռու՝ այնքան արագ։',
cta:'Սեղմի՛ր ԲԱՑԱՏԸ կամ հպի՛ր', hint:'Բացատ · ↑ · սեղմում · հպում՝ ցատկ (կրկնակի ցատկ օդում)',
overSub:'Ճանապարհի վերջը', restart:'Սլանալ նորից', record:'Նոր ռեկորդ։ Մենք ենք մեր սարերը 🇦🇲', gemsPre:'Հավաքված նուռ՝ ', gemsPost:'։ Եւս մեկ անգա՞մ' },
en:{ score:'Score', poms:'Pomegranates', best:'Best', am:'Արցախ · “land of horsemen”', title:'Rider of Artsakh',
desc:'Gallop the native mountains, leap over the stones and collect pomegranates. The farther you go, the faster it gets.',
cta:'Press SPACE or tap', hint:'Space · ↑ · click · tap — jump (double-jump in the air)',
overSub:'End of the road', restart:'Ride again', record:'New record! Մենք ենք մեր սարերը 🇦🇲', gemsPre:'Pomegranates collected: ', gemsPost:'. Once more?' }
};
function tr(k){ return (UI[lang]&&UI[lang][k]!=null)?UI[lang][k]:UI.ru[k]; }
function applyChrome(){
document.querySelectorAll('[data-t]').forEach(el=>{ const k=el.getAttribute('data-t'); if(UI[lang][k]!=null) el.textContent=UI[lang][k]; });
document.documentElement.lang=lang;
document.querySelectorAll('#langs button').forEach(b=>b.classList.toggle('on',b.getAttribute('data-l')===lang));
}
document.querySelectorAll('#langs button').forEach(b=>b.addEventListener('click',ev=>{ ev.stopPropagation(); lang=b.getAttribute('data-l'); try{localStorage.setItem('artsakh_lang',lang);}catch(e){} applyChrome(); }));
applyChrome();
let W, H, s, groundY, skyGrad;
function resize(){
const dpr = Math.min(window.devicePixelRatio || 1, 2);
W = cv.clientWidth || window.innerWidth || 800;
H = cv.clientHeight || window.innerHeight || 600;
cv.width = W * dpr; cv.height = H * dpr;
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
s = Math.max(0.62, Math.min(H / 720, W / 1180));
groundY = H * 0.80;
player.x = W * 0.24;
if (state !== 'play') player.y = groundY;
skyGrad = ctx.createLinearGradient(0, 0, 0, groundY);
skyGrad.addColorStop(0, '#6db0dd');
skyGrad.addColorStop(0.55,'#a9d2d6');
skyGrad.addColorStop(1, '#ecdcaa');
}
addEventListener('resize', resize);
/* ───────── состояние ───────── */
let state = 'start'; // start | play | over
let scrollX = 0, bgX = 0, speed = 0, baseSpeed = 0, runTime = 0, t = 0, overTime = 0;
let poms = 0;
// Рекорд в localStorage. Через file:// некоторые браузеры (Safari) бросают
// ошибку при доступе — поэтому всё в try/catch, чтобы игра никогда не падала.
function loadBest(){ try { return (+localStorage.getItem('artsakh_best')) || 0; } catch(e){ return 0; } }
function saveBest(v){ try { localStorage.setItem('artsakh_best', v); } catch(e){} }
let best = loadBest();
$('best').textContent = best;
const player = { x:0, y:0, vy:0, jumps:0, legPhase:0 };
let obstacles = [], gems = [], particles = [], monasteries = [], clouds = [];
let obSpawnAt = 0, gemSpawnAt = 0, monSpawnAt = 0;
for (let i = 0; i < 4; i++) clouds.push({ x:Math.random(), y:Math.random()*0.32+0.06, sc:0.7+Math.random()*0.8 });
/* ───────── звук (синтез, без файлов) ───────── */
let actx = null;
function ensureAudio(){
if (!actx) { try { actx = new (window.AudioContext||window.webkitAudioContext)(); } catch(e){} }
if (actx && actx.state === 'suspended') actx.resume();
}
function tone(f0,f1,dur,type,vol,when){
const o=actx.createOscillator(), g=actx.createGain();
o.type=type; o.frequency.setValueAtTime(f0,when);
o.frequency.exponentialRampToValueAtTime(Math.max(1,f1),when+dur);
g.gain.setValueAtTime(vol,when); g.gain.exponentialRampToValueAtTime(0.0001,when+dur);
o.connect(g).connect(actx.destination); o.start(when); o.stop(when+dur);
}
function noise(dur,when,vol){
const n=Math.floor(actx.sampleRate*dur), buf=actx.createBuffer(1,n,actx.sampleRate), d=buf.getChannelData(0);
for(let i=0;i<n;i++) d[i]=(Math.random()*2-1)*(1-i/n);
const src=actx.createBufferSource(); src.buffer=buf;
const g=actx.createGain(); g.gain.setValueAtTime(vol,when); g.gain.exponentialRampToValueAtTime(0.0001,when+dur);
src.connect(g).connect(actx.destination); src.start(when);
}
function sfx(type){
if(!actx) return; const now=actx.currentTime;
try{
if(type==='jump'){ tone(360,560,0.14,'square',0.05,now); }
else if(type==='collect'){ tone(680,1000,0.09,'sine',0.10,now); tone(1000,1360,0.09,'sine',0.06,now+0.05); }
else if(type==='hit'){ tone(190,55,0.42,'sawtooth',0.16,now); noise(0.28,now,0.14); }
}catch(e){}
}
/* ───────── физика ───────── */
const G = () => 2500 * s;
const JUMP = () => -900 * s;
/* ───────── ввод ───────── */
function tap(){
ensureAudio();
if (state === 'start') startGame();
else if (state === 'play') jump();
else if (state === 'over' && performance.now() - overTime > 650) startGame();
}
function jump(){
if (player.jumps < 2){
player.vy = player.jumps === 0 ? JUMP() : JUMP()*0.82;
player.jumps++; sfx('jump');
burst(player.x - 12*s, player.y, 6, 'dust');
}
}
addEventListener('keydown', e => { if(e.code==='Space'||e.code==='ArrowUp'){ e.preventDefault(); tap(); } });
addEventListener('pointerdown', () => tap());
/* ───────── управление игрой ───────── */
function startGame(){
state='play'; scrollX=0; runTime=0; baseSpeed=360*s; speed=baseSpeed; poms=0;
obstacles=[]; gems=[]; particles=[]; monasteries=[];
player.y=groundY; player.vy=0; player.jumps=0;
obSpawnAt=700*s; gemSpawnAt=360*s; monSpawnAt=900*s;
$('startScreen').classList.add('hidden');
$('overScreen').classList.add('hidden');
}
function gameOver(){
state='over'; overTime=performance.now(); sfx('hit');
burst(player.x, player.y-20*s, 24, 'dust');
const sc=scoreVal(), record=sc>best;
if(record){ best=sc; saveBest(best); $('best').textContent=best; }
$('finalScore').textContent=sc;
$('finalLine').textContent = (record && sc>0)
? tr('record')
: tr('gemsPre') + poms + tr('gemsPost');
$('overScreen').classList.remove('hidden');
}
const scoreVal = () => Math.floor(scrollX/(38*s)) + poms*10;
/* ───────── частицы ───────── */
function burst(x,y,n,kind){
for(let i=0;i<n;i++){
const a=Math.random()*Math.PI*2, sp=(kind==='spark'?120:80)*s*(0.4+Math.random());
particles.push({
x,y, vx:Math.cos(a)*sp - (kind==='dust'?60*s:0), vy:Math.sin(a)*sp - (kind==='spark'?80*s:20*s),
g:(kind==='spark'?260:520)*s, life:0.5+Math.random()*0.4, max:0.9,
r:(kind==='spark'?3:5)*s*(0.6+Math.random()),
c: kind==='spark' ? (Math.random()<0.5?'#ffd27a':'#ff7a86') : '#9c8a66'
});
}
}
/* ───────── спавн ───────── */
function spawnObstacle(){
const h=(42+Math.random()*46)*s, w=(30+Math.random()*30)*s;
obstacles.push({ x:W+w, w, h });
}
function spawnGem(){
const high = Math.random() < 0.55;
const y = high ? groundY-(95+Math.random()*70)*s : groundY-(26+Math.random()*18)*s;
gems.push({ x:W+20*s, y, r:13*s, bob:Math.random()*6.28 });
}
function spawnMonastery(){ monasteries.push({ x:W+120*s, scale:0.85+Math.random()*0.5 }); }
/* ───────── обновление ───────── */
function update(dt){
t += dt;
if (state === 'play'){
runTime += dt;
speed = baseSpeed + Math.min(560*s, runTime*24*s);
scrollX += speed*dt; bgX += speed*dt;
player.vy += G()*dt; player.y += player.vy*dt;
if (player.y >= groundY){
if (player.vy > 900*s) burst(player.x-8*s, groundY, 7, 'dust');
player.y = groundY; player.vy = 0; player.jumps = 0;
}
const air = player.y < groundY - 1;
player.legPhase += dt * (air ? 6 : speed/(24*s));
if (scrollX >= obSpawnAt){ spawnObstacle(); obSpawnAt = scrollX + speed*(0.95+Math.random()*1.05); }
if (scrollX >= gemSpawnAt){ spawnGem(); gemSpawnAt = scrollX + speed*(0.5+Math.random()*0.85); }
if (scrollX >= monSpawnAt){ spawnMonastery(); monSpawnAt = scrollX + (1500+Math.random()*1700)*s; }
for (const o of obstacles) o.x -= speed*dt;
for (const g of gems) g.x -= speed*dt;
for (const m of monasteries) m.x -= speed*0.45*dt;
obstacles = obstacles.filter(o => o.x + o.w > -30);
gems = gems.filter(g => g.x + g.r > -30);
monasteries = monasteries.filter(m => m.x > -260*s);
// столкновения
const hx=player.x-24*s, hy=player.y-44*s, hw=42*s, hh=40*s;
for (const o of obstacles){
const ox=o.x+5*s, oy=groundY-o.h, ow=o.w-10*s, oh=o.h;
if (hx<ox+ow && hx+hw>ox && hy<oy+oh && hy+hh>oy){ gameOver(); break; }
}
for (let i=gems.length-1; i>=0; i--){
const g=gems[i];
const cx=Math.max(hx,Math.min(g.x,hx+hw)), cy=Math.max(hy,Math.min(g.y,hy+hh));
if ((g.x-cx)**2+(g.y-cy)**2 < (g.r+4*s)**2){
gems.splice(i,1); poms++; sfx('collect'); burst(g.x,g.y,10,'spark');
}
}
} else {
bgX += 95*s*dt;
player.y = groundY;
player.legPhase += dt*7;
}
for (const c of clouds){ c.x -= (8*s/W)*dt*(0.4+c.sc*0.3); if (c.x < -0.2) c.x = 1.2; }
for (const p of particles){ p.x+=p.vx*dt; p.y+=p.vy*dt; p.vy+=p.g*dt; p.life-=dt; }
particles = particles.filter(p => p.life > 0);
$('score').textContent = state==='start' ? 0 : scoreVal();
$('poms').textContent = poms;
}
/* ───────── отрисовка ───────── */
function ridge(yBase, amp, color, par){
ctx.fillStyle=color; ctx.beginPath(); ctx.moveTo(0,H);
const off=bgX*par;
for (let x=0;x<=W;x+=10){
const wx=x+off;
const y=yBase - (Math.sin(wx*0.0042)*amp + Math.sin(wx*0.0119+1.3)*amp*0.42 + Math.sin(wx*0.027+0.6)*amp*0.12);
ctx.lineTo(x,y);
}
ctx.lineTo(W,H); ctx.closePath(); ctx.fill();
}
function drawSun(){
const sx=W*0.78, sy=H*0.2;
const gr=ctx.createRadialGradient(sx,sy,4,sx,sy,120*s);
gr.addColorStop(0,'rgba(255,246,214,0.95)'); gr.addColorStop(0.4,'rgba(255,238,190,0.35)'); gr.addColorStop(1,'rgba(255,238,190,0)');
ctx.fillStyle=gr; ctx.beginPath(); ctx.arc(sx,sy,120*s,0,6.28); ctx.fill();
ctx.fillStyle='#fff4d2'; ctx.beginPath(); ctx.arc(sx,sy,40*s,0,6.28); ctx.fill();
}
function drawClouds(){
ctx.fillStyle='rgba(255,255,255,0.5)';
for (const c of clouds){
const x=c.x*W, y=c.y*H, r=20*s*c.sc;
ctx.beginPath();
ctx.arc(x,y,r,0,6.28); ctx.arc(x+r,y+4*s,r*0.8,0,6.28); ctx.arc(x-r,y+5*s,r*0.7,0,6.28); ctx.arc(x+r*0.4,y-r*0.5,r*0.7,0,6.28);
ctx.fill();
}
}
function drawMonastery(m){
const x=m.x, baseY=H*0.705, sc=m.scale*s;
ctx.fillStyle='#496857';
ctx.fillRect(x-14*sc, baseY-24*sc, 28*sc, 24*sc);
ctx.fillRect(x-7*sc, baseY-40*sc, 14*sc, 16*sc);
ctx.beginPath(); ctx.moveTo(x-9*sc,baseY-40*sc); ctx.lineTo(x,baseY-55*sc); ctx.lineTo(x+9*sc,baseY-40*sc); ctx.closePath(); ctx.fill();
ctx.strokeStyle='#496857'; ctx.lineWidth=2*sc; ctx.lineCap='round';
ctx.beginPath(); ctx.moveTo(x,baseY-55*sc); ctx.lineTo(x,baseY-62*sc); ctx.moveTo(x-3*sc,baseY-58.5*sc); ctx.lineTo(x+3*sc,baseY-58.5*sc); ctx.stroke();
}
function drawGround(){
const gr=ctx.createLinearGradient(0,groundY,0,H);
gr.addColorStop(0,'#9ec06a'); gr.addColorStop(1,'#6f8f49');
ctx.fillStyle=gr; ctx.fillRect(0,groundY,W,H-groundY);
// травинки, бегущие со скоростью мира
ctx.strokeStyle='rgba(60,80,40,0.5)'; ctx.lineWidth=2*s; ctx.lineCap='round';
const step=46*s, off=(bgX)% step;
for (let x=-off; x<W; x+=step){
const yy=groundY+10*s;
ctx.beginPath(); ctx.moveTo(x,yy); ctx.lineTo(x-3*s,yy-9*s); ctx.moveTo(x,yy); ctx.lineTo(x+4*s,yy-11*s); ctx.stroke();
}
}
function drawRock(o){
const x=o.x,w=o.w,h=o.h;
ctx.fillStyle='#2a2128';
ctx.beginPath();
ctx.moveTo(x,groundY);
ctx.lineTo(x+w*0.13, groundY-h*0.68);
ctx.lineTo(x+w*0.42, groundY-h);
ctx.lineTo(x+w*0.72, groundY-h*0.74);
ctx.lineTo(x+w, groundY-h*0.32);
ctx.lineTo(x+w, groundY);
ctx.closePath(); ctx.fill();
ctx.fillStyle='rgba(255,226,180,0.12)';
ctx.beginPath();
ctx.moveTo(x+w*0.42,groundY-h); ctx.lineTo(x+w*0.72,groundY-h*0.74); ctx.lineTo(x+w*0.52,groundY-h*0.52);
ctx.closePath(); ctx.fill();
}
function drawGem(g){
const by=g.y+Math.sin(t*3+g.bob)*3*s;
const gr=ctx.createRadialGradient(g.x,by,2,g.x,by,g.r*2.3);
gr.addColorStop(0,'rgba(255,120,120,0.4)'); gr.addColorStop(1,'rgba(255,120,120,0)');
ctx.fillStyle=gr; ctx.beginPath(); ctx.arc(g.x,by,g.r*2.3,0,6.28); ctx.fill();
ctx.fillStyle='#c52c39'; ctx.beginPath(); ctx.arc(g.x,by,g.r,0,6.28); ctx.fill();
ctx.fillStyle='#a11f2b'; ctx.beginPath(); ctx.arc(g.x+g.r*0.3,by+g.r*0.2,g.r*0.66,0,6.28); ctx.fill();
ctx.fillStyle='#6f8a36';
ctx.beginPath();
ctx.moveTo(g.x-5*s,by-g.r+1*s); ctx.lineTo(g.x-2*s,by-g.r-6*s); ctx.lineTo(g.x,by-g.r);
ctx.lineTo(g.x+2*s,by-g.r-6*s); ctx.lineTo(g.x+5*s,by-g.r+1*s); ctx.closePath(); ctx.fill();
ctx.fillStyle='rgba(255,222,210,0.65)'; ctx.beginPath(); ctx.arc(g.x-g.r*0.32,by-g.r*0.34,g.r*0.22,0,6.28); ctx.fill();
}
function leg(rootx,rooty,ang,len,w,c){
const kx=rootx+Math.cos(ang)*len*0.5, ky=rooty+Math.sin(ang)*len*0.5;
const fx=kx+Math.cos(ang+0.35)*len*0.5, fy=ky+Math.sin(ang+0.35)*len*0.5;
ctx.strokeStyle=c; ctx.lineWidth=w; ctx.lineCap='round';
ctx.beginPath(); ctx.moveTo(rootx,rooty); ctx.lineTo(kx,ky); ctx.lineTo(fx,fy); ctx.stroke();
}
function drawHorse(px,py,phase,air){
const c='#23191d';
ctx.fillStyle='rgba(20,12,16,0.18)';
ctx.beginPath(); ctx.ellipse(px,py+2*s,30*s,7*s,0,0,6.28); ctx.fill();
const bob = air?0:Math.sin(phase*2)*1.6*s;
ctx.save(); ctx.translate(px, py-22*s+bob);
const set=[{x:16*s,off:0},{x:11*s,off:Math.PI},{x:-12*s,off:Math.PI*0.6},{x:-17*s,off:Math.PI*1.6}];
for (const L of set){
let ang = air ? Math.PI/2 + (L.x>0?0.9:-0.7) : Math.PI/2 + Math.sin(phase+L.off)*0.55;
leg(L.x, 9*s, ang, 21*s, 5.5*s, c);
}
ctx.fillStyle=c;
ctx.beginPath(); ctx.ellipse(-2*s,0,27*s,13*s,0,0,6.28); ctx.fill();
ctx.beginPath(); ctx.arc(-22*s,-2*s,11*s,0,6.28); ctx.fill();
ctx.beginPath(); ctx.arc(20*s,-3*s,11*s,0,6.28); ctx.fill();
ctx.beginPath();
ctx.moveTo(22*s,-6*s);
ctx.quadraticCurveTo(34*s,-20*s,40*s,-24*s);
ctx.lineTo(46*s,-22*s);
ctx.quadraticCurveTo(48*s,-17*s,43*s,-15*s);
ctx.lineTo(39*s,-14*s);
ctx.quadraticCurveTo(33*s,-9*s,26*s,-2*s);
ctx.closePath(); ctx.fill();
ctx.beginPath(); ctx.moveTo(37*s,-24*s); ctx.lineTo(39*s,-31*s); ctx.lineTo(43*s,-23*s); ctx.closePath(); ctx.fill();
// хвост
ctx.beginPath();
ctx.moveTo(-30*s,-5*s);
ctx.quadraticCurveTo(-46*s,-2*s+Math.sin(phase*1.5)*3*s,-43*s,16*s+Math.sin(phase*1.5)*3*s);
ctx.quadraticCurveTo(-39*s,4*s,-29*s,2*s); ctx.closePath(); ctx.fill();
// грива
ctx.fillStyle='#181014';
ctx.beginPath(); ctx.moveTo(24*s,-8*s); ctx.quadraticCurveTo(31*s,-23*s,39*s,-24*s);
ctx.lineTo(36*s,-18*s); ctx.quadraticCurveTo(30*s,-12*s,26*s,-4*s); ctx.closePath(); ctx.fill();
// всадник
const rb = air?0:Math.sin(phase*2)*1.2*s;
ctx.save(); ctx.translate(2*s,-10*s+rb);
ctx.fillStyle='#2c2024';
ctx.beginPath(); ctx.ellipse(0,-6*s,7*s,10*s,-0.15,0,6.28); ctx.fill();
ctx.beginPath(); ctx.arc(2*s,-18*s,5.2*s,0,6.28); ctx.fill();
ctx.strokeStyle='#2c2024'; ctx.lineWidth=3.4*s; ctx.lineCap='round';
ctx.beginPath(); ctx.moveTo(2*s,-7*s); ctx.lineTo(17*s,-2*s); ctx.stroke();
ctx.restore();
ctx.restore();
}
function draw(){
ctx.fillStyle=skyGrad; ctx.fillRect(0,0,W,groundY);
drawSun();
drawClouds();
ridge(H*0.50, 72*s, 'rgba(138,166,194,0.85)', 0.12);
ridge(H*0.58, 92*s, '#6f9486', 0.25);
for (const m of monasteries) drawMonastery(m);
ridge(H*0.72, 60*s, '#557a4f', 0.45);
drawGround();
for (const o of obstacles) drawRock(o);
for (const g of gems) drawGem(g);
drawHorse(player.x, player.y, player.legPhase, player.y < groundY-1);
for (const p of particles){
ctx.globalAlpha = Math.max(0, p.life/p.max);
ctx.fillStyle = p.c;
ctx.beginPath(); ctx.arc(p.x,p.y,p.r,0,6.28); ctx.fill();
}
ctx.globalAlpha = 1;
// лёгкая виньетка
const vg=ctx.createRadialGradient(W/2,H*0.45,H*0.3,W/2,H*0.5,H*0.85);
vg.addColorStop(0,'rgba(0,0,0,0)'); vg.addColorStop(1,'rgba(0,0,0,0.22)');
ctx.fillStyle=vg; ctx.fillRect(0,0,W,H);
}
/* ───────── главный цикл ───────── */
let last = performance.now();
function frame(now){
let dt=(now-last)/1000; last=now; if(dt>0.05) dt=0.05;
update(dt); draw();
requestAnimationFrame(frame);
}
resize();
addEventListener('load', resize);
requestAnimationFrame(frame);
</script>
</body>
</html>