void Enemy::update( const cc::Vec2f& screenSize ) { if( nullptr == _texture || nullptr == _target) { return; } followTarget(0.9f); _position += _velocity; // bounds limiting const cc::Vec2f size(static_cast<float>(_texture->getWidth()) * 0.5f, static_cast<float>(_texture->getHeight()) * 0.5f); _position.x = cc::math::clamp<float>(_position.x, size.x * 0.5f, screenSize.x - size.x * 0.5f); _position.y = cc::math::clamp<float>(_position.y, size.y * 0.5f, screenSize.y - size.y * 0.5f); _velocity *= 0.8f; }
void SoldierLyzc::doAttack() { //TODO:如果攻击目标是可移动的(比如敌方士兵,英雄),则每次攻击前都要判断是否在攻击范围内,如果不在范围内则重新寻路,或者更换目标 if (checkDistance()) { m_attackName = ""; switch (m_direction) { case e_battle_dir_east : m_attackName = "01_attack03"; break; case e_battle_dir_es : m_attackName = "01_attack02"; break; case e_battle_dir_south : m_attackName = "01_attack01"; break; case e_battle_dir_ws : m_attackName = "01_attack04"; break; case e_battle_dir_west : m_attackName = "01_attack01"; break; case e_battle_dir_wn : m_attackName = "01_attack02"; break; case e_battle_dir_north : m_attackName = "01_attack03"; break; case e_battle_dir_en : m_attackName = "01_attack05"; break; default: break; } getBody()->getAnimation()->play(m_attackName, -1, 0); auto sc = SoldierConfig::getSoldierConfig(getType()); Director::getInstance()->getScheduler()->schedule(schedule_selector(Soldier::updateAttack), this, sc->attack_speed, false); getBody()->getAnimation()->setMovementEventCallFunc(CC_CALLBACK_0(Soldier::animationEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); } else { setStatus(e_battle_status_moveing); followTarget(); } }