🎮ArcadeLab

Mini CS

by CyberCobra24
172 lines3.5 KB
▶ Play
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mini CS</title>

<style>
body {
    margin: 0;
    background: #222;
    color: white;
    font-family: Arial;
    text-align: center;
}

canvas {
    background: #444;
    display: block;
    margin: 15px auto;
    border: 3px solid #888;
    cursor: crosshair;
}

h1 {
    margin-bottom: 5px;
}

button {
    padding: 12px 25px;
    font-size: 18px;
    background: #e0a000;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}
</style>
</head>

<body>

<h1>MINI CS</h1>
<p>Нажимай мышкой, чтобы стрелять</p>

<canvas id="game" width="900" height="600"></canvas>

<button onclick="restart()">Перезапустить</button>

<script>
const canvas = document.getElementById("game");
const ctx = canvas.getContext("2d");

let enemy = { x: 650, y: 300, radius: 35 };
let enemyHP = 100;
let score = 0;
let alive = true;

let aim = { x: 450, y: 300 };

canvas.addEventListener("mousemove", function(e) {
    const rect = canvas.getBoundingClientRect();

    aim.x = (e.clientX - rect.left) * canvas.width / rect.width;
    aim.y = (e.clientY - rect.top) * canvas.height / rect.height;
});

canvas.addEventListener("click", function() {
    if (!alive) return;

    let dx = aim.x - enemy.x;
    let dy = aim.y - enemy.y;
    let distance = Math.sqrt(dx * dx + dy * dy);

    if (distance < enemy.radius) {
        enemyHP -= 25;

        if (enemyHP <= 0) {
            alive = false;
            score++;
        }
    }
});

function draw() {
    ctx.clearRect(0, 0, canvas.width, canvas.height);

    // Фон
    ctx.fillStyle = "#353535";
    ctx.fillRect(0, 0, 900, 600);

    // Пол
    ctx.fillStyle = "#555";
    ctx.fillRect(0, 450, 900, 150);

    // Игрок
    ctx.fillStyle = "blue";
    ctx.beginPath();
    ctx.arc(450, 520, 30, 0, Math.PI * 2);
    ctx.fill();

    // Игровой предмет
    ctx.fillStyle = "#bbb";
    ctx.fillRect(465, 510, 40, 8);
    ctx.fillStyle = "#222";
    ctx.fillRect(490, 508, 15, 12);

    // Противник
    if (alive) {
        ctx.fillStyle = "red";
        ctx.beginPath();
        ctx.arc(enemy.x, enemy.y, enemy.radius, 0, Math.PI * 2);
        ctx.fill();

        // Полоска HP
        ctx.fillStyle = "black";
        ctx.fillRect(enemy.x - 40, enemy.y - 55, 80, 10);

        ctx.fillStyle = "lime";
        ctx.fillRect(enemy.x - 40, enemy.y - 55, enemyHP * 0.8, 10);
    }

    // Прицел
    ctx.strokeStyle = "white";
    ctx.lineWidth = 2;

    ctx.beginPath();
    ctx.moveTo(aim.x - 10, aim.y);
    ctx.lineTo(aim.x + 10, aim.y);

    ctx.moveTo(aim.x, aim.y - 10);
    ctx.lineTo(aim.x, aim.y + 10);
    ctx.stroke();

    // Интерфейс
    ctx.fillStyle = "white";
    ctx.font = "30px Arial";
    ctx.fillText("MINI CS", 20, 40);

    ctx.font = "25px Arial";
    ctx.fillStyle = "yellow";
    ctx.fillText("Score: " + score, 20, 80);

    ctx.fillStyle = "white";
    ctx.font = "20px Arial";
    ctx.fillText("LMB - SHOOT", 20, 120);

    if (!alive) {
        ctx.fillStyle = "lime";
        ctx.font = "40px Arial";
        ctx.fillText("ENEMY DOWN!", 330, 250);

        ctx.font = "25px Arial";
        ctx.fillStyle = "white";
        ctx.fillText("Press restart", 365, 310);
    }

    requestAnimationFrame(draw);
}

function restart() {
    enemyHP = 100;
    alive = true;

    enemy.x = Math.random() * 600 + 150;
    enemy.y = Math.random() * 300 + 150;
}

draw();
</script>

</body>
</html>

Game Source: Mini CS

Creator: CyberCobra24

Libraries: none

Complexity: moderate (172 lines, 3.5 KB)

The full source code is displayed above on this page.

Remix Instructions

To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: mini-cs-cybercobra24" to link back to the original. Then publish at arcadelab.ai/publish.