/
superwizard
/
openhmm
Обзор
Документация
Войти
/
superwizard
/
openhmm
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
hero.cpp
40 строк
782 B
Denis Burlaka
Initial project setup
20 июл 2026, 22:19
Верифицирован
20 июл 2026, 22:19
a818c95
Код
Авторство
О чём код?
#include "hero.hpp" #include <algorithm> #include <cmath> Hero::Hero(std::string_view name, int hp, int attack, double speed) : name(name), hp(hp), attack(attack), speed(speed) {} void Hero::takeDamage(int damage) { hp = std::max(0, hp - damage); } bool Hero::isAlive() const { return hp > 0; } bool Hero::moveToward(int targetX, int targetY) { this->targetX = targetX; this->targetY = targetY; state = State::Moving; double dx = this->targetX - x; double dy = this->targetY - y; double dist = std::sqrt(dx * dx + dy * dy); if (dist <= speed) { x = this->targetX; y = this->targetY; state = State::Wait; return true; } x += dx / dist * speed; y += dy / dist * speed; return false; }