/
xem
/
mini-m
Обзор
Документация
Войти
/
xem
/
mini-m
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
js/unit.js
28 строк
1 KB
romican
first_commit
15 май 2026, 20:10
15 май 2026, 20:10
65014ec
Код
Авторство
О чём код?
// js/unit.js export class Unit { constructor({ x, y, hp = 100, damage = 10, attackRadius = 40, attackSpeed = 0.8, speed = 100, color = '#888', radius = 12, shape = 'circle' }) { this.x = x; this.y = y; this.maxHp = hp; this.hp = hp; this.damage = damage; this.attackRadius = attackRadius; this.attackSpeed = attackSpeed; this.speed = speed; this.color = color; this.radius = radius; this.shape = shape; this.lastAttackTime = 0; this.isAlive = true; } canAttack(currentTime) { return currentTime - this.lastAttackTime >= this.attackSpeed; } performAttack(target, currentTime) { if (!this.canAttack(currentTime) || !target.isAlive) return null; this.lastAttackTime = currentTime; target.takeDamage(this.damage); return this.damage; } takeDamage(amount) { this.hp -= amount; if (this.hp <= 0) { this.hp = 0; this.isAlive = false; } } get alive() { return this.isAlive; } }