This commit is contained in:
Vladislav Khorev committed 2026-04-24 18:40:51 +03:00
1 parent b4b41e8620
commit 2bb7da2e37
8 files changed
+227397 -37

No files matched your search

+102 -36
View File
@@ -6,9 +6,10 @@
namespace ZL {
const float ATTACK_COOLDOWN_TIME = 3.0f;
const float ATTACK_COOLDOWN_TIME = 2.3f;
extern float x;
extern float y;
const float ATTACK_RANGE = 1.25f;
void Character::loadAnimation(AnimationState state, const std::string& filename, const std::string& zipFile) {
auto& data = animations[state];
@@ -131,7 +132,7 @@ void Character::update(int64_t deltaMs) {
battle_state = 0;
}
else if (distToGhost < 10.0f && distToGhost >= 1.f) {
else if (distToGhost < 10.0f && distToGhost >= ATTACK_RANGE) {
setTarget(attackTarget->position);
battle_state = 0;
}
@@ -202,40 +203,55 @@ void Character::update(int64_t deltaMs) {
targetFacingAngle = facingAngle;
}
}
if (battle_state == 1)
if (hp <= 0)
{
targetFacingAngle = atan2(lookTarget.x() - position.x(), -(lookTarget.z() - position.z()));
if (currentState == AnimationState::STAND || currentState == AnimationState::WALK) {
currentState = AnimationState::STAND_TO_ACTION;
resetAnim = true;
}
if (canAttack && attack == 0 && attack_cooldown < 0.f && currentState == AnimationState::ACTION_IDLE)
if (currentState != AnimationState::ACTION_TO_DEATH && currentState != AnimationState::DEATH_IDLE)
{
attack = 1;
attack_cooldown = ATTACK_COOLDOWN_TIME;
}
if (canAttack && attack_cooldown >= 0.f)
{
attack_cooldown = attack_cooldown - deltaMs / 1000.f;
}
if (attack == 1 && currentState == AnimationState::ACTION_IDLE)
{
currentState = AnimationState::ACTION_ATTACK;
currentState = AnimationState::ACTION_TO_DEATH;
resetAnim = true;
}
}
else
{
if (currentState == AnimationState::STAND_TO_ACTION
|| currentState == AnimationState::ACTION_IDLE
|| currentState == AnimationState::ACTION_ATTACK
) {
currentState = AnimationState::ACTION_TO_STAND;
resetAnim = true;
if (battle_state == 1)
{
targetFacingAngle = atan2(lookTarget.x() - position.x(), -(lookTarget.z() - position.z()));
if (currentState == AnimationState::STAND || currentState == AnimationState::WALK) {
currentState = AnimationState::STAND_TO_ACTION;
resetAnim = true;
}
if (canAttack && attack == 0 && attack_cooldown < 0.f && currentState == AnimationState::ACTION_IDLE)
{
attack = 1;
attack_cooldown = ATTACK_COOLDOWN_TIME;
}
if (canAttack && attack_cooldown >= 0.f)
{
attack_cooldown = attack_cooldown - deltaMs / 1000.f;
}
if (attack == 1 && currentState == AnimationState::ACTION_IDLE)
{
if (attackTarget != nullptr && attackTarget->hp > 0)
{
currentState = AnimationState::ACTION_ATTACK;
resetAnim = true;
}
}
}
else
{
if (currentState == AnimationState::STAND_TO_ACTION
|| currentState == AnimationState::ACTION_IDLE
|| currentState == AnimationState::ACTION_ATTACK
) {
currentState = AnimationState::ACTION_TO_STAND;
resetAnim = true;
}
}
}
@@ -262,10 +278,15 @@ void Character::update(int64_t deltaMs) {
resetAnim = false;
anim.currentFrame = 0;
}
//19
int prevFrame = anim.currentFrame;
anim.currentFrame += static_cast<float>(deltaMs) / 24.f;
/*
if (npcId == "ghost_01x")
{
std::cout << "Current animation frame: " << anim.currentFrame << " / " << anim.totalFrames << " -- " << anim.lastFrame << std::endl;
}*/
//std::cout << "Current animation frame: " << anim.currentFrame << " / " << anim.totalFrames << " -- " << anim.lastFrame << std::endl;
if (static_cast<int>(anim.currentFrame) >= 20 && currentState == AnimationState::STAND_TO_ACTION)
{
showWeapon = true;
@@ -276,11 +297,32 @@ void Character::update(int64_t deltaMs) {
}
else if (currentState == AnimationState::ACTION_ATTACK_2 || currentState == AnimationState::ACTION_ATTACK || currentState == AnimationState::ACTION_IDLE)
{
showWeapon = true;
showWeapon = true;
}
else
{
showWeapon = false;
showWeapon = false;
}
if (isPlayer)
{
if (prevFrame == 18 && static_cast<int>(anim.currentFrame) != 18 && (currentState == AnimationState::ACTION_ATTACK || currentState == AnimationState::ACTION_ATTACK_2))
{
if (attackTarget != nullptr)
{
attackTarget->applyDamage(10.f);
}
}
}
else
{
if (prevFrame == 49 && static_cast<int>(anim.currentFrame) != 49 && (currentState == AnimationState::ACTION_ATTACK || currentState == AnimationState::ACTION_ATTACK_2))
{
if (attackTarget != nullptr)
{
attackTarget->applyDamage(10.f);
}
}
}
int frms = anim.model.animations[0].keyFrames[anim.model.animations[0].keyFrames.size() - 1].frame;
@@ -290,20 +332,26 @@ void Character::update(int64_t deltaMs) {
if (currentState == AnimationState::STAND_TO_ACTION)
{
currentState = AnimationState::ACTION_IDLE;
resetAnim = true;
//resetAnim = true;
}
if (currentState == AnimationState::ACTION_TO_STAND)
{
currentState = AnimationState::STAND;
resetAnim = true;
//resetAnim = true;
}
if (currentState == AnimationState::ACTION_ATTACK)
{
currentState = AnimationState::ACTION_IDLE;
resetAnim = true;
//resetAnim = true;
attack = 0;
}
if (currentState == AnimationState::ACTION_TO_DEATH)
{
currentState = AnimationState::DEATH_IDLE;
//resetAnim = true;
}
}
@@ -317,6 +365,10 @@ void Character::update(int64_t deltaMs) {
}
void Character::draw(Renderer& renderer) {
if (!isPlayer && hp <= 0)
{
return;
}
if (useGpuSkinning) {
drawGpuSkinning(renderer);
return;
@@ -482,6 +534,10 @@ void Character::drawAttachedWeapon(Renderer& renderer)
// ==================== Shadow depth pass ====================
void Character::drawShadowDepth(Renderer& renderer) {
if (!isPlayer && hp <= 0)
{
return;
}
if (useGpuSkinning) {
drawShadowDepthGpuSkinning(renderer);
} else {
@@ -568,6 +624,10 @@ void Character::drawShadowDepthGpuSkinning(Renderer& renderer) {
// ==================== Main pass with shadows ====================
void Character::drawWithShadow(Renderer& renderer, const Eigen::Matrix4f& lightFromCamera, GLuint shadowMapTex, const Eigen::Vector3f& lightDirCamera) {
if (!isPlayer && hp <= 0)
{
return;
}
if (useGpuSkinning) {
drawGpuSkinningWithShadow(renderer, lightFromCamera, shadowMapTex, lightDirCamera);
} else {
@@ -695,4 +755,10 @@ void Character::drawGpuSkinningWithShadow(Renderer& renderer, const Eigen::Matri
CheckGlError(__FILE__, __LINE__);
}
void Character::applyDamage(float damageAmount)
{
hp = hp - damageAmount;
if (hp < 0) hp = 0;
}
} // namespace ZL