Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- index.html +326 -292
index.html
CHANGED
|
@@ -1,234 +1,262 @@
|
|
| 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">
|
| 6 |
-
<title>Counter-Strike: Web Ops</title>
|
| 7 |
-
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
-
<link href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@400;600;700&display=swap" rel="stylesheet">
|
| 9 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.49/Tone.js"></script>
|
| 10 |
-
<style>
|
| 11 |
-
:root {
|
| 12 |
-
--cs-orange: #d57b00;
|
| 13 |
-
--cs-blue: #4f7cac;
|
| 14 |
-
--cs-bg: #1a1a1a;
|
| 15 |
-
--cs-dark: #111;
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
body {
|
| 19 |
-
margin: 0;
|
| 20 |
-
overflow: hidden;
|
| 21 |
-
background-color: #000;
|
| 22 |
-
font-family: 'Rajdhani', sans-serif;
|
| 23 |
-
user-select: none;
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
/* UI Styling */
|
| 27 |
-
.cs-hud {
|
| 28 |
-
text-shadow: 0 0 2px rgba(0,0,0,0.8);
|
| 29 |
-
letter-spacing: 1px;
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
.weapon-slot {
|
| 33 |
-
transition: all 0.2s;
|
| 34 |
-
}
|
| 35 |
-
.weapon-slot.active {
|
| 36 |
-
background: rgba(255, 255, 255, 0.2);
|
| 37 |
-
border-left: 3px solid white;
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
-
/* Crosshair */
|
| 41 |
-
#crosshair {
|
| 42 |
-
position: absolute;
|
| 43 |
-
top: 50%;
|
| 44 |
-
left: 50%;
|
| 45 |
-
transform: translate(-50%, -50%);
|
| 46 |
-
pointer-events: none;
|
| 47 |
-
z-index: 10;
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
/* Hit Marker */
|
| 51 |
-
#hitmarker {
|
| 52 |
-
position: absolute;
|
| 53 |
-
top: 50%;
|
| 54 |
-
left: 50%;
|
| 55 |
-
transform: translate(-50%, -50%);
|
| 56 |
-
width: 40px;
|
| 57 |
-
height: 40px;
|
| 58 |
-
opacity: 0;
|
| 59 |
-
pointer-events: none;
|
| 60 |
-
z-index: 11;
|
| 61 |
-
}
|
| 62 |
-
#hitmarker.active {
|
| 63 |
-
animation: hitmarker-anim 0.1s ease-out;
|
| 64 |
-
}
|
| 65 |
-
@keyframes hitmarker-anim {
|
| 66 |
-
0% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
|
| 67 |
-
100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
|
| 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 |
</head>
|
|
|
|
| 123 |
<body class="text-white">
|
| 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 |
</div>
|
| 150 |
|
| 151 |
-
<!-- HUD
|
| 152 |
-
<div
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
<div class="text-blue-400 font-bold text-2xl">CT <span id="score-ct">0</span></div>
|
| 159 |
-
</div>
|
| 160 |
</div>
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
<!-- Health & Armor -->
|
| 165 |
-
<div class="flex gap-4">
|
| 166 |
-
<div class="bg-black/60 p-3 border-l-4 border-green-500">
|
| 167 |
-
<div class="text-xs text-gray-400">HEALTH</div>
|
| 168 |
-
<div class="text-3xl font-bold text-green-500" id="health-val">100</div>
|
| 169 |
-
</div>
|
| 170 |
-
<div class="bg-black/60 p-3 border-l-4 border-blue-400">
|
| 171 |
-
<div class="text-xs text-gray-400">ARMOR</div>
|
| 172 |
-
<div class="text-3xl font-bold text-blue-400" id="armor-val">100</div>
|
| 173 |
-
</div>
|
| 174 |
-
</div>
|
| 175 |
-
|
| 176 |
-
<!-- Kill Feed -->
|
| 177 |
-
<div id="kill-feed" class="absolute top-20 right-4 flex flex-col gap-1 text-right pointer-events-none">
|
| 178 |
-
<!-- Dynamic content -->
|
| 179 |
-
</div>
|
| 180 |
-
|
| 181 |
-
<!-- Ammo & Weapons -->
|
| 182 |
-
<div class="flex items-end gap-6">
|
| 183 |
-
<div class="text-right">
|
| 184 |
-
<div class="text-6xl font-bold leading-none" id="ammo-clip">30</div>
|
| 185 |
-
<div class="text-xl text-gray-400" id="ammo-reserve">90</div>
|
| 186 |
-
</div>
|
| 187 |
-
<div class="flex flex-col gap-1 w-32">
|
| 188 |
-
<div class="weapon-slot active bg-black/60 p-2 text-right text-sm font-bold" id="wep-primary">AK-47</div>
|
| 189 |
-
<div class="weapon-slot bg-black/60 p-2 text-right text-sm font-bold" id="wep-secondary">GLOCK-18</div>
|
| 190 |
-
<div class="weapon-slot bg-black/60 p-2 text-right text-sm font-bold" id="wep-knife">KNIFE</div>
|
| 191 |
-
</div>
|
| 192 |
-
</div>
|
| 193 |
</div>
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
<
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
|
|
|
| 205 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
</div>
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
</div>
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
</div>
|
|
|
|
| 229 |
|
| 230 |
-
|
| 231 |
-
|
| 232 |
const AudioEngine = {
|
| 233 |
synth: null,
|
| 234 |
noise: null,
|
|
@@ -345,8 +373,8 @@
|
|
| 345 |
let nextX = this.pos.x + moveDir.x * 2 * dt;
|
| 346 |
let nextZ = this.pos.z + moveDir.z * 2 * dt;
|
| 347 |
|
| 348 |
-
if (map[Math.floor(nextX)][Math.floor(this.pos.z)] === 0) this.pos.x = nextX;
|
| 349 |
-
if (map[Math.floor(this.pos.x)][Math.floor(nextZ)] === 0) this.pos.z = nextZ;
|
| 350 |
|
| 351 |
// Attack
|
| 352 |
if (dist < 10 && Date.now() - this.lastShot > 1000) {
|
|
@@ -376,7 +404,10 @@
|
|
| 376 |
let t = i/steps;
|
| 377 |
let cx = this.pos.x + dx * t;
|
| 378 |
let cz = this.pos.z + dz * t;
|
| 379 |
-
|
|
|
|
|
|
|
|
|
|
| 380 |
}
|
| 381 |
return true;
|
| 382 |
}
|
|
@@ -408,7 +439,19 @@
|
|
| 408 |
armor: 0,
|
| 409 |
speed: 4,
|
| 410 |
money: 800,
|
| 411 |
-
kills: 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
};
|
| 413 |
this.camera.pos = this.player.pos;
|
| 414 |
|
|
@@ -461,7 +504,7 @@
|
|
| 461 |
if (this.entities.length < 5) {
|
| 462 |
let x = Math.floor(Math.random() * (this.mapSize-2)) + 1;
|
| 463 |
let z = Math.floor(Math.random() * (this.mapSize-2)) + 1;
|
| 464 |
-
if (this.map[x][z] === 0 && (Math.abs(x - this.player.pos.x) > 5)) {
|
| 465 |
this.entities.push(new Entity(x, z, 'enemy', 100));
|
| 466 |
}
|
| 467 |
}
|
|
@@ -508,6 +551,12 @@
|
|
| 508 |
if (e.code === 'Digit2') this.switchWeapon(this.weapons.secondary);
|
| 509 |
if (e.code === 'Digit3') this.switchWeapon('knife');
|
| 510 |
if (e.code === 'KeyR') this.reload();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 511 |
});
|
| 512 |
document.addEventListener('keyup', (e) => this.keys[e.code] = false);
|
| 513 |
|
|
@@ -531,12 +580,22 @@
|
|
| 531 |
this.currentWeapon = key;
|
| 532 |
// Update UI
|
| 533 |
['primary', 'secondary', 'knife'].forEach(w => {
|
| 534 |
-
document.getElementById(`wep-${w}`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
});
|
| 536 |
let slot = 'primary';
|
| 537 |
if (key === this.weapons.secondary) slot = 'secondary';
|
| 538 |
if (key === 'knife') slot = 'knife';
|
| 539 |
-
document.getElementById(`wep-${slot}`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 540 |
this.updateAmmoUI();
|
| 541 |
}
|
| 542 |
|
|
@@ -574,6 +633,7 @@
|
|
| 574 |
reload() {
|
| 575 |
const w = WEAPONS[this.currentWeapon];
|
| 576 |
const a = this.ammo[this.currentWeapon];
|
|
|
|
| 577 |
if (a.clip < w.clip && a.reserve > 0) {
|
| 578 |
let need = w.clip - a.clip;
|
| 579 |
let take = Math.min(need, a.reserve);
|
|
@@ -587,6 +647,7 @@
|
|
| 587 |
const now = Date.now();
|
| 588 |
const w = WEAPONS[this.currentWeapon];
|
| 589 |
const a = this.ammo[this.currentWeapon];
|
|
|
|
| 590 |
|
| 591 |
if (now - this.lastShotTime < w.rate) return;
|
| 592 |
|
|
@@ -596,7 +657,7 @@
|
|
| 596 |
return;
|
| 597 |
}
|
| 598 |
|
| 599 |
-
if (a.clip <= 0) {
|
| 600 |
AudioEngine.playEmpty();
|
| 601 |
return;
|
| 602 |
}
|
|
@@ -607,14 +668,14 @@
|
|
| 607 |
AudioEngine.playShoot(w.type);
|
| 608 |
|
| 609 |
// Visuals
|
| 610 |
-
document.getElementById('muzzle-flash')
|
| 611 |
-
|
| 612 |
-
|
|
|
|
| 613 |
|
| 614 |
// Recoil kick
|
| 615 |
this.recoil = 5;
|
| 616 |
|
| 617 |
-
// Raycast
|
| 618 |
// Add spread
|
| 619 |
let spreadX = (Math.random() - 0.5) * w.spread;
|
| 620 |
let spreadZ = (Math.random() - 0.5) * w.spread;
|
|
@@ -663,11 +724,9 @@
|
|
| 663 |
let dist = e.pos.dist(this.player.pos);
|
| 664 |
if (dist > maxDist) continue;
|
| 665 |
|
| 666 |
-
// Check if ray passes near entity center (very rough box check)
|
| 667 |
let ex = Math.floor(e.pos.x);
|
| 668 |
let ez = Math.floor(e.pos.z);
|
| 669 |
if (ex === mapX && ez === mapZ) {
|
| 670 |
-
// Hit enemy
|
| 671 |
this.hitEntity(e, w.damage);
|
| 672 |
return;
|
| 673 |
}
|
|
@@ -690,9 +749,10 @@
|
|
| 690 |
AudioEngine.playHit();
|
| 691 |
|
| 692 |
// Hitmarker
|
| 693 |
-
document.getElementById('hitmarker')
|
| 694 |
-
|
| 695 |
-
|
|
|
|
| 696 |
|
| 697 |
if (entity.hp <= 0) {
|
| 698 |
entity.dead = true;
|
|
@@ -701,7 +761,6 @@
|
|
| 701 |
AudioEngine.playKill();
|
| 702 |
this.addKillFeed("Player", "Terrorist", this.currentWeapon === 'knife' ? 'KNIFE' : WEAPONS[this.currentWeapon].name);
|
| 703 |
|
| 704 |
-
// Respawn enemy logic (disappear after time)
|
| 705 |
setTimeout(() => {
|
| 706 |
this.entities = this.entities.filter(ent => ent !== entity);
|
| 707 |
}, 5000);
|
|
@@ -718,19 +777,6 @@
|
|
| 718 |
setTimeout(() => div.remove(), 5000);
|
| 719 |
}
|
| 720 |
|
| 721 |
-
takeDamage(amount) {
|
| 722 |
-
if (this.player.armor > 0) {
|
| 723 |
-
let absorb = amount * 0.66;
|
| 724 |
-
this.player.armor -= absorb;
|
| 725 |
-
this.player.hp -= (amount - absorb);
|
| 726 |
-
} else {
|
| 727 |
-
this.player.hp -= amount;
|
| 728 |
-
}
|
| 729 |
-
|
| 730 |
-
if (this.player.hp <= 0) this.gameOver();
|
| 731 |
-
this.updateHealthUI();
|
| 732 |
-
}
|
| 733 |
-
|
| 734 |
updateHealthUI() {
|
| 735 |
document.getElementById('health-val').innerText = Math.ceil(Math.max(0, this.player.hp));
|
| 736 |
document.getElementById('armor-val').innerText = Math.ceil(Math.max(0, this.player.armor));
|
|
@@ -742,8 +788,10 @@
|
|
| 742 |
document.getElementById('ammo-clip').innerText = a ? a.clip : 0;
|
| 743 |
document.getElementById('ammo-reserve').innerText = a ? a.reserve : 0;
|
| 744 |
|
| 745 |
-
document.getElementById('wep-primary')
|
| 746 |
-
document.getElementById('wep-secondary')
|
|
|
|
|
|
|
| 747 |
}
|
| 748 |
|
| 749 |
gameOver() {
|
|
@@ -766,26 +814,26 @@
|
|
| 766 |
|
| 767 |
if (moveVec.length() > 0) {
|
| 768 |
moveVec = moveVec.normalize().mul(moveSpeed);
|
| 769 |
-
// Collision Detection
|
| 770 |
let nextX = this.player.pos.x + moveVec.x;
|
| 771 |
let nextZ = this.player.pos.z + moveVec.z;
|
| 772 |
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 776 |
}
|
| 777 |
|
| 778 |
-
// Recoil recovery
|
| 779 |
if (this.recoil > 0) this.recoil -= dt * 10;
|
| 780 |
else this.recoil = 0;
|
| 781 |
|
| 782 |
-
// Update entities
|
| 783 |
this.entities.forEach(e => e.update(dt, this.player, this.map));
|
| 784 |
}
|
| 785 |
|
| 786 |
-
// --- THE RENDERER (Raycasting) ---
|
| 787 |
render() {
|
| 788 |
-
// Floor & Ceiling
|
| 789 |
const grad = this.ctx.createLinearGradient(0, 0, 0, this.height);
|
| 790 |
grad.addColorStop(0, '#222');
|
| 791 |
grad.addColorStop(0.5, '#444');
|
|
@@ -795,7 +843,7 @@
|
|
| 795 |
this.ctx.fillRect(0, 0, this.width, this.height);
|
| 796 |
|
| 797 |
// Raycasting Walls
|
| 798 |
-
for (let x = 0; x < this.width; x += 2) {
|
| 799 |
let cameraX = 2 * x / this.width - 1;
|
| 800 |
let rayDirX = this.camera.dir.x + this.camera.plane.x * cameraX;
|
| 801 |
let rayDirZ = this.camera.dir.z + this.camera.plane.z * cameraX;
|
|
@@ -815,7 +863,6 @@
|
|
| 815 |
|
| 816 |
let hit = 0, side, wallDist;
|
| 817 |
|
| 818 |
-
// DDA Loop
|
| 819 |
while (hit === 0) {
|
| 820 |
if (sideDistX < sideDistZ) {
|
| 821 |
sideDistX += deltaDistX;
|
|
@@ -826,68 +873,51 @@
|
|
| 826 |
mapZ += stepZ;
|
| 827 |
side = 1;
|
| 828 |
}
|
|
|
|
| 829 |
if (this.map[mapX][mapZ] > 0) hit = 1;
|
| 830 |
}
|
| 831 |
|
|
|
|
|
|
|
| 832 |
if (side === 0) wallDist = (mapX - this.player.pos.x + (1 - stepX) / 2) / rayDirX;
|
| 833 |
else wallDist = (mapZ - this.player.pos.z + (1 - stepZ) / 2) / rayDirZ;
|
| 834 |
|
| 835 |
let lineHeight = Math.floor(this.height / wallDist);
|
| 836 |
let drawStart = Math.floor(-lineHeight / 2 + this.height / 2) + this.recoil;
|
| 837 |
-
let drawEnd = Math.floor(lineHeight / 2 + this.height / 2) + this.recoil;
|
| 838 |
-
|
| 839 |
-
// Color
|
| 840 |
-
let color = '#555'; // Default Wall
|
| 841 |
-
if (this.map[mapX][mapZ] === 1) color = '#777';
|
| 842 |
|
| 843 |
-
|
| 844 |
-
if
|
| 845 |
-
// Darken for Z side
|
| 846 |
-
color = color.replace(/^#/, '#0'); // Cheap darken trick
|
| 847 |
-
}
|
| 848 |
|
| 849 |
-
// Distance fog
|
| 850 |
let alpha = Math.min(1, wallDist / 15);
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
if(side===1) { r-=40; g-=40; b-=40; }
|
| 855 |
-
|
| 856 |
-
// Apply fog
|
| 857 |
-
r = r * (1-alpha) + 0 * alpha;
|
| 858 |
-
g = g * (1-alpha) + 0 * alpha;
|
| 859 |
-
b = b * (1-alpha) + 0 * alpha;
|
| 860 |
|
| 861 |
-
this.ctx.fillStyle = `rgb(${r},${g},${b})`;
|
| 862 |
this.ctx.fillRect(x, drawStart, 2, lineHeight);
|
| 863 |
}
|
| 864 |
|
| 865 |
-
// Render Entities
|
| 866 |
this.entities.forEach(e => {
|
| 867 |
if (e.dead) return;
|
| 868 |
let spriteX = e.pos.x - this.player.pos.x;
|
| 869 |
let spriteZ = e.pos.z - this.player.pos.z;
|
| 870 |
|
| 871 |
-
// Transform sprite with the inverse camera matrix
|
| 872 |
let invDet = 1.0 / (this.camera.plane.x * this.camera.dir.z - this.camera.dir.x * this.camera.plane.z);
|
| 873 |
let transformX = invDet * (this.camera.dir.z * spriteX - this.camera.dir.x * spriteZ);
|
| 874 |
let transformY = invDet * (-this.camera.plane.z * spriteX + this.camera.plane.x * spriteZ);
|
| 875 |
|
|
|
|
|
|
|
| 876 |
let spriteScreenX = Math.floor((this.width / 2) * (1 + transformX / transformY));
|
| 877 |
let spriteHeight = Math.abs(Math.floor(this.height / (transformY)));
|
| 878 |
|
| 879 |
-
// Don't draw if behind player or too far
|
| 880 |
-
if (transformY < 0 || transformY > 20) return;
|
| 881 |
-
|
| 882 |
let drawStartY = -spriteHeight / 2 + this.height / 2;
|
| 883 |
let drawStartX = -spriteHeight / 2 + spriteScreenX;
|
| 884 |
-
let drawEndX = spriteHeight / 2 + spriteScreenX;
|
| 885 |
|
| 886 |
-
// Draw Enemy Box (Very primitive sprite)
|
| 887 |
if (e.type === 'enemy') {
|
| 888 |
this.ctx.fillStyle = 'rgba(255, 0, 0, 0.8)';
|
| 889 |
this.ctx.fillRect(drawStartX, drawStartY, spriteHeight/2, spriteHeight);
|
| 890 |
-
// Name tag
|
| 891 |
this.ctx.font = "12px Arial";
|
| 892 |
this.ctx.fillStyle = "white";
|
| 893 |
this.ctx.fillText("TERRORIST", drawStartX, drawStartY - 5);
|
|
@@ -895,14 +925,13 @@
|
|
| 895 |
});
|
| 896 |
|
| 897 |
// Weapon Viewmodel
|
| 898 |
-
this.ctx.fillStyle = '#333';
|
| 899 |
-
// Gun body
|
| 900 |
let bob = Math.sin(Date.now()/100) * 5;
|
| 901 |
let recoilY = this.recoil * 2;
|
| 902 |
|
|
|
|
| 903 |
this.ctx.fillRect(this.width/2 + 50 + bob, this.height - 150 - recoilY, 150, 100);
|
| 904 |
this.ctx.fillStyle = '#111';
|
| 905 |
-
this.ctx.fillRect(this.width/2 + 200 + bob, this.height - 120 - recoilY, 100, 40);
|
| 906 |
}
|
| 907 |
|
| 908 |
loop(time) {
|
|
@@ -917,4 +946,9 @@
|
|
| 917 |
}
|
| 918 |
}
|
| 919 |
|
| 920 |
-
// Init
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="UTF-8">
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
+
<title>Counter-Strike: Web Ops</title>
|
| 8 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 9 |
+
<link href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@400;600;700&display=swap" rel="stylesheet">
|
| 10 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.49/Tone.js"></script>
|
| 11 |
+
<style>
|
| 12 |
+
:root {
|
| 13 |
+
--cs-orange: #d57b00;
|
| 14 |
+
--cs-blue: #4f7cac;
|
| 15 |
+
--cs-bg: #1a1a1a;
|
| 16 |
+
--cs-dark: #111;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
body {
|
| 20 |
+
margin: 0;
|
| 21 |
+
overflow: hidden;
|
| 22 |
+
background-color: #000;
|
| 23 |
+
font-family: 'Rajdhani', sans-serif;
|
| 24 |
+
user-select: none;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
/* UI Styling */
|
| 28 |
+
.cs-hud {
|
| 29 |
+
text-shadow: 0 0 2px rgba(0, 0, 0, 0.8);
|
| 30 |
+
letter-spacing: 1px;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
.weapon-slot {
|
| 34 |
+
transition: all 0.2s;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.weapon-slot.active {
|
| 38 |
+
background: rgba(255, 255, 255, 0.2);
|
| 39 |
+
border-left: 3px solid white;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
/* Crosshair */
|
| 43 |
+
#crosshair {
|
| 44 |
+
position: absolute;
|
| 45 |
+
top: 50%;
|
| 46 |
+
left: 50%;
|
| 47 |
+
transform: translate(-50%, -50%);
|
| 48 |
+
pointer-events: none;
|
| 49 |
+
z-index: 10;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/* Hit Marker */
|
| 53 |
+
#hitmarker {
|
| 54 |
+
position: absolute;
|
| 55 |
+
top: 50%;
|
| 56 |
+
left: 50%;
|
| 57 |
+
transform: translate(-50%, -50%);
|
| 58 |
+
width: 40px;
|
| 59 |
+
height: 40px;
|
| 60 |
+
opacity: 0;
|
| 61 |
+
pointer-events: none;
|
| 62 |
+
z-index: 11;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
#hitmarker.active {
|
| 66 |
+
animation: hitmarker-anim 0.1s ease-out;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
@keyframes hitmarker-anim {
|
| 70 |
+
0% {
|
| 71 |
+
opacity: 1;
|
| 72 |
+
transform: translate(-50%, -50%) scale(1.2);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
100% {
|
| 76 |
+
opacity: 0;
|
| 77 |
+
transform: translate(-50%, -50%) scale(1);
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
/* Damage Overlay */
|
| 82 |
+
#damage-overlay {
|
| 83 |
+
background: radial-gradient(circle, transparent 50%, rgba(255, 0, 0, 0.6) 100%);
|
| 84 |
+
opacity: 0;
|
| 85 |
+
transition: opacity 0.2s;
|
| 86 |
+
pointer-events: none;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
/* Muzzle Flash */
|
| 90 |
+
.muzzle-flash {
|
| 91 |
+
position: absolute;
|
| 92 |
+
width: 100px;
|
| 93 |
+
height: 100px;
|
| 94 |
+
background: radial-gradient(circle, #ffaa00 0%, transparent 70%);
|
| 95 |
+
border-radius: 50%;
|
| 96 |
+
opacity: 0;
|
| 97 |
+
pointer-events: none;
|
| 98 |
+
mix-blend-mode: screen;
|
| 99 |
+
z-index: 5;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
.muzzle-flash.active {
|
| 103 |
+
animation: flash-anim 0.05s linear;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
@keyframes flash-anim {
|
| 107 |
+
0% {
|
| 108 |
+
opacity: 0.8;
|
| 109 |
+
transform: scale(0.5);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
100% {
|
| 113 |
+
opacity: 0;
|
| 114 |
+
transform: scale(1.5);
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
/* Menus */
|
| 119 |
+
.menu-overlay {
|
| 120 |
+
background: rgba(0, 0, 0, 0.85);
|
| 121 |
+
backdrop-filter: blur(5px);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.btn-cs {
|
| 125 |
+
background: linear-gradient(to bottom, #555, #333);
|
| 126 |
+
border: 1px solid #777;
|
| 127 |
+
color: white;
|
| 128 |
+
text-transform: uppercase;
|
| 129 |
+
clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
|
| 130 |
+
transition: all 0.2s;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
.btn-cs:hover {
|
| 134 |
+
background: linear-gradient(to bottom, #666, #444);
|
| 135 |
+
border-color: white;
|
| 136 |
+
transform: translateY(-2px);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
canvas {
|
| 140 |
+
display: block;
|
| 141 |
+
}
|
| 142 |
+
</style>
|
| 143 |
</head>
|
| 144 |
+
|
| 145 |
<body class="text-white">
|
| 146 |
|
| 147 |
+
<!-- Canvas Layer -->
|
| 148 |
+
<canvas id="gameCanvas" class="absolute top-0 left-0 w-full h-full"></canvas>
|
| 149 |
+
|
| 150 |
+
<!-- Visual Effects Layer -->
|
| 151 |
+
<div id="muzzle-flash" class="muzzle-flash" style="top: 60%; left: 50%; transform: translate(-50%, -50%);"></div>
|
| 152 |
+
<div id="hitmarker">
|
| 153 |
+
<svg width="40" height="40" viewBox="0 0 40 40">
|
| 154 |
+
<line x1="5" y1="5" x2="15" y2="15" stroke="white" stroke-width="2" />
|
| 155 |
+
<line x1="35" y1="5" x2="25" y2="15" stroke="white" stroke-width="2" />
|
| 156 |
+
<line x1="5" y1="35" x2="15" y2="25" stroke="white" stroke-width="2" />
|
| 157 |
+
<line x1="35" y1="35" x2="25" y2="25" stroke="white" stroke-width="2" />
|
| 158 |
+
</svg>
|
| 159 |
+
</div>
|
| 160 |
+
<div id="damage-overlay" class="absolute top-0 left-0 w-full h-full z-20"></div>
|
| 161 |
+
|
| 162 |
+
<!-- Crosshair -->
|
| 163 |
+
<div id="crosshair">
|
| 164 |
+
<svg width="32" height="32" viewBox="0 0 32 32" fill="none">
|
| 165 |
+
<rect x="15" y="0" width="2" height="10" fill="white" />
|
| 166 |
+
<rect x="15" y="22" width="2" height="10" fill="white" />
|
| 167 |
+
<rect x="22" y="15" width="10" height="2" fill="white" />
|
| 168 |
+
<rect x="0" y="15" width="10" height="2" fill="white" />
|
| 169 |
+
<circle cx="16" cy="16" r="1.5" fill="white" />
|
| 170 |
+
</svg>
|
| 171 |
+
</div>
|
| 172 |
+
|
| 173 |
+
<!-- HUD Layer -->
|
| 174 |
+
<div id="hud" class="absolute top-0 left-0 w-full h-full z-30 pointer-events-none hidden">
|
| 175 |
+
<!-- Top Info -->
|
| 176 |
+
<div class="absolute top-4 left-0 w-full flex justify-center cs-hud">
|
| 177 |
+
<div class="bg-black/50 px-6 py-2 border-b-2 border-white/20 flex items-center gap-8">
|
| 178 |
+
<div class="text-red-500 font-bold text-2xl">T <span id="score-t">0</span></div>
|
| 179 |
+
<div class="text-yellow-500 font-bold text-xl tracking-widest" id="timer">01:30</div>
|
| 180 |
+
<div class="text-blue-400 font-bold text-2xl">CT <span id="score-ct">0</span></div>
|
| 181 |
+
</div>
|
| 182 |
</div>
|
| 183 |
|
| 184 |
+
<!-- Bottom HUD -->
|
| 185 |
+
<div class="absolute bottom-0 left-0 w-full flex justify-between items-end p-6 cs-hud">
|
| 186 |
+
<!-- Health & Armor -->
|
| 187 |
+
<div class="flex gap-4">
|
| 188 |
+
<div class="bg-black/60 p-3 border-l-4 border-green-500">
|
| 189 |
+
<div class="text-xs text-gray-400">HEALTH</div>
|
| 190 |
+
<div class="text-3xl font-bold text-green-500" id="health-val">100</div>
|
|
|
|
|
|
|
| 191 |
</div>
|
| 192 |
+
<div class="bg-black/60 p-3 border-l-4 border-blue-400">
|
| 193 |
+
<div class="text-xs text-gray-400">ARMOR</div>
|
| 194 |
+
<div class="text-3xl font-bold text-blue-400" id="armor-val">100</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
</div>
|
| 196 |
+
</div>
|
| 197 |
+
|
| 198 |
+
<!-- Kill Feed -->
|
| 199 |
+
<div id="kill-feed" class="absolute top-20 right-4 flex flex-col gap-1 text-right pointer-events-none">
|
| 200 |
+
<!-- Dynamic content -->
|
| 201 |
+
</div>
|
| 202 |
+
|
| 203 |
+
<!-- Ammo & Weapons -->
|
| 204 |
+
<div class="flex items-end gap-6">
|
| 205 |
+
<div class="text-right">
|
| 206 |
+
<div class="text-6xl font-bold leading-none" id="ammo-clip">30</div>
|
| 207 |
+
<div class="text-xl text-gray-400" id="ammo-reserve">90</div>
|
| 208 |
</div>
|
| 209 |
+
<div class="flex flex-col gap-1 w-32">
|
| 210 |
+
<div class="weapon-slot active bg-black/60 p-2 text-right text-sm font-bold" id="wep-primary">AK-47</div>
|
| 211 |
+
<div class="weapon-slot bg-black/60 p-2 text-right text-sm font-bold" id="wep-secondary">GLOCK-18</div>
|
| 212 |
+
<div class="weapon-slot bg-black/60 p-2 text-right text-sm font-bold" id="wep-knife">KNIFE</div>
|
| 213 |
+
</div>
|
| 214 |
+
</div>
|
| 215 |
</div>
|
| 216 |
+
</div>
|
| 217 |
+
|
| 218 |
+
<!-- Start Menu -->
|
| 219 |
+
<div id="start-menu"
|
| 220 |
+
class="menu-overlay absolute top-0 left-0 w-full h-full z-50 flex flex-col items-center justify-center text-center">
|
| 221 |
+
<h1 class="text-6xl font-bold mb-2 text-white italic tracking-tighter"
|
| 222 |
+
style="text-shadow: 0 0 20px rgba(255,255,255,0.5);">COUNTER-STRIKE</h1>
|
| 223 |
+
<h2 class="text-2xl text-gray-400 mb-8 tracking-[0.5em]">WEB OPS</h2>
|
| 224 |
+
|
| 225 |
+
<div class="bg-black/80 p-8 border border-gray-700 max-w-md w-full rounded-lg shadow-2xl">
|
| 226 |
+
<p class="text-gray-300 mb-6 text-sm">Mouse to Look | WASD to Move | Click to Shoot | 1/2/3 for Weapons | B to Buy
|
| 227 |
+
</p>
|
| 228 |
+
<button onclick="game.start()" class="btn-cs w-full py-4 text-xl font-bold mb-4">Start Mission</button>
|
| 229 |
+
<div class="text-xs text-gray-500 mt-4">Built with <a href="https://huggingface.co/spaces/akhaliq/anycoder"
|
| 230 |
+
target="_blank" class="text-blue-400 hover:underline">anycoder</a></div>
|
| 231 |
</div>
|
| 232 |
+
</div>
|
| 233 |
+
|
| 234 |
+
<!-- Game Over Menu -->
|
| 235 |
+
<div id="game-over-menu"
|
| 236 |
+
class="menu-overlay absolute top-0 left-0 w-full h-full z-50 flex flex-col items-center justify-center hidden">
|
| 237 |
+
<h1 class="text-5xl font-bold mb-4 text-red-500">MISSION FAILED</h1>
|
| 238 |
+
<p class="text-xl text-white mb-8">Kills: <span id="final-score">0</span></p>
|
| 239 |
+
<button onclick="location.reload()" class="btn-cs px-8 py-3 text-lg font-bold">RETRY</button>
|
| 240 |
+
</div>
|
| 241 |
+
|
| 242 |
+
<!-- Buy Menu (Hidden by default) -->
|
| 243 |
+
<div id="buy-menu"
|
| 244 |
+
class="menu-overlay absolute top-0 left-0 w-full h-full z-40 flex items-center justify-center hidden">
|
| 245 |
+
<div class="bg-black/90 border border-yellow-600 p-8 w-[600px] max-w-full">
|
| 246 |
+
<h2 class="text-3xl text-yellow-500 font-bold mb-6 border-b border-gray-700 pb-2">BUY MENU</h2>
|
| 247 |
+
<div class="grid grid-cols-2 gap-4">
|
| 248 |
+
<button onclick="game.buyWeapon('ak47')" class="btn-cs p-3 text-left flex justify-between"><span>AK-47</span> <span class="text-yellow-500">$2700</span></button>
|
| 249 |
+
<button onclick="game.buyWeapon('m4a1')" class="btn-cs p-3 text-left flex justify-between"><span>M4A4</span> <span class="text-yellow-500">$3100</span></button>
|
| 250 |
+
<button onclick="game.buyWeapon('awp')" class="btn-cs p-3 text-left flex justify-between"><span>AWP</span> <span class="text-yellow-500">$4750</span></button>
|
| 251 |
+
<button onclick="game.buyWeapon('deagle')" class="btn-cs p-3 text-left flex justify-between"><span>DESERT EAGLE</span> <span class="text-yellow-500">$700</span></button>
|
| 252 |
+
<button onclick="game.buyWeapon('armor')" class="btn-cs p-3 text-left flex justify-between"><span>KEVLAR + HELMET</span> <span class="text-yellow-500">$1000</span></button>
|
| 253 |
+
</div>
|
| 254 |
+
<p class="mt-6 text-center text-gray-400 text-sm">Press 'B' or 'ESC' to close</p>
|
| 255 |
</div>
|
| 256 |
+
</div>
|
| 257 |
|
| 258 |
+
<script>
|
| 259 |
+
// --- Audio Engine (Tone.js) ---
|
| 260 |
const AudioEngine = {
|
| 261 |
synth: null,
|
| 262 |
noise: null,
|
|
|
|
| 373 |
let nextX = this.pos.x + moveDir.x * 2 * dt;
|
| 374 |
let nextZ = this.pos.z + moveDir.z * 2 * dt;
|
| 375 |
|
| 376 |
+
if (map[Math.floor(nextX)] && map[Math.floor(nextX)][Math.floor(this.pos.z)] === 0) this.pos.x = nextX;
|
| 377 |
+
if (map[Math.floor(this.pos.x)] && map[Math.floor(this.pos.x)][Math.floor(nextZ)] === 0) this.pos.z = nextZ;
|
| 378 |
|
| 379 |
// Attack
|
| 380 |
if (dist < 10 && Date.now() - this.lastShot > 1000) {
|
|
|
|
| 404 |
let t = i/steps;
|
| 405 |
let cx = this.pos.x + dx * t;
|
| 406 |
let cz = this.pos.z + dz * t;
|
| 407 |
+
let mx = Math.floor(cx);
|
| 408 |
+
let mz = Math.floor(cz);
|
| 409 |
+
if (mx < 0 || mx >= map.length || mz < 0 || mz >= map[0].length) return false;
|
| 410 |
+
if (map[mx][mz] > 0) return false; // Wall hit
|
| 411 |
}
|
| 412 |
return true;
|
| 413 |
}
|
|
|
|
| 439 |
armor: 0,
|
| 440 |
speed: 4,
|
| 441 |
money: 800,
|
| 442 |
+
kills: 0,
|
| 443 |
+
takeDamage: (amount) => {
|
| 444 |
+
if (this.player.armor > 0) {
|
| 445 |
+
let absorb = amount * 0.66;
|
| 446 |
+
this.player.armor -= absorb;
|
| 447 |
+
this.player.hp -= (amount - absorb);
|
| 448 |
+
} else {
|
| 449 |
+
this.player.hp -= amount;
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
if (this.player.hp <= 0) this.gameOver();
|
| 453 |
+
this.updateHealthUI();
|
| 454 |
+
}
|
| 455 |
};
|
| 456 |
this.camera.pos = this.player.pos;
|
| 457 |
|
|
|
|
| 504 |
if (this.entities.length < 5) {
|
| 505 |
let x = Math.floor(Math.random() * (this.mapSize-2)) + 1;
|
| 506 |
let z = Math.floor(Math.random() * (this.mapSize-2)) + 1;
|
| 507 |
+
if (this.map[x] && this.map[x][z] === 0 && (Math.abs(x - this.player.pos.x) > 5)) {
|
| 508 |
this.entities.push(new Entity(x, z, 'enemy', 100));
|
| 509 |
}
|
| 510 |
}
|
|
|
|
| 551 |
if (e.code === 'Digit2') this.switchWeapon(this.weapons.secondary);
|
| 552 |
if (e.code === 'Digit3') this.switchWeapon('knife');
|
| 553 |
if (e.code === 'KeyR') this.reload();
|
| 554 |
+
if (e.code === 'Escape') {
|
| 555 |
+
const menu = document.getElementById('buy-menu');
|
| 556 |
+
if (!menu.classList.contains('hidden')) {
|
| 557 |
+
this.toggleBuyMenu();
|
| 558 |
+
}
|
| 559 |
+
}
|
| 560 |
});
|
| 561 |
document.addEventListener('keyup', (e) => this.keys[e.code] = false);
|
| 562 |
|
|
|
|
| 580 |
this.currentWeapon = key;
|
| 581 |
// Update UI
|
| 582 |
['primary', 'secondary', 'knife'].forEach(w => {
|
| 583 |
+
let el = document.getElementById(`wep-${w}`);
|
| 584 |
+
if(el) {
|
| 585 |
+
el.classList.remove('active');
|
| 586 |
+
el.style.borderLeft = 'none';
|
| 587 |
+
el.style.background = 'rgba(0,0,0,0.6)';
|
| 588 |
+
}
|
| 589 |
});
|
| 590 |
let slot = 'primary';
|
| 591 |
if (key === this.weapons.secondary) slot = 'secondary';
|
| 592 |
if (key === 'knife') slot = 'knife';
|
| 593 |
+
let activeEl = document.getElementById(`wep-${slot}`);
|
| 594 |
+
if(activeEl) {
|
| 595 |
+
activeEl.classList.add('active');
|
| 596 |
+
activeEl.style.borderLeft = '3px solid white';
|
| 597 |
+
activeEl.style.background = 'rgba(255,255,255,0.2)';
|
| 598 |
+
}
|
| 599 |
this.updateAmmoUI();
|
| 600 |
}
|
| 601 |
|
|
|
|
| 633 |
reload() {
|
| 634 |
const w = WEAPONS[this.currentWeapon];
|
| 635 |
const a = this.ammo[this.currentWeapon];
|
| 636 |
+
if (!w || !a) return;
|
| 637 |
if (a.clip < w.clip && a.reserve > 0) {
|
| 638 |
let need = w.clip - a.clip;
|
| 639 |
let take = Math.min(need, a.reserve);
|
|
|
|
| 647 |
const now = Date.now();
|
| 648 |
const w = WEAPONS[this.currentWeapon];
|
| 649 |
const a = this.ammo[this.currentWeapon];
|
| 650 |
+
if (!w) return;
|
| 651 |
|
| 652 |
if (now - this.lastShotTime < w.rate) return;
|
| 653 |
|
|
|
|
| 657 |
return;
|
| 658 |
}
|
| 659 |
|
| 660 |
+
if (!a || a.clip <= 0) {
|
| 661 |
AudioEngine.playEmpty();
|
| 662 |
return;
|
| 663 |
}
|
|
|
|
| 668 |
AudioEngine.playShoot(w.type);
|
| 669 |
|
| 670 |
// Visuals
|
| 671 |
+
let flash = document.getElementById('muzzle-flash');
|
| 672 |
+
flash.classList.remove('active');
|
| 673 |
+
void flash.offsetWidth; // trigger reflow
|
| 674 |
+
flash.classList.add('active');
|
| 675 |
|
| 676 |
// Recoil kick
|
| 677 |
this.recoil = 5;
|
| 678 |
|
|
|
|
| 679 |
// Add spread
|
| 680 |
let spreadX = (Math.random() - 0.5) * w.spread;
|
| 681 |
let spreadZ = (Math.random() - 0.5) * w.spread;
|
|
|
|
| 724 |
let dist = e.pos.dist(this.player.pos);
|
| 725 |
if (dist > maxDist) continue;
|
| 726 |
|
|
|
|
| 727 |
let ex = Math.floor(e.pos.x);
|
| 728 |
let ez = Math.floor(e.pos.z);
|
| 729 |
if (ex === mapX && ez === mapZ) {
|
|
|
|
| 730 |
this.hitEntity(e, w.damage);
|
| 731 |
return;
|
| 732 |
}
|
|
|
|
| 749 |
AudioEngine.playHit();
|
| 750 |
|
| 751 |
// Hitmarker
|
| 752 |
+
let hm = document.getElementById('hitmarker');
|
| 753 |
+
hm.classList.remove('active');
|
| 754 |
+
void hm.offsetWidth;
|
| 755 |
+
hm.classList.add('active');
|
| 756 |
|
| 757 |
if (entity.hp <= 0) {
|
| 758 |
entity.dead = true;
|
|
|
|
| 761 |
AudioEngine.playKill();
|
| 762 |
this.addKillFeed("Player", "Terrorist", this.currentWeapon === 'knife' ? 'KNIFE' : WEAPONS[this.currentWeapon].name);
|
| 763 |
|
|
|
|
| 764 |
setTimeout(() => {
|
| 765 |
this.entities = this.entities.filter(ent => ent !== entity);
|
| 766 |
}, 5000);
|
|
|
|
| 777 |
setTimeout(() => div.remove(), 5000);
|
| 778 |
}
|
| 779 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 780 |
updateHealthUI() {
|
| 781 |
document.getElementById('health-val').innerText = Math.ceil(Math.max(0, this.player.hp));
|
| 782 |
document.getElementById('armor-val').innerText = Math.ceil(Math.max(0, this.player.armor));
|
|
|
|
| 788 |
document.getElementById('ammo-clip').innerText = a ? a.clip : 0;
|
| 789 |
document.getElementById('ammo-reserve').innerText = a ? a.reserve : 0;
|
| 790 |
|
| 791 |
+
let pri = document.getElementById('wep-primary');
|
| 792 |
+
let sec = document.getElementById('wep-secondary');
|
| 793 |
+
if(pri) pri.innerText = WEAPONS[this.weapons.primary].name;
|
| 794 |
+
if(sec) sec.innerText = WEAPONS[this.weapons.secondary].name;
|
| 795 |
}
|
| 796 |
|
| 797 |
gameOver() {
|
|
|
|
| 814 |
|
| 815 |
if (moveVec.length() > 0) {
|
| 816 |
moveVec = moveVec.normalize().mul(moveSpeed);
|
|
|
|
| 817 |
let nextX = this.player.pos.x + moveVec.x;
|
| 818 |
let nextZ = this.player.pos.z + moveVec.z;
|
| 819 |
|
| 820 |
+
let mx = Math.floor(nextX);
|
| 821 |
+
let mz = Math.floor(nextZ);
|
| 822 |
+
let cx = Math.floor(this.player.pos.x);
|
| 823 |
+
let cz = Math.floor(this.player.pos.z);
|
| 824 |
+
|
| 825 |
+
if (mx >= 0 && mx < this.mapSize && this.map[mx] && this.map[mx][cz] === 0) this.player.pos.x = nextX;
|
| 826 |
+
if (mz >= 0 && mz < this.mapSize && this.map[cx] && this.map[cx][mz] === 0) this.player.pos.z = nextZ;
|
| 827 |
}
|
| 828 |
|
|
|
|
| 829 |
if (this.recoil > 0) this.recoil -= dt * 10;
|
| 830 |
else this.recoil = 0;
|
| 831 |
|
|
|
|
| 832 |
this.entities.forEach(e => e.update(dt, this.player, this.map));
|
| 833 |
}
|
| 834 |
|
|
|
|
| 835 |
render() {
|
| 836 |
+
// Floor & Ceiling
|
| 837 |
const grad = this.ctx.createLinearGradient(0, 0, 0, this.height);
|
| 838 |
grad.addColorStop(0, '#222');
|
| 839 |
grad.addColorStop(0.5, '#444');
|
|
|
|
| 843 |
this.ctx.fillRect(0, 0, this.width, this.height);
|
| 844 |
|
| 845 |
// Raycasting Walls
|
| 846 |
+
for (let x = 0; x < this.width; x += 2) {
|
| 847 |
let cameraX = 2 * x / this.width - 1;
|
| 848 |
let rayDirX = this.camera.dir.x + this.camera.plane.x * cameraX;
|
| 849 |
let rayDirZ = this.camera.dir.z + this.camera.plane.z * cameraX;
|
|
|
|
| 863 |
|
| 864 |
let hit = 0, side, wallDist;
|
| 865 |
|
|
|
|
| 866 |
while (hit === 0) {
|
| 867 |
if (sideDistX < sideDistZ) {
|
| 868 |
sideDistX += deltaDistX;
|
|
|
|
| 873 |
mapZ += stepZ;
|
| 874 |
side = 1;
|
| 875 |
}
|
| 876 |
+
if (mapX < 0 || mapX >= this.mapSize || mapZ < 0 || mapZ >= this.mapSize) { hit = 1; break; }
|
| 877 |
if (this.map[mapX][mapZ] > 0) hit = 1;
|
| 878 |
}
|
| 879 |
|
| 880 |
+
if (hit === 0) continue;
|
| 881 |
+
|
| 882 |
if (side === 0) wallDist = (mapX - this.player.pos.x + (1 - stepX) / 2) / rayDirX;
|
| 883 |
else wallDist = (mapZ - this.player.pos.z + (1 - stepZ) / 2) / rayDirZ;
|
| 884 |
|
| 885 |
let lineHeight = Math.floor(this.height / wallDist);
|
| 886 |
let drawStart = Math.floor(-lineHeight / 2 + this.height / 2) + this.recoil;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 887 |
|
| 888 |
+
let r=180, g=180, b=180;
|
| 889 |
+
if(side===1) { r=140; g=140; b=140; }
|
|
|
|
|
|
|
|
|
|
| 890 |
|
|
|
|
| 891 |
let alpha = Math.min(1, wallDist / 15);
|
| 892 |
+
r = r * (1-alpha);
|
| 893 |
+
g = g * (1-alpha);
|
| 894 |
+
b = b * (1-alpha);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 895 |
|
| 896 |
+
this.ctx.fillStyle = `rgb(${Math.floor(r)},${Math.floor(g)},${Math.floor(b)})`;
|
| 897 |
this.ctx.fillRect(x, drawStart, 2, lineHeight);
|
| 898 |
}
|
| 899 |
|
| 900 |
+
// Render Entities
|
| 901 |
this.entities.forEach(e => {
|
| 902 |
if (e.dead) return;
|
| 903 |
let spriteX = e.pos.x - this.player.pos.x;
|
| 904 |
let spriteZ = e.pos.z - this.player.pos.z;
|
| 905 |
|
|
|
|
| 906 |
let invDet = 1.0 / (this.camera.plane.x * this.camera.dir.z - this.camera.dir.x * this.camera.plane.z);
|
| 907 |
let transformX = invDet * (this.camera.dir.z * spriteX - this.camera.dir.x * spriteZ);
|
| 908 |
let transformY = invDet * (-this.camera.plane.z * spriteX + this.camera.plane.x * spriteZ);
|
| 909 |
|
| 910 |
+
if (transformY <= 0 || transformY > 20) return;
|
| 911 |
+
|
| 912 |
let spriteScreenX = Math.floor((this.width / 2) * (1 + transformX / transformY));
|
| 913 |
let spriteHeight = Math.abs(Math.floor(this.height / (transformY)));
|
| 914 |
|
|
|
|
|
|
|
|
|
|
| 915 |
let drawStartY = -spriteHeight / 2 + this.height / 2;
|
| 916 |
let drawStartX = -spriteHeight / 2 + spriteScreenX;
|
|
|
|
| 917 |
|
|
|
|
| 918 |
if (e.type === 'enemy') {
|
| 919 |
this.ctx.fillStyle = 'rgba(255, 0, 0, 0.8)';
|
| 920 |
this.ctx.fillRect(drawStartX, drawStartY, spriteHeight/2, spriteHeight);
|
|
|
|
| 921 |
this.ctx.font = "12px Arial";
|
| 922 |
this.ctx.fillStyle = "white";
|
| 923 |
this.ctx.fillText("TERRORIST", drawStartX, drawStartY - 5);
|
|
|
|
| 925 |
});
|
| 926 |
|
| 927 |
// Weapon Viewmodel
|
|
|
|
|
|
|
| 928 |
let bob = Math.sin(Date.now()/100) * 5;
|
| 929 |
let recoilY = this.recoil * 2;
|
| 930 |
|
| 931 |
+
this.ctx.fillStyle = '#333';
|
| 932 |
this.ctx.fillRect(this.width/2 + 50 + bob, this.height - 150 - recoilY, 150, 100);
|
| 933 |
this.ctx.fillStyle = '#111';
|
| 934 |
+
this.ctx.fillRect(this.width/2 + 200 + bob, this.height - 120 - recoilY, 100, 40);
|
| 935 |
}
|
| 936 |
|
| 937 |
loop(time) {
|
|
|
|
| 946 |
}
|
| 947 |
}
|
| 948 |
|
| 949 |
+
// Init
|
| 950 |
+
const game = new Game();
|
| 951 |
+
</script>
|
| 952 |
+
</body>
|
| 953 |
+
|
| 954 |
+
</html>
|