Nafiul Huda commited on
Update public/index.html
Browse files- public/index.html +747 -352
public/index.html
CHANGED
|
@@ -1,384 +1,779 @@
|
|
| 1 |
-
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>
|
| 7 |
<style>
|
| 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 |
</style>
|
| 33 |
</head>
|
| 34 |
<body>
|
| 35 |
-
<canvas id="gameCanvas"></canvas>
|
| 36 |
|
| 37 |
-
<div id="
|
| 38 |
-
<
|
| 39 |
-
<div id="scoreVal" style="font-size: 24px; font-weight: bold;">0</div>
|
| 40 |
-
<div style="font-size: 14px; color: #888;">Score</div>
|
| 41 |
-
</div>
|
| 42 |
-
|
| 43 |
-
<div id="statOverlay" style="display:none;">
|
| 44 |
-
<div style="font-weight:bold; margin-bottom:5px; color:#ddd;">UPGRADES (<span id="pts">0</span>)</div>
|
| 45 |
-
<div class="upg-btn" onclick="upgrade('spd')">[1] Speed</div>
|
| 46 |
-
<div class="upg-btn" onclick="upgrade('dmg')">[2] Damage</div>
|
| 47 |
-
<div class="upg-btn" onclick="upgrade('rld')">[3] Reload</div>
|
| 48 |
-
<div class="upg-btn" onclick="upgrade('reg')">[4] Regen</div>
|
| 49 |
-
</div>
|
| 50 |
|
| 51 |
-
<div id="
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
<
|
| 57 |
-
<input type="text" id="nameInput" placeholder="Pilot Name" maxlength="12">
|
| 58 |
-
<button onclick="startGame()">LAUNCH</button>
|
| 59 |
</div>
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
|
| 82 |
-
let mouseX = 0, mouseY = 0;
|
| 83 |
|
| 84 |
-
//
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
function resize() {
|
| 94 |
-
canvas.width = window.innerWidth;
|
| 95 |
-
canvas.height = window.innerHeight;
|
| 96 |
-
}
|
| 97 |
-
window.onresize = resize;
|
| 98 |
-
resize();
|
| 99 |
-
|
| 100 |
-
// Generate Background Stars
|
| 101 |
-
for(let i=0; i<200; i++) {
|
| 102 |
-
stars.push({
|
| 103 |
-
x: Math.random() * mapSize,
|
| 104 |
-
y: Math.random() * mapSize,
|
| 105 |
-
z: Math.random() * 2 + 0.5 // Depth
|
| 106 |
-
});
|
| 107 |
}
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
const osc = actx.createOscillator();
|
| 113 |
-
const gain = actx.createGain();
|
| 114 |
-
osc.connect(gain);
|
| 115 |
-
gain.connect(actx.destination);
|
| 116 |
-
|
| 117 |
-
const now = actx.currentTime;
|
| 118 |
-
|
| 119 |
-
if (type === 'shoot') {
|
| 120 |
-
osc.type = 'triangle';
|
| 121 |
-
osc.frequency.setValueAtTime(400, now);
|
| 122 |
-
osc.frequency.exponentialRampToValueAtTime(100, now + 0.1);
|
| 123 |
-
gain.gain.setValueAtTime(0.1, now);
|
| 124 |
-
gain.gain.exponentialRampToValueAtTime(0.01, now + 0.1);
|
| 125 |
-
osc.start(now);
|
| 126 |
-
osc.stop(now + 0.1);
|
| 127 |
-
} else if (type === 'exp') { // Explosion
|
| 128 |
-
osc.type = 'sawtooth';
|
| 129 |
-
osc.frequency.setValueAtTime(100, now);
|
| 130 |
-
osc.frequency.exponentialRampToValueAtTime(10, now + 0.2);
|
| 131 |
-
gain.gain.setValueAtTime(0.2, now);
|
| 132 |
-
gain.gain.exponentialRampToValueAtTime(0.01, now + 0.2);
|
| 133 |
-
osc.start(now);
|
| 134 |
-
osc.stop(now + 0.2);
|
| 135 |
-
} else if (type === 'lvl') { // Level Up
|
| 136 |
-
osc.type = 'sine';
|
| 137 |
-
osc.frequency.setValueAtTime(440, now);
|
| 138 |
-
osc.frequency.setValueAtTime(660, now + 0.1);
|
| 139 |
-
osc.frequency.setValueAtTime(880, now + 0.2);
|
| 140 |
-
gain.gain.setValueAtTime(0.1, now);
|
| 141 |
-
gain.gain.linearRampToValueAtTime(0, now + 0.4);
|
| 142 |
-
osc.start(now);
|
| 143 |
-
osc.stop(now + 0.4);
|
| 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 |
-
socket.on('dead', () => {
|
| 190 |
-
particles.push({x: me.x, y: me.y, vx:0, vy:0, color:'red', life:50, size:50}); // Big boom visual
|
| 191 |
-
playSound('exp');
|
| 192 |
-
});
|
| 193 |
-
|
| 194 |
-
// === INPUTS ===
|
| 195 |
-
function startGame() {
|
| 196 |
-
const name = document.getElementById('nameInput').value || 'Pilot';
|
| 197 |
-
socket.emit('join', name);
|
| 198 |
-
document.getElementById('startScreen').style.display = 'none';
|
| 199 |
-
document.getElementById('statOverlay').style.display = 'block';
|
| 200 |
-
|
| 201 |
-
// Start sending inputs
|
| 202 |
-
setInterval(() => {
|
| 203 |
-
if(!me) return;
|
| 204 |
-
const angle = Math.atan2(mouseY - canvas.height/2, mouseX - canvas.width/2);
|
| 205 |
-
|
| 206 |
-
socket.emit('input', {
|
| 207 |
-
u: keys.w,
|
| 208 |
-
d: keys.s,
|
| 209 |
-
l: keys.a,
|
| 210 |
-
r: keys.d,
|
| 211 |
-
s: isMouseDown,
|
| 212 |
-
angle: angle
|
| 213 |
-
});
|
| 214 |
-
|
| 215 |
-
if(isMouseDown) playSound('shoot');
|
| 216 |
-
}, 1000/30); // 30hz Input rate
|
| 217 |
}
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
}
|
| 222 |
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
if(e.key === '1') upgrade('spd');
|
| 230 |
-
if(e.key === '2') upgrade('dmg');
|
| 231 |
-
if(e.key === '3') upgrade('rld');
|
| 232 |
-
if(e.key === '4') upgrade('reg');
|
| 233 |
-
};
|
| 234 |
-
|
| 235 |
-
window.onkeyup = (e) => {
|
| 236 |
-
if(e.key === 'w' || e.key === 'ArrowUp') keys.w = false;
|
| 237 |
-
if(e.key === 's' || e.key === 'ArrowDown') keys.s = false;
|
| 238 |
-
if(e.key === 'a' || e.key === 'ArrowLeft') keys.a = false;
|
| 239 |
-
if(e.key === 'd' || e.key === 'ArrowRight') keys.d = false;
|
| 240 |
-
};
|
| 241 |
-
|
| 242 |
-
window.onmousemove = (e) => { mouseX = e.clientX; mouseY = e.clientY; };
|
| 243 |
-
window.onmousedown = () => isMouseDown = true;
|
| 244 |
-
window.onmouseup = () => isMouseDown = false;
|
| 245 |
-
|
| 246 |
-
// === RENDER LOOP ===
|
| 247 |
-
function draw() {
|
| 248 |
-
// Clear
|
| 249 |
-
ctx.fillStyle = '#050510';
|
| 250 |
-
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
| 251 |
-
|
| 252 |
-
// Camera follow
|
| 253 |
-
if (me) {
|
| 254 |
-
// Smooth camera
|
| 255 |
-
camX += (me.x - canvas.width/2 - camX) * 0.1;
|
| 256 |
-
camY += (me.y - canvas.height/2 - camY) * 0.1;
|
| 257 |
-
}
|
| 258 |
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
// Draw Background Stars (Parallax)
|
| 263 |
-
ctx.fillStyle = '#fff';
|
| 264 |
-
stars.forEach(s => {
|
| 265 |
-
const px = (s.x - camX * (s.z * 0.1)) % mapSize;
|
| 266 |
-
const py = (s.y - camY * (s.z * 0.1)) % mapSize;
|
| 267 |
-
// Wrap visual
|
| 268 |
-
const wrapX = px < 0 ? px + mapSize : px;
|
| 269 |
-
const wrapY = py < 0 ? py + mapSize : py;
|
| 270 |
-
|
| 271 |
-
ctx.globalAlpha = s.z * 0.5;
|
| 272 |
-
ctx.beginPath();
|
| 273 |
-
ctx.arc(wrapX, wrapY, s.z, 0, Math.PI*2);
|
| 274 |
-
ctx.fill();
|
| 275 |
-
});
|
| 276 |
-
ctx.globalAlpha = 1;
|
| 277 |
-
|
| 278 |
-
// Draw Map Borders
|
| 279 |
-
ctx.strokeStyle = '#f00';
|
| 280 |
-
ctx.lineWidth = 5;
|
| 281 |
-
ctx.strokeRect(0,0, mapSize, mapSize);
|
| 282 |
-
|
| 283 |
-
// Draw Orbs
|
| 284 |
-
orbs.forEach(o => {
|
| 285 |
-
ctx.fillStyle = `hsl(${Date.now()/20 % 360}, 100%, 50%)`;
|
| 286 |
-
ctx.shadowBlur = 10;
|
| 287 |
-
ctx.shadowColor = ctx.fillStyle;
|
| 288 |
-
ctx.beginPath();
|
| 289 |
-
ctx.arc(o.x, o.y, 4, 0, Math.PI*2);
|
| 290 |
-
ctx.fill();
|
| 291 |
-
ctx.shadowBlur = 0;
|
| 292 |
-
});
|
| 293 |
-
|
| 294 |
-
// Draw Asteroids
|
| 295 |
-
ctx.fillStyle = '#334';
|
| 296 |
-
ctx.strokeStyle = '#556';
|
| 297 |
-
ctx.lineWidth = 3;
|
| 298 |
-
asteroids.forEach(a => {
|
| 299 |
-
ctx.beginPath();
|
| 300 |
-
ctx.arc(a.x, a.y, a.r, 0, Math.PI*2);
|
| 301 |
-
ctx.fill();
|
| 302 |
-
ctx.stroke();
|
| 303 |
-
});
|
| 304 |
-
|
| 305 |
-
// Draw Bullets
|
| 306 |
-
ctx.fillStyle = '#ff9';
|
| 307 |
-
ctx.shadowBlur = 5;
|
| 308 |
-
ctx.shadowColor = '#ff0';
|
| 309 |
-
bullets.forEach(b => {
|
| 310 |
-
ctx.beginPath();
|
| 311 |
-
ctx.arc(b.x, b.y, 3, 0, Math.PI*2);
|
| 312 |
-
ctx.fill();
|
| 313 |
-
});
|
| 314 |
-
ctx.shadowBlur = 0;
|
| 315 |
-
|
| 316 |
-
// Draw Players
|
| 317 |
-
players.forEach(p => {
|
| 318 |
-
const isMe = p.id === myId;
|
| 319 |
-
|
| 320 |
-
ctx.save();
|
| 321 |
-
ctx.translate(p.x, p.y);
|
| 322 |
-
ctx.rotate(p.a);
|
| 323 |
-
|
| 324 |
-
// Ship Body
|
| 325 |
-
ctx.fillStyle = isMe ? '#00f260' : '#f05053';
|
| 326 |
-
ctx.strokeStyle = '#fff';
|
| 327 |
-
ctx.lineWidth = 2;
|
| 328 |
-
|
| 329 |
-
ctx.beginPath();
|
| 330 |
-
ctx.moveTo(15, 0);
|
| 331 |
-
ctx.lineTo(-10, 10);
|
| 332 |
-
ctx.lineTo(-5, 0);
|
| 333 |
-
ctx.lineTo(-10, -10);
|
| 334 |
-
ctx.closePath();
|
| 335 |
-
ctx.fill();
|
| 336 |
-
ctx.stroke();
|
| 337 |
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
ctx.fillStyle = '#0f0';
|
| 355 |
-
ctx.fillRect(p.x - 20, p.y + 25, 40 * hpPct, 6);
|
| 356 |
-
|
| 357 |
-
// Name
|
| 358 |
-
ctx.fillStyle = '#fff';
|
| 359 |
-
ctx.font = '12px Arial';
|
| 360 |
-
ctx.textAlign = 'center';
|
| 361 |
-
ctx.fillText(p.nm, p.x, p.y - 25);
|
| 362 |
-
});
|
| 363 |
-
|
| 364 |
-
// Particles (Explosions)
|
| 365 |
-
for(let i=particles.length-1; i>=0; i--) {
|
| 366 |
-
const p = particles[i];
|
| 367 |
-
p.life--;
|
| 368 |
-
p.size *= 0.95;
|
| 369 |
-
ctx.globalAlpha = p.life / 20;
|
| 370 |
-
ctx.fillStyle = p.color;
|
| 371 |
-
ctx.beginPath();
|
| 372 |
-
ctx.arc(p.x, p.y, p.size, 0, Math.PI*2);
|
| 373 |
-
ctx.fill();
|
| 374 |
-
if(p.life <= 0) particles.splice(i, 1);
|
| 375 |
}
|
| 376 |
-
|
| 377 |
-
ctx.restore();
|
| 378 |
-
requestAnimationFrame(draw);
|
| 379 |
}
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
</body>
|
| 384 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
|
| 6 |
+
<title>Ascent: Multiplayer</title>
|
| 7 |
<style>
|
| 8 |
+
/* RESET & LAYOUT */
|
| 9 |
+
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
|
| 10 |
+
body { background-color: #000; overflow: hidden; width: 100vw; height: 100vh; display: flex; justify-content: center; align-items: center; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
|
| 11 |
|
| 12 |
+
/* GAME CONTAINER */
|
| 13 |
+
#game-container { position: relative; width: 100%; height: 100%; max-width: 50vh; max-height: 100vh; background: linear-gradient(180deg, #2d2347 0%, #5d426e 100%); overflow: hidden; box-shadow: 0 0 20px rgba(0,0,0,0.5); }
|
| 14 |
+
canvas { display: block; width: 100%; height: 100%; }
|
| 15 |
+
|
| 16 |
+
/* UI OVERLAY */
|
| 17 |
+
#ui-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
|
| 18 |
+
#score-container { position: absolute; top: 60px; right: 20px; text-align: right; }
|
| 19 |
+
#score { color: rgba(255, 255, 255, 0.9); font-size: 32px; font-weight: 900; text-shadow: 2px 2px 0px rgba(0,0,0,0.3); line-height: 1; }
|
| 20 |
+
#score-label { font-size: 14px; color: rgba(255,255,255,0.7); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 2px; }
|
| 21 |
+
#star-count { margin-top: 5px; font-size: 16px; color: #ffd700; font-weight: bold; text-shadow: 1px 1px 0 rgba(0,0,0,0.5); }
|
| 22 |
|
| 23 |
+
/* Powerups */
|
| 24 |
+
#powerups { position: absolute; top: 130px; right: 20px; display: flex; flex-direction: column; gap: 5px; align-items: flex-end; }
|
| 25 |
+
.powerup-badge { background: rgba(0,0,0,0.5); padding: 5px 10px; border-radius: 15px; color: #fff; font-size: 12px; font-weight: bold; display: none; }
|
| 26 |
+
#tutorial { position: absolute; top: 40%; width: 100%; text-align: center; color: rgba(255,255,255,0.6); font-size: 18px; font-weight: 600; animation: pulse 2s infinite; }
|
| 27 |
+
#pause-btn { position: absolute; top: 60px; left: 20px; font-size: 24px; color: white; pointer-events: auto; cursor: pointer; z-index: 20; }
|
| 28 |
+
|
| 29 |
+
/* MENUS */
|
| 30 |
+
.overlay-menu { display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(18, 14, 30, 0.95); flex-direction: column; justify-content: center; align-items: center; pointer-events: auto; z-index: 50; }
|
| 31 |
+
.overlay-menu h1 { color: #fff; font-size: 40px; margin-bottom: 20px; text-transform: uppercase; font-style: italic; }
|
| 32 |
+
.overlay-menu p { color: #ccc; margin-bottom: 30px; }
|
| 33 |
+
.btn { background: #fff; color: #2d2347; padding: 15px 40px; font-size: 20px; font-weight: bold; border-radius: 30px; border: none; cursor: pointer; text-transform: uppercase; box-shadow: 0 5px 15px rgba(0,0,0,0.3); transition: transform 0.1s; margin-top: 10px; }
|
| 34 |
+
.btn:active { transform: scale(0.95); }
|
| 35 |
+
|
| 36 |
+
/* LOGIN SCREEN */
|
| 37 |
+
#login-screen { display: flex; z-index: 100; }
|
| 38 |
+
#username-input { padding: 15px; font-size: 18px; border-radius: 10px; border: none; margin-bottom: 20px; text-align: center; width: 80%; max-width: 300px; font-family: inherit; }
|
| 39 |
+
|
| 40 |
+
/* SHOP STYLES */
|
| 41 |
+
.shop-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin-bottom: 20px; }
|
| 42 |
+
.shop-item { width: 60px; height: 60px; background: rgba(255,255,255,0.1); border-radius: 10px; display: flex; justify-content: center; align-items: center; cursor: pointer; border: 2px solid transparent; position: relative; }
|
| 43 |
+
.shop-item.selected { border-color: #00ff88; background: rgba(0,255,136,0.2); }
|
| 44 |
+
.shop-item.locked { opacity: 0.5; }
|
| 45 |
+
.shop-item .price { position: absolute; bottom: -20px; font-size: 10px; color: #ffd700; }
|
| 46 |
+
|
| 47 |
+
/* LEADERBOARD */
|
| 48 |
+
#leaderboard {
|
| 49 |
+
position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
|
| 50 |
+
background: rgba(0,0,0,0.3); padding: 8px 15px; border-radius: 15px;
|
| 51 |
+
color: white; font-size: 12px; pointer-events: none; width: 200px;
|
| 52 |
+
}
|
| 53 |
+
.lb-row { display: flex; justify-content: space-between; margin-bottom: 2px; }
|
| 54 |
+
.lb-rank { color: #ffd700; font-weight: bold; margin-right: 5px; }
|
| 55 |
+
|
| 56 |
+
@keyframes pulse { 0% { opacity: 0.4; transform: translateY(0); } 50% { opacity: 0.8; transform: translateY(-5px); } 100% { opacity: 0.4; transform: translateY(0); } }
|
| 57 |
</style>
|
| 58 |
</head>
|
| 59 |
<body>
|
|
|
|
| 60 |
|
| 61 |
+
<div id="game-container">
|
| 62 |
+
<canvas id="gameCanvas"></canvas>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
+
<div id="ui-layer">
|
| 65 |
+
<div id="pause-btn">❚❚</div>
|
| 66 |
+
|
| 67 |
+
<!-- LEADERBOARD UI -->
|
| 68 |
+
<div id="leaderboard">
|
| 69 |
+
<div style="text-align:center; color:#ccc; font-size:10px; margin-bottom:4px;">LIVE RANKING</div>
|
| 70 |
+
<div id="lb-content">Loading...</div>
|
| 71 |
+
</div>
|
| 72 |
+
|
| 73 |
+
<div id="score-container">
|
| 74 |
+
<div id="score-label">Height</div>
|
| 75 |
+
<div id="score"><span id="score-value">0</span>m</div>
|
| 76 |
+
<div id="star-count">★ <span id="stars-value">0</span></div>
|
| 77 |
+
</div>
|
| 78 |
+
|
| 79 |
+
<div id="powerups">
|
| 80 |
+
<div id="badge-shield" class="powerup-badge" style="color:#00ffff">🛡️ SAFE</div>
|
| 81 |
+
<div id="badge-rocket" class="powerup-badge" style="color:#ff4444">🚀 BOOST</div>
|
| 82 |
+
<div id="badge-slow" class="powerup-badge" style="color:#ffff00">⏳ SLOW</div>
|
| 83 |
+
</div>
|
| 84 |
+
|
| 85 |
+
<div id="tutorial">DRAG TO JUMP</div>
|
| 86 |
+
|
| 87 |
+
<!-- LOGIN SCREEN -->
|
| 88 |
+
<div id="login-screen" class="overlay-menu">
|
| 89 |
+
<h1>Ascent MP</h1>
|
| 90 |
+
<input type="text" id="username-input" placeholder="Enter Username" maxlength="12">
|
| 91 |
+
<button class="btn" id="start-btn">PLAY</button>
|
| 92 |
+
</div>
|
| 93 |
+
|
| 94 |
+
<!-- GAME OVER MENU -->
|
| 95 |
+
<div id="game-over" class="overlay-menu">
|
| 96 |
+
<h1>Fell Down!</h1>
|
| 97 |
+
<p>Best Height: <span id="final-score">0</span>m</p>
|
| 98 |
+
<button class="btn" id="retry-btn">Try Again</button>
|
| 99 |
+
<button class="btn" id="shop-btn-go" style="font-size: 16px; padding: 10px 20px;">Shop</button>
|
| 100 |
+
</div>
|
| 101 |
+
|
| 102 |
+
<!-- SHOP / PAUSE MENU -->
|
| 103 |
+
<div id="shop-menu" class="overlay-menu">
|
| 104 |
+
<h1>SKIN SHOP</h1>
|
| 105 |
+
<p>Stars: <span id="shop-stars">0</span></p>
|
| 106 |
+
|
| 107 |
+
<div class="shop-grid" id="skin-grid"></div>
|
| 108 |
|
| 109 |
+
<button class="btn" id="resume-btn">Resume</button>
|
| 110 |
+
</div>
|
| 111 |
+
</div>
|
|
|
|
|
|
|
| 112 |
</div>
|
| 113 |
|
| 114 |
+
<script src="/socket.io/socket.io.js"></script>
|
| 115 |
+
<script>
|
| 116 |
+
/**
|
| 117 |
+
* ASCENT: MULTIPLAYER EDITION
|
| 118 |
+
* Core game logic preserved. Added Networking and Seeded Generation.
|
| 119 |
+
*/
|
| 120 |
+
|
| 121 |
+
// --- SOCKET & NETWORK ---
|
| 122 |
+
const socket = io();
|
| 123 |
+
let myId = null;
|
| 124 |
+
let serverSeed = 0; // The seed ensuring all players see same map
|
| 125 |
+
let otherPlayers = {}; // Map of id -> {x, y, skin, isDead}
|
| 126 |
+
let leaderboardData = [];
|
| 127 |
+
|
| 128 |
+
// Setup Login
|
| 129 |
+
const loginScreen = document.getElementById('login-screen');
|
| 130 |
+
const usernameInput = document.getElementById('username-input');
|
| 131 |
+
const startBtn = document.getElementById('start-btn');
|
| 132 |
+
const lbContent = document.getElementById('lb-content');
|
| 133 |
+
|
| 134 |
+
let myName = localStorage.getItem('ascent_name') || `Player${Math.floor(Math.random()*999)}`;
|
| 135 |
+
usernameInput.value = myName;
|
| 136 |
+
|
| 137 |
+
startBtn.onclick = () => {
|
| 138 |
+
const name = usernameInput.value.trim() || "Anon";
|
| 139 |
+
localStorage.setItem('ascent_name', name);
|
| 140 |
+
myName = name;
|
| 141 |
+
loginScreen.style.display = 'none';
|
| 142 |
+
|
| 143 |
+
// Join Server
|
| 144 |
+
socket.emit('join', { name: myName, skin: state.currentSkin });
|
| 145 |
+
initLevel();
|
| 146 |
+
state.isPlaying = true;
|
| 147 |
+
gameLoop();
|
| 148 |
+
};
|
| 149 |
+
|
| 150 |
+
socket.on('connect', () => {
|
| 151 |
+
myId = socket.id;
|
| 152 |
+
});
|
| 153 |
+
|
| 154 |
+
socket.on('config', (data) => {
|
| 155 |
+
serverSeed = data.seed;
|
| 156 |
+
// We do NOT init level here, we wait for user to click Play
|
| 157 |
+
});
|
| 158 |
+
|
| 159 |
+
socket.on('worldUpdate', (data) => {
|
| 160 |
+
// Sync other players
|
| 161 |
+
otherPlayers = {};
|
| 162 |
+
data.players.forEach(p => {
|
| 163 |
+
if (p.id !== socket.id) {
|
| 164 |
+
otherPlayers[p.id] = p;
|
| 165 |
+
}
|
| 166 |
+
});
|
| 167 |
+
|
| 168 |
+
// Update Leaderboard UI
|
| 169 |
+
leaderboardData = data.lb;
|
| 170 |
+
updateLeaderboardUI();
|
| 171 |
+
});
|
| 172 |
+
|
| 173 |
+
function updateLeaderboardUI() {
|
| 174 |
+
let html = '';
|
| 175 |
+
leaderboardData.forEach((p, i) => {
|
| 176 |
+
html += `<div class="lb-row"><span class="lb-rank">#${i+1}</span> <span>${p.name}</span> <span>${p.score}m</span></div>`;
|
| 177 |
+
});
|
| 178 |
+
lbContent.innerHTML = html;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
// Send Update Loop (20 times per second)
|
| 182 |
+
setInterval(() => {
|
| 183 |
+
if (state.isPlaying && !state.gameOver) {
|
| 184 |
+
socket.emit('update', {
|
| 185 |
+
x: player.x,
|
| 186 |
+
y: player.y,
|
| 187 |
+
vx: player.vx,
|
| 188 |
+
vy: player.vy,
|
| 189 |
+
skin: state.currentSkin,
|
| 190 |
+
score: state.highScore,
|
| 191 |
+
isDead: false
|
| 192 |
+
});
|
| 193 |
+
} else if (state.gameOver) {
|
| 194 |
+
socket.emit('update', { x:0, y:0, vx:0, vy:0, skin:state.currentSkin, score:state.highScore, isDead:true });
|
| 195 |
+
}
|
| 196 |
+
}, 50);
|
| 197 |
+
|
| 198 |
+
// --- DETERMINISTIC RNG (For Syncing Level) ---
|
| 199 |
+
// Returns a random number 0-1 based on the Height (y) and a Server Seed
|
| 200 |
+
function seededRandom(y, salt) {
|
| 201 |
+
const v = Math.sin(y * 12.9898 + serverSeed + salt) * 43758.5453;
|
| 202 |
+
return v - Math.floor(v);
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
// --- AUDIO SYSTEM (Unchanged) ---
|
| 207 |
+
const AudioSys = {
|
| 208 |
+
ctx: null,
|
| 209 |
+
init: function() {
|
| 210 |
+
window.AudioContext = window.AudioContext || window.webkitAudioContext;
|
| 211 |
+
this.ctx = new AudioContext();
|
| 212 |
+
},
|
| 213 |
+
playTone: function(freq, type, duration, vol = 0.1) {
|
| 214 |
+
if (!this.ctx) return;
|
| 215 |
+
const osc = this.ctx.createOscillator();
|
| 216 |
+
const gain = this.ctx.createGain();
|
| 217 |
+
osc.type = type;
|
| 218 |
+
osc.frequency.setValueAtTime(freq, this.ctx.currentTime);
|
| 219 |
+
gain.gain.setValueAtTime(vol, this.ctx.currentTime);
|
| 220 |
+
gain.gain.exponentialRampToValueAtTime(0.01, this.ctx.currentTime + duration);
|
| 221 |
+
osc.connect(gain);
|
| 222 |
+
gain.connect(this.ctx.destination);
|
| 223 |
+
osc.start();
|
| 224 |
+
osc.stop(this.ctx.currentTime + duration);
|
| 225 |
+
},
|
| 226 |
+
sfx: {
|
| 227 |
+
jump: () => AudioSys.playTone(400, 'sine', 0.1, 0.1),
|
| 228 |
+
land: () => AudioSys.playTone(150, 'triangle', 0.1, 0.2),
|
| 229 |
+
coin: () => { AudioSys.playTone(1200, 'sine', 0.1, 0.05); setTimeout(() => AudioSys.playTone(1600, 'sine', 0.2, 0.05), 50); },
|
| 230 |
+
crumble: () => AudioSys.playTone(100, 'sawtooth', 0.3, 0.1),
|
| 231 |
+
die: () => AudioSys.playTone(100, 'sawtooth', 1.0, 0.3),
|
| 232 |
+
powerup: () => AudioSys.playTone(600, 'square', 0.4, 0.1)
|
| 233 |
+
}
|
| 234 |
+
};
|
| 235 |
+
|
| 236 |
+
// --- CONSTANTS & CONFIG ---
|
| 237 |
+
const LOGICAL_WIDTH = 375;
|
| 238 |
+
const LOGICAL_HEIGHT = 812;
|
| 239 |
+
const GRAVITY = 0.5;
|
| 240 |
+
const FRICTION_AIR = 0.93;
|
| 241 |
+
const FRICTION_GROUND = 0.80;
|
| 242 |
+
const FRICTION_ICE = 0.995;
|
| 243 |
+
const DRAG_STRENGTH = 0.18;
|
| 244 |
+
const MAX_POWER = 22;
|
| 245 |
+
const MIN_POWER = 3;
|
| 246 |
+
const CAMERA_SMOOTHING = 0.1;
|
| 247 |
+
|
| 248 |
+
// --- DYNAMIC COLORS ---
|
| 249 |
+
const PALETTES = [
|
| 250 |
+
{ h: 0, top: '#2d2347', bot: '#7a5a8a' },
|
| 251 |
+
{ h: 1000, top: '#001a33', bot: '#006699' },
|
| 252 |
+
{ h: 3000, top: '#000000', bot: '#2c003e' }
|
| 253 |
+
];
|
| 254 |
+
|
| 255 |
+
const COLORS = { platform: '#1a1a2e', platformHighlight: '#262642', vine: '#25203b', tree: '#2d4a66', treeLight: '#3a5d7c', spike: '#666', saw: '#ff4444', wind: 'rgba(100, 200, 255, 0.3)' };
|
| 256 |
+
|
| 257 |
+
// --- GAME STATE ---
|
| 258 |
+
const canvas = document.getElementById('gameCanvas');
|
| 259 |
+
const ctx = canvas.getContext('2d');
|
| 260 |
+
const uiScore = document.getElementById('score-value');
|
| 261 |
+
const uiStars = document.getElementById('stars-value');
|
| 262 |
+
const uiFinalScore = document.getElementById('final-score');
|
| 263 |
+
const uiGameOver = document.getElementById('game-over');
|
| 264 |
+
const uiShop = document.getElementById('shop-menu');
|
| 265 |
+
const uiTutorial = document.getElementById('tutorial');
|
| 266 |
+
const uiBadgeShield = document.getElementById('badge-shield');
|
| 267 |
+
const uiBadgeRocket = document.getElementById('badge-rocket');
|
| 268 |
+
const uiBadgeSlow = document.getElementById('badge-slow');
|
| 269 |
+
const uiShopStars = document.getElementById('shop-stars');
|
| 270 |
+
const uiSkinGrid = document.getElementById('skin-grid');
|
| 271 |
+
|
| 272 |
+
let state = {
|
| 273 |
+
width: LOGICAL_WIDTH, height: LOGICAL_HEIGHT, scale: 1, cameraY: 0,
|
| 274 |
+
score: 0, starsCollected: parseInt(localStorage.getItem('ascent_stars')) || 0,
|
| 275 |
+
unlockedSkins: JSON.parse(localStorage.getItem('ascent_skins')) || ['square'],
|
| 276 |
+
currentSkin: localStorage.getItem('ascent_current_skin') || 'square',
|
| 277 |
+
highScore: 0, isPlaying: false, isPaused: false, gameOver: false, // Changed isPlaying to false initially
|
| 278 |
+
lastPlatformY: 0, timeScale: 1.0,
|
| 279 |
+
hasShield: false, rocketActive: false, rocketTimer: 0, slowMoTimer: 0,
|
| 280 |
+
isDragging: false, dragStartX: 0, dragStartY: 0, dragCurrX: 0, dragCurrY: 0,
|
| 281 |
+
bgTop: PALETTES[0].top, bgBot: PALETTES[0].bot
|
| 282 |
+
};
|
| 283 |
+
|
| 284 |
+
// --- SKINS DATA ---
|
| 285 |
+
const SKINS = [
|
| 286 |
+
{ id: 'square', name: 'Cube', price: 0, color: '#fff' },
|
| 287 |
+
{ id: 'circle', name: 'Ball', price: 50, color: '#00ff88' },
|
| 288 |
+
{ id: 'triangle', name: 'Tri', price: 100, color: '#ff00ff' },
|
| 289 |
+
{ id: 'gold', name: 'Gold', price: 300, color: '#ffd700' }
|
| 290 |
+
];
|
| 291 |
+
|
| 292 |
+
// --- ENTITIES ---
|
| 293 |
+
class Player {
|
| 294 |
+
constructor() { this.w = 24; this.h = 24; this.reset(); }
|
| 295 |
+
reset() {
|
| 296 |
+
this.x = LOGICAL_WIDTH / 2 - this.w / 2;
|
| 297 |
+
this.y = LOGICAL_HEIGHT - 250;
|
| 298 |
+
this.vx = 0; this.vy = 0;
|
| 299 |
+
this.grounded = false; this.landedPlatform = null;
|
| 300 |
+
this.stretchX = 1; this.stretchY = 1; this.rotation = 0;
|
| 301 |
+
state.rocketActive = false; state.hasShield = false;
|
| 302 |
+
}
|
| 303 |
+
update() {
|
| 304 |
+
if (state.rocketActive) {
|
| 305 |
+
this.vy = -25; this.vx = 0;
|
| 306 |
+
state.rocketTimer--;
|
| 307 |
+
if (state.rocketTimer <= 0) {
|
| 308 |
+
state.rocketActive = false; this.vy = -10;
|
| 309 |
+
uiBadgeRocket.style.display = 'none';
|
| 310 |
+
}
|
| 311 |
+
this.y += this.vy;
|
| 312 |
+
this.x += (LOGICAL_WIDTH/2 - this.w/2 - this.x) * 0.1;
|
| 313 |
+
return;
|
| 314 |
+
}
|
| 315 |
+
this.vy += GRAVITY * state.timeScale;
|
| 316 |
+
let friction = FRICTION_AIR;
|
| 317 |
+
if (this.grounded) {
|
| 318 |
+
if (this.landedPlatform && this.landedPlatform.type === 'ice') friction = FRICTION_ICE;
|
| 319 |
+
else friction = FRICTION_GROUND;
|
| 320 |
+
}
|
| 321 |
+
this.vx *= Math.pow(friction, state.timeScale);
|
| 322 |
+
this.x += this.vx * state.timeScale;
|
| 323 |
+
this.y += this.vy * state.timeScale;
|
| 324 |
+
if (this.grounded && this.landedPlatform && this.landedPlatform.type === 'moving') {
|
| 325 |
+
this.x += this.landedPlatform.vx * state.timeScale;
|
| 326 |
+
}
|
| 327 |
+
if (this.x < 0) { this.x = 0; this.vx *= -0.5; }
|
| 328 |
+
else if (this.x + this.w > LOGICAL_WIDTH) { this.x = LOGICAL_WIDTH - this.w; this.vx *= -0.5; }
|
| 329 |
+
this.stretchX += (1 - this.stretchX) * 0.1;
|
| 330 |
+
this.stretchY += (1 - this.stretchY) * 0.1;
|
| 331 |
+
this.rotation = (this.vx * 0.1);
|
| 332 |
+
this.grounded = false;
|
| 333 |
+
}
|
| 334 |
+
draw(ctx, isLocal = true, customSkin = null, customX = null, customY = null) {
|
| 335 |
+
ctx.save();
|
| 336 |
+
const dX = customX !== null ? customX : this.x;
|
| 337 |
+
const dY = customY !== null ? customY : this.y;
|
| 338 |
|
| 339 |
+
ctx.translate(dX + this.w/2, dY + this.h/2);
|
|
|
|
| 340 |
|
| 341 |
+
// Ghost visual tweak
|
| 342 |
+
if (!isLocal) ctx.globalAlpha = 0.5;
|
| 343 |
+
|
| 344 |
+
if (state.rocketActive && isLocal) {
|
| 345 |
+
ctx.fillStyle = '#ff4444';
|
| 346 |
+
ctx.beginPath(); ctx.moveTo(0, -20); ctx.lineTo(10, 10); ctx.lineTo(-10, 10); ctx.fill();
|
| 347 |
+
ctx.fillStyle = `rgba(255, 200, 0, ${Math.random()})`;
|
| 348 |
+
ctx.beginPath(); ctx.arc(0, 15, Math.random()*10, 0, Math.PI*2); ctx.fill();
|
| 349 |
+
ctx.restore(); return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
}
|
| 351 |
|
| 352 |
+
if (isLocal) {
|
| 353 |
+
ctx.rotate(this.rotation);
|
| 354 |
+
ctx.scale(this.stretchX, this.stretchY);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
}
|
| 356 |
|
| 357 |
+
const skinId = customSkin || state.currentSkin;
|
| 358 |
+
const skinData = SKINS.find(s => s.id === skinId) || SKINS[0];
|
| 359 |
+
ctx.fillStyle = skinData.color;
|
| 360 |
+
|
| 361 |
+
// Remove shadow for ghosts to improve perf
|
| 362 |
+
if(isLocal) { ctx.shadowBlur = 10; ctx.shadowColor = skinData.color; }
|
| 363 |
+
|
| 364 |
+
if (skinId === 'circle') { ctx.beginPath(); ctx.arc(0, 0, this.w/2, 0, Math.PI*2); ctx.fill(); }
|
| 365 |
+
else if (skinId === 'triangle') { ctx.beginPath(); ctx.moveTo(0, -this.h/2); ctx.lineTo(this.w/2, this.h/2); ctx.lineTo(-this.w/2, this.h/2); ctx.fill(); }
|
| 366 |
+
else { ctx.beginPath(); ctx.roundRect(-this.w/2, -this.h/2, this.w, this.h, 4); ctx.fill(); }
|
| 367 |
+
|
| 368 |
+
ctx.fillStyle = "#000";
|
| 369 |
+
if (isLocal) {
|
| 370 |
+
if (Math.abs(this.vx) > 1) { const dir = Math.sign(this.vx); ctx.fillRect(dir * 4 - 2, -4, 4, 8); }
|
| 371 |
+
else { ctx.fillRect(-5, -2, 3, 3); ctx.fillRect(3, -2, 3, 3); }
|
| 372 |
+
} else {
|
| 373 |
+
ctx.fillRect(-5, -2, 3, 3); ctx.fillRect(3, -2, 3, 3);
|
| 374 |
+
}
|
| 375 |
|
| 376 |
+
if (state.hasShield && isLocal) { ctx.strokeStyle = "#00ffff"; ctx.lineWidth = 2; ctx.beginPath(); ctx.arc(0, 0, this.w, 0, Math.PI*2); ctx.stroke(); }
|
| 377 |
+
|
| 378 |
+
ctx.globalAlpha = 1.0;
|
| 379 |
+
ctx.restore();
|
| 380 |
+
}
|
| 381 |
+
jump(vx, vy) {
|
| 382 |
+
this.vx = vx; this.vy = vy; this.grounded = false; this.landedPlatform = null;
|
| 383 |
+
this.stretchX = 0.6; this.stretchY = 1.4;
|
| 384 |
+
uiTutorial.style.display = 'none';
|
| 385 |
+
AudioSys.sfx.jump();
|
| 386 |
+
}
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
class Platform {
|
| 390 |
+
constructor(x, y, w, h, type = 'normal') {
|
| 391 |
+
this.x = x; this.y = y; this.w = w; this.h = h;
|
| 392 |
+
this.type = type;
|
| 393 |
+
this.crumbleTimer = 60; this.isCrumbling = false; this.isDestroyed = false; this.hasBounced = false;
|
| 394 |
+
// Seeded random for movement
|
| 395 |
+
const r1 = seededRandom(y, 1);
|
| 396 |
+
this.vx = (type === 'moving') ? (r1 > 0.5 ? 1 : -1) * (1 + r1 * 1.5) : 0;
|
| 397 |
+
|
| 398 |
+
const r2 = seededRandom(y, 2);
|
| 399 |
+
this.hasSpikes = (r2 < 0.2 && type !== 'crumble' && type !== 'bouncy');
|
| 400 |
+
this.spikeX = seededRandom(y, 3) * (this.w - 20);
|
| 401 |
+
|
| 402 |
+
this.decorations = [];
|
| 403 |
+
this.generateDecorations();
|
| 404 |
+
}
|
| 405 |
+
triggerCrumble() {
|
| 406 |
+
if (this.type === 'crumble' && !this.isCrumbling) { this.isCrumbling = true; AudioSys.sfx.crumble(); }
|
| 407 |
+
}
|
| 408 |
+
update() {
|
| 409 |
+
if (this.type === 'moving') {
|
| 410 |
+
this.x += this.vx * state.timeScale;
|
| 411 |
+
if (this.x <= 0 || this.x + this.w >= LOGICAL_WIDTH) this.vx *= -1;
|
| 412 |
+
}
|
| 413 |
+
else if (this.type === 'crumble' && this.isCrumbling) {
|
| 414 |
+
this.crumbleTimer -= 1 * state.timeScale;
|
| 415 |
+
if (this.crumbleTimer <= 0) { this.isDestroyed = true; createDust(this.x + this.w/2, this.y + this.h/2, 10); }
|
| 416 |
+
}
|
| 417 |
+
}
|
| 418 |
+
generateDecorations() {
|
| 419 |
+
if (this.type === 'crumble' || this.type === 'ice' || this.type === 'bouncy') return;
|
| 420 |
+
const r = seededRandom(this.y, 4);
|
| 421 |
+
if (r > 0.5) this.decorations.push({ type: 'vine', x: seededRandom(this.y,5)*(this.w-10), len: 20+seededRandom(this.y,6)*40 });
|
| 422 |
+
if (seededRandom(this.y, 7) > 0.7 && !this.hasSpikes) this.decorations.push({ type: 'tree', x: seededRandom(this.y,8)*(this.w-20), h: 20+seededRandom(this.y,9)*30 });
|
| 423 |
+
}
|
| 424 |
+
draw(ctx) {
|
| 425 |
+
if (this.isDestroyed) return;
|
| 426 |
+
let dx = this.x, dy = this.y;
|
| 427 |
+
if (this.isCrumbling) { dx += (Math.random() - 0.5) * 4; dy += (Math.random() - 0.5) * 4; }
|
| 428 |
+
ctx.strokeStyle = COLORS.vine; ctx.lineWidth = 3;
|
| 429 |
+
this.decorations.forEach(d => {
|
| 430 |
+
if (d.type === 'vine') {
|
| 431 |
+
ctx.beginPath(); ctx.moveTo(dx+d.x, dy+this.h);
|
| 432 |
+
ctx.quadraticCurveTo(dx+d.x+Math.sin(Date.now()/1000)*5, dy+this.h+d.len/2, dx+d.x, dy+this.h+d.len);
|
| 433 |
+
ctx.stroke();
|
| 434 |
}
|
| 435 |
});
|
| 436 |
+
ctx.fillStyle = COLORS.platform;
|
| 437 |
+
ctx.beginPath(); ctx.roundRect(dx, dy, this.w, this.h, 8); ctx.fill();
|
| 438 |
+
if (this.type === 'bouncy') {
|
| 439 |
+
ctx.fillStyle = !this.hasBounced ? '#ff66cc' : '#554466'; ctx.fillRect(dx+5, !this.hasBounced?dy:dy+4, this.w-10, !this.hasBounced?6:2);
|
| 440 |
+
} else if (this.type === 'ice') {
|
| 441 |
+
ctx.fillStyle = '#00ffff'; ctx.fillRect(dx, dy, this.w, 8);
|
| 442 |
+
} else {
|
| 443 |
+
ctx.fillStyle = COLORS.platformHighlight; ctx.beginPath(); ctx.roundRect(dx+4, dy+4, this.w-8, this.h-8, 4); ctx.fill();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 444 |
}
|
| 445 |
+
if (this.hasSpikes) {
|
| 446 |
+
ctx.fillStyle = COLORS.spike; ctx.beginPath(); ctx.moveTo(dx + this.spikeX, dy); ctx.lineTo(dx + this.spikeX + 10, dy - 15); ctx.lineTo(dx + this.spikeX + 20, dy); ctx.fill();
|
| 447 |
+
}
|
| 448 |
+
}
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
class Enemy {
|
| 452 |
+
constructor(y) { this.y = y; this.x = seededRandom(y, 10) * LOGICAL_WIDTH; this.r = 15; this.vx = 2; this.angle = 0; }
|
| 453 |
+
update() { this.x += this.vx * state.timeScale; if (this.x < 15 || this.x > LOGICAL_WIDTH-15) this.vx *= -1; this.angle += 0.2 * state.timeScale; }
|
| 454 |
+
draw(ctx) {
|
| 455 |
+
ctx.save(); ctx.translate(this.x, this.y); ctx.rotate(this.angle);
|
| 456 |
+
ctx.fillStyle = COLORS.saw; ctx.beginPath();
|
| 457 |
+
for(let i=0; i<8; i++) { ctx.rotate(Math.PI/4); ctx.lineTo(0, -this.r); ctx.lineTo(5, -this.r+5); ctx.lineTo(-5, -this.r+5); }
|
| 458 |
+
ctx.fill(); ctx.fillStyle = "#333"; ctx.beginPath(); ctx.arc(0,0,5,0,Math.PI*2); ctx.fill(); ctx.restore();
|
| 459 |
+
}
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
class WindZone {
|
| 463 |
+
constructor(y) {
|
| 464 |
+
this.y = y; this.h = 100;
|
| 465 |
+
this.dir = seededRandom(y, 11) > 0.5 ? 1 : -1;
|
| 466 |
+
this.particles = [];
|
| 467 |
+
for(let i=0; i<10; i++) this.particles.push({x:Math.random()*LOGICAL_WIDTH, y:Math.random()*this.h, s:Math.random()*3+2});
|
| 468 |
+
}
|
| 469 |
+
update() {
|
| 470 |
+
this.particles.forEach(p => { p.x += this.dir * 4 * state.timeScale; if(p.x > LOGICAL_WIDTH) p.x = 0; if(p.x < 0) p.x = LOGICAL_WIDTH; });
|
| 471 |
+
if (player.y > this.y && player.y < this.y + this.h) player.vx += this.dir * 0.5 * state.timeScale;
|
| 472 |
+
}
|
| 473 |
+
draw(ctx) {
|
| 474 |
+
ctx.fillStyle = COLORS.wind;
|
| 475 |
+
this.particles.forEach(p => { ctx.fillRect(p.x, this.y + p.y, p.s*2, 2); });
|
| 476 |
+
}
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
class Collectible {
|
| 480 |
+
constructor(x, y, type) { this.x = x; this.y = y; this.type = type; this.collected = false; this.bob = Math.random() * Math.PI; }
|
| 481 |
+
draw(ctx) {
|
| 482 |
+
if(this.collected) return;
|
| 483 |
+
const by = this.y + Math.sin(Date.now()/300 + this.bob)*3;
|
| 484 |
+
ctx.save(); ctx.translate(this.x, by);
|
| 485 |
+
if (this.type === 'star') {
|
| 486 |
+
ctx.fillStyle = '#ffd700'; ctx.shadowBlur=10; ctx.shadowColor='#ffd700'; ctx.beginPath(); ctx.arc(0,0,8,0,Math.PI*2); ctx.fill();
|
| 487 |
+
ctx.fillStyle = '#fff'; ctx.font='10px Arial'; ctx.textAlign='center'; ctx.fillText('★',0,4);
|
| 488 |
+
} else {
|
| 489 |
+
ctx.fillStyle = 'rgba(255,255,255,0.2)'; ctx.beginPath(); ctx.arc(0,0,14,0,Math.PI*2); ctx.fill(); ctx.strokeStyle = '#fff'; ctx.stroke();
|
| 490 |
+
ctx.font = '16px Arial'; ctx.textAlign='center';
|
| 491 |
+
if (this.type === 'rocket') ctx.fillText('🚀',0,5); if (this.type === 'shield') ctx.fillText('🛡️',0,5); if (this.type === 'slow') ctx.fillText('⏳',0,5);
|
| 492 |
+
}
|
| 493 |
+
ctx.restore();
|
| 494 |
+
}
|
| 495 |
+
}
|
| 496 |
+
|
| 497 |
+
const player = new Player();
|
| 498 |
+
let platforms = [], enemies = [], winds = [], collectibles = [], particles = [];
|
| 499 |
+
|
| 500 |
+
function initLevel() {
|
| 501 |
+
platforms = []; enemies = []; winds = []; collectibles = []; particles = [];
|
| 502 |
+
state.lastPlatformY = LOGICAL_HEIGHT - 100;
|
| 503 |
+
// Ground platform is always same
|
| 504 |
+
platforms.push(new Platform(0, LOGICAL_HEIGHT - 100, LOGICAL_WIDTH, 150));
|
| 505 |
+
generateChunk(LOGICAL_HEIGHT - 250);
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
function generateChunk(targetY) {
|
| 509 |
+
let y = state.lastPlatformY;
|
| 510 |
+
// Safe guard loop
|
| 511 |
+
let loops = 0;
|
| 512 |
+
while (y > targetY && loops < 500) {
|
| 513 |
+
loops++;
|
| 514 |
+
const heightMeters = Math.abs(y - (LOGICAL_HEIGHT - 100)) / 10;
|
| 515 |
+
const diff = Math.min(1, heightMeters / 1500);
|
| 516 |
+
|
| 517 |
+
// Use Seeded Random for Gap
|
| 518 |
+
const rGap = seededRandom(y, 12);
|
| 519 |
+
const minGap = 80 + (diff * 40);
|
| 520 |
+
const maxGap = 160 + (diff * 60);
|
| 521 |
+
y -= (minGap + rGap * (maxGap - minGap));
|
| 522 |
+
|
| 523 |
+
// Width
|
| 524 |
+
let w = (60 + seededRandom(y, 13) * 100) * (1 - diff * 0.4);
|
| 525 |
+
w = Math.max(40, w);
|
| 526 |
+
let x = Math.max(10, Math.min(seededRandom(y, 14)*(LOGICAL_WIDTH-w), LOGICAL_WIDTH-w-10));
|
| 527 |
+
|
| 528 |
+
// Platform Type
|
| 529 |
+
let type = 'normal';
|
| 530 |
+
const rand = seededRandom(y, 15);
|
| 531 |
+
if (heightMeters > 50 && rand < 0.2 + diff*0.3) type = 'moving';
|
| 532 |
+
else if (heightMeters > 20 && rand < 0.35) type = 'crumble';
|
| 533 |
+
else if (heightMeters > 100 && rand < 0.45) type = 'bouncy';
|
| 534 |
+
else if (heightMeters > 150 && rand < 0.55) type = 'ice';
|
| 535 |
+
|
| 536 |
+
platforms.push(new Platform(x, y, w, 30 + seededRandom(y, 16) * 100, type));
|
| 537 |
+
|
| 538 |
+
// Spawners - using seeded random
|
| 539 |
+
if (seededRandom(y, 17) < 0.05) {
|
| 540 |
+
const pArr = ['rocket','shield','slow'];
|
| 541 |
+
const pType = pArr[Math.floor(seededRandom(y, 18)*3)];
|
| 542 |
+
collectibles.push(new Collectible(x+w/2, y-30, pType));
|
| 543 |
+
} else if (seededRandom(y, 19) < 0.25) {
|
| 544 |
+
collectibles.push(new Collectible(x+w/2, y-30-Math.random()*30, 'star'));
|
| 545 |
}
|
| 546 |
|
| 547 |
+
if (heightMeters > 200 && seededRandom(y, 20) < 0.1 + diff*0.3) enemies.push(new Enemy(y - 50));
|
| 548 |
+
if (heightMeters > 300 && seededRandom(y, 21) < 0.1) winds.push(new WindZone(y - 100));
|
| 549 |
+
}
|
| 550 |
+
state.lastPlatformY = y;
|
| 551 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 552 |
|
| 553 |
+
function checkCollisions() {
|
| 554 |
+
if (state.rocketActive) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 555 |
|
| 556 |
+
for (let p of platforms) {
|
| 557 |
+
if (p.isDestroyed) continue;
|
| 558 |
+
if (p.hasSpikes) {
|
| 559 |
+
if (player.x + player.w > p.x + p.spikeX && player.x < p.x + p.spikeX + 20 &&
|
| 560 |
+
player.y + player.h > p.y - 10 && player.y + player.h < p.y + 10) { killPlayer(); return; }
|
| 561 |
+
}
|
| 562 |
+
if (player.vy >= 0 && player.y + player.h <= p.y + player.vy + 3 &&
|
| 563 |
+
player.y + player.h >= p.y - 5 && player.x + player.w > p.x + 5 && player.x < p.x + p.w - 5) {
|
| 564 |
+
if (p.type === 'bouncy' && !p.hasBounced) {
|
| 565 |
+
player.y = p.y - player.h; player.vy = -15; p.hasBounced = true;
|
| 566 |
+
createDust(player.x+player.w/2, player.y+player.h, 5); AudioSys.sfx.jump();
|
| 567 |
+
} else {
|
| 568 |
+
const impactVelocity = player.vy;
|
| 569 |
+
player.y = p.y - player.h; player.vy = 0; player.grounded = true; player.landedPlatform = p;
|
| 570 |
+
if (p.type === 'crumble') p.triggerCrumble();
|
| 571 |
+
if (impactVelocity > 2.0) { AudioSys.sfx.land(); createDust(player.x+player.w/2, player.y+player.h, 3); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 572 |
}
|
|
|
|
|
|
|
|
|
|
| 573 |
}
|
| 574 |
+
}
|
| 575 |
+
for (let e of enemies) { if (Math.hypot((player.x+player.w/2)-e.x, (player.y+player.h/2)-e.y) < player.w/2 + e.r) killPlayer(); }
|
| 576 |
+
collectibles.forEach(c => {
|
| 577 |
+
if (c.collected) return;
|
| 578 |
+
if (Math.hypot((player.x+player.w/2)-c.x, (player.y+player.h/2)-c.y) < 20) {
|
| 579 |
+
c.collected = true;
|
| 580 |
+
if (c.type === 'star') {
|
| 581 |
+
state.score += 10; state.starsCollected++; uiStars.innerText = state.starsCollected;
|
| 582 |
+
localStorage.setItem('ascent_stars', state.starsCollected); AudioSys.sfx.coin();
|
| 583 |
+
} else activatePowerup(c.type);
|
| 584 |
+
}
|
| 585 |
+
});
|
| 586 |
+
if (player.y > state.cameraY + LOGICAL_HEIGHT + 100) {
|
| 587 |
+
if (state.hasShield) { player.vy = -25; state.hasShield = false; uiBadgeShield.style.display = 'none'; AudioSys.sfx.powerup(); }
|
| 588 |
+
else killPlayer();
|
| 589 |
+
}
|
| 590 |
+
}
|
| 591 |
+
|
| 592 |
+
function activatePowerup(type) {
|
| 593 |
+
AudioSys.sfx.powerup();
|
| 594 |
+
if (type === 'shield') { state.hasShield = true; uiBadgeShield.style.display = 'block'; }
|
| 595 |
+
else if (type === 'rocket') { state.rocketActive = true; state.rocketTimer = 100; uiBadgeRocket.style.display = 'block'; }
|
| 596 |
+
else if (type === 'slow') { state.slowMoTimer = 300; uiBadgeSlow.style.display = 'block'; }
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
function killPlayer() {
|
| 600 |
+
if (state.gameOver) return;
|
| 601 |
+
state.gameOver = true; state.isPlaying = false; AudioSys.sfx.die(); if(navigator.vibrate) navigator.vibrate(200);
|
| 602 |
+
uiFinalScore.innerText = Math.floor(state.highScore); uiGameOver.style.display = 'flex';
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
function createDust(x, y, count) {
|
| 606 |
+
for(let i=0; i<count; i++) particles.push({ x: x, y: y, vx: (Math.random()-0.5)*4, vy: Math.random()*-2, life: 1.0, size: Math.random()*4+2 });
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
function updateEnvironment() {
|
| 610 |
+
const h = state.highScore;
|
| 611 |
+
for(let i=0; i<PALETTES.length-1; i++) {
|
| 612 |
+
if (h >= PALETTES[i].h && h <= PALETTES[i+1].h) {
|
| 613 |
+
const t = (h - PALETTES[i].h) / (PALETTES[i+1].h - PALETTES[i].h);
|
| 614 |
+
state.bgTop = lerpColor(PALETTES[i].top, PALETTES[i+1].top, t);
|
| 615 |
+
state.bgBot = lerpColor(PALETTES[i].bot, PALETTES[i+1].bot, t);
|
| 616 |
+
break;
|
| 617 |
+
}
|
| 618 |
+
}
|
| 619 |
+
}
|
| 620 |
+
function lerpColor(a, b, amount) {
|
| 621 |
+
const ah = parseInt(a.replace(/#/g, ''), 16), ar = ah >> 16, ag = ah >> 8 & 0xff, ab = ah & 0xff,
|
| 622 |
+
bh = parseInt(b.replace(/#/g, ''), 16), br = bh >> 16, bg = bh >> 8 & 0xff, bb = bh & 0xff,
|
| 623 |
+
rr = ar + amount * (br - ar), rg = ag + amount * (bg - ag), rb = ab + amount * (bb - ab);
|
| 624 |
+
return '#' + ((1 << 24) + (rr << 16) + (rg << 8) + (rb | 0)).toString(16).slice(1);
|
| 625 |
+
}
|
| 626 |
+
|
| 627 |
+
function updateCamera() {
|
| 628 |
+
let targetY = player.y - LOGICAL_HEIGHT * 0.6;
|
| 629 |
+
if (state.rocketActive) targetY = player.y - LOGICAL_HEIGHT * 0.5;
|
| 630 |
+
state.cameraY += (targetY - state.cameraY) * CAMERA_SMOOTHING;
|
| 631 |
+
const currentHeight = Math.floor((-player.y + (LOGICAL_HEIGHT - 100)) / 10);
|
| 632 |
+
if (currentHeight > state.highScore) { state.highScore = currentHeight; uiScore.innerText = state.highScore; }
|
| 633 |
+
if (state.cameraY < state.lastPlatformY + LOGICAL_HEIGHT) generateChunk(state.cameraY - LOGICAL_HEIGHT);
|
| 634 |
+
if (platforms.length > 20) platforms.shift();
|
| 635 |
+
if (collectibles.length > 20) collectibles.shift();
|
| 636 |
+
if (enemies.length > 10) enemies.shift();
|
| 637 |
+
if (winds.length > 10) winds.shift();
|
| 638 |
+
}
|
| 639 |
+
|
| 640 |
+
function gameLoop() {
|
| 641 |
+
if (state.isPlaying && !state.isPaused) {
|
| 642 |
+
if (state.slowMoTimer > 0) { state.timeScale = 0.3; state.slowMoTimer--; if (state.slowMoTimer <= 0) { state.timeScale = 1.0; uiBadgeSlow.style.display = 'none'; } }
|
| 643 |
+
else if (!state.rocketActive) state.timeScale = 1.0;
|
| 644 |
+
|
| 645 |
+
player.update();
|
| 646 |
+
platforms.forEach(p => p.update());
|
| 647 |
+
enemies.forEach(e => e.update());
|
| 648 |
+
winds.forEach(w => w.update());
|
| 649 |
+
checkCollisions();
|
| 650 |
+
updateCamera();
|
| 651 |
+
updateEnvironment();
|
| 652 |
+
for (let i = particles.length - 1; i >= 0; i--) { let p = particles[i]; p.x += p.vx * state.timeScale; p.y += p.vy * state.timeScale; p.life -= 0.05 * state.timeScale; if (p.life <= 0) particles.splice(i, 1); }
|
| 653 |
+
}
|
| 654 |
+
|
| 655 |
+
// Render
|
| 656 |
+
const gradient = ctx.createLinearGradient(0, 0, 0, LOGICAL_HEIGHT);
|
| 657 |
+
gradient.addColorStop(0, state.bgTop); gradient.addColorStop(1, state.bgBot);
|
| 658 |
+
ctx.fillStyle = gradient; ctx.fillRect(0, 0, LOGICAL_WIDTH, LOGICAL_HEIGHT);
|
| 659 |
+
|
| 660 |
+
ctx.save();
|
| 661 |
+
ctx.translate(0, -state.cameraY);
|
| 662 |
+
|
| 663 |
+
winds.forEach(w => { if(isVisible(w.y, 200)) w.draw(ctx); });
|
| 664 |
+
platforms.forEach(p => { if(isVisible(p.y, p.h)) p.draw(ctx); });
|
| 665 |
+
collectibles.forEach(c => { if(isVisible(c.y, 20)) c.draw(ctx); });
|
| 666 |
+
enemies.forEach(e => { if(isVisible(e.y, 50)) e.draw(ctx); });
|
| 667 |
+
|
| 668 |
+
// Draw Other Players (Ghosts)
|
| 669 |
+
for (let id in otherPlayers) {
|
| 670 |
+
const op = otherPlayers[id];
|
| 671 |
+
if (!op.isDead && isVisible(op.y, 50)) {
|
| 672 |
+
// Re-use player draw logic but pass custom coords and skin
|
| 673 |
+
player.draw(ctx, false, op.s, op.x, op.y);
|
| 674 |
+
// Draw Name
|
| 675 |
+
ctx.fillStyle = "rgba(255,255,255,0.7)";
|
| 676 |
+
ctx.font = "10px Arial";
|
| 677 |
+
ctx.textAlign = "center";
|
| 678 |
+
ctx.fillText(op.name || "Guest", op.x + 12, op.y - 10);
|
| 679 |
+
}
|
| 680 |
+
}
|
| 681 |
+
|
| 682 |
+
ctx.fillStyle = "rgba(255, 255, 255, 0.6)";
|
| 683 |
+
particles.forEach(p => { ctx.globalAlpha = p.life; ctx.beginPath(); ctx.arc(p.x, p.y, p.size, 0, Math.PI*2); ctx.fill(); });
|
| 684 |
+
ctx.globalAlpha = 1.0;
|
| 685 |
+
|
| 686 |
+
if (state.isPlaying && !state.gameOver) player.draw(ctx, true);
|
| 687 |
+
drawTrajectory(ctx);
|
| 688 |
+
|
| 689 |
+
ctx.restore();
|
| 690 |
+
requestAnimationFrame(gameLoop);
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
function isVisible(y, h) { return y + h > state.cameraY && y < state.cameraY + LOGICAL_HEIGHT; }
|
| 694 |
+
|
| 695 |
+
function restartGame() {
|
| 696 |
+
state.gameOver = false; state.isPlaying = true; state.cameraY = 0; state.score = 0; state.highScore = 0;
|
| 697 |
+
state.rocketActive = false; state.hasShield = false; state.slowMoTimer = 0;
|
| 698 |
+
document.querySelectorAll('.powerup-badge').forEach(el => el.style.display = 'none');
|
| 699 |
+
uiScore.innerText = "0"; uiGameOver.style.display = 'none';
|
| 700 |
+
player.reset(); initLevel(); uiTutorial.style.display = 'block';
|
| 701 |
+
// Sync restart with server
|
| 702 |
+
socket.emit('update', { x:player.x, y:player.y, vx:0, vy:0, skin:state.currentSkin, score:0, isDead:false });
|
| 703 |
+
}
|
| 704 |
+
|
| 705 |
+
function getPointerPos(e) {
|
| 706 |
+
const rect = canvas.getBoundingClientRect();
|
| 707 |
+
const scaleX = LOGICAL_WIDTH / rect.width; const scaleY = LOGICAL_HEIGHT / rect.height;
|
| 708 |
+
let cx = e.touches ? e.touches[0].clientX : e.clientX; let cy = e.touches ? e.touches[0].clientY : e.clientY;
|
| 709 |
+
return { x: (cx - rect.left) * scaleX, y: (cy - rect.top) * scaleY };
|
| 710 |
+
}
|
| 711 |
+
|
| 712 |
+
const startDrag = (e) => {
|
| 713 |
+
if (!state.isPlaying || state.isPaused || (!player.grounded && !state.slowMoTimer>0)) return;
|
| 714 |
+
if(e.target === canvas) e.preventDefault();
|
| 715 |
+
AudioSys.init(); state.isDragging = true;
|
| 716 |
+
const pos = getPointerPos(e); state.dragStartX = pos.x; state.dragStartY = pos.y; state.dragCurrX = pos.x; state.dragCurrY = pos.y;
|
| 717 |
+
};
|
| 718 |
+
const moveDrag = (e) => {
|
| 719 |
+
if (!state.isDragging) return;
|
| 720 |
+
if(e.target === canvas) e.preventDefault();
|
| 721 |
+
const pos = getPointerPos(e); state.dragCurrX = pos.x; state.dragCurrY = pos.y;
|
| 722 |
+
};
|
| 723 |
+
const endDrag = (e) => {
|
| 724 |
+
if (!state.isDragging) return;
|
| 725 |
+
state.isDragging = false;
|
| 726 |
+
let dx = state.dragStartX - state.dragCurrX; let dy = state.dragStartY - state.dragCurrY;
|
| 727 |
+
let power = Math.sqrt(dx*dx + dy*dy) * DRAG_STRENGTH;
|
| 728 |
+
if (power > MAX_POWER) { const a = Math.atan2(dy, dx); dx = Math.cos(a)*(MAX_POWER/DRAG_STRENGTH); dy = Math.sin(a)*(MAX_POWER/DRAG_STRENGTH); }
|
| 729 |
+
if (Math.sqrt(dx*dx+dy*dy)*DRAG_STRENGTH >= MIN_POWER) player.jump(dx*DRAG_STRENGTH, dy*DRAG_STRENGTH);
|
| 730 |
+
};
|
| 731 |
+
|
| 732 |
+
window.addEventListener('mousedown', startDrag); window.addEventListener('mousemove', moveDrag); window.addEventListener('mouseup', endDrag);
|
| 733 |
+
window.addEventListener('touchstart', startDrag, {passive:false}); window.addEventListener('touchmove', moveDrag, {passive:false}); window.addEventListener('touchend', endDrag);
|
| 734 |
+
|
| 735 |
+
document.getElementById('retry-btn').onclick = (e) => { e.stopPropagation(); restartGame(); };
|
| 736 |
+
document.getElementById('pause-btn').onclick = (e) => { e.stopPropagation(); state.isPaused = !state.isPaused; uiShop.style.display = state.isPaused ? 'flex' : 'none'; if(state.isPaused) renderShop(); };
|
| 737 |
+
document.getElementById('resume-btn').onclick = (e) => { e.stopPropagation(); state.isPaused = false; uiShop.style.display = 'none'; };
|
| 738 |
+
document.getElementById('shop-btn-go').onclick = (e) => { e.stopPropagation(); uiGameOver.style.display = 'none'; state.isPaused = true; uiShop.style.display = 'flex'; renderShop(); };
|
| 739 |
+
|
| 740 |
+
function renderShop() {
|
| 741 |
+
uiShopStars.innerText = state.starsCollected; uiSkinGrid.innerHTML = '';
|
| 742 |
+
SKINS.forEach(skin => {
|
| 743 |
+
const unlocked = state.unlockedSkins.includes(skin.id);
|
| 744 |
+
const el = document.createElement('div');
|
| 745 |
+
el.className = `shop-item ${unlocked ? '' : 'locked'} ${state.currentSkin === skin.id ? 'selected' : ''}`;
|
| 746 |
+
el.style.borderColor = unlocked ? skin.color : 'transparent';
|
| 747 |
+
const icon = document.createElement('div'); icon.style.background = skin.color; icon.style.width = '20px'; icon.style.height = '20px';
|
| 748 |
+
if(skin.id==='circle') icon.style.borderRadius = '50%';
|
| 749 |
+
if(skin.id==='triangle') { icon.style.width=0; icon.style.height=0; icon.style.background='transparent'; icon.style.borderLeft='10px solid transparent'; icon.style.borderRight='10px solid transparent'; icon.style.borderBottom=`20px solid ${skin.color}`; }
|
| 750 |
+
el.appendChild(icon);
|
| 751 |
+
if (!unlocked) { const price = document.createElement('div'); price.className = 'price'; price.innerText = `${skin.price}★`; el.appendChild(price); }
|
| 752 |
+
el.onclick = () => {
|
| 753 |
+
if (unlocked) { state.currentSkin = skin.id; localStorage.setItem('ascent_current_skin', skin.id); renderShop(); }
|
| 754 |
+
else if (state.starsCollected >= skin.price) { state.starsCollected -= skin.price; state.unlockedSkins.push(skin.id); localStorage.setItem('ascent_stars', state.starsCollected); localStorage.setItem('ascent_skins', JSON.stringify(state.unlockedSkins)); AudioSys.sfx.powerup(); renderShop(); }
|
| 755 |
+
};
|
| 756 |
+
uiSkinGrid.appendChild(el);
|
| 757 |
+
});
|
| 758 |
+
}
|
| 759 |
+
|
| 760 |
+
function drawTrajectory(ctx) {
|
| 761 |
+
if (!state.isDragging || !player.grounded) return;
|
| 762 |
+
let dx = state.dragStartX - state.dragCurrX; let dy = state.dragStartY - state.dragCurrY;
|
| 763 |
+
let dist = Math.sqrt(dx*dx + dy*dy);
|
| 764 |
+
if (dist * DRAG_STRENGTH > MAX_POWER) { const a = Math.atan2(dy, dx); dx = Math.cos(a)*(MAX_POWER/DRAG_STRENGTH); dy = Math.sin(a)*(MAX_POWER/DRAG_STRENGTH); }
|
| 765 |
+
let vx = dx * DRAG_STRENGTH; let vy = dy * DRAG_STRENGTH;
|
| 766 |
+
let sx = player.x + player.w/2, sy = player.y + player.h/2;
|
| 767 |
+
ctx.fillStyle = '#fff';
|
| 768 |
+
for (let i = 0; i < 15; i++) { sx += vx; sy += vy; vy += GRAVITY; if (i%2===0) { ctx.beginPath(); ctx.arc(sx, sy, 3, 0, Math.PI*2); ctx.fill(); } }
|
| 769 |
+
}
|
| 770 |
+
|
| 771 |
+
function resize() { canvas.width = LOGICAL_WIDTH; canvas.height = LOGICAL_HEIGHT; }
|
| 772 |
+
window.addEventListener('resize', resize);
|
| 773 |
+
resize();
|
| 774 |
+
uiStars.innerText = state.starsCollected;
|
| 775 |
+
|
| 776 |
+
// DO NOT INIT LEVEL AUTOMATICALLY - WAIT FOR LOGIN
|
| 777 |
+
</script>
|
| 778 |
</body>
|
| 779 |
</html>
|