From 0c0e27ff32efcc9a2f53a0d2e401c5cf5dd7b123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=BA=E6=98=8E=20=E6=B2=88?= <2431685932@qq.com> Date: Mon, 1 Jul 2024 19:59:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BF=AE=E6=AD=A3=E4=B8=8A=E4=B8=80?= =?UTF-8?q?=E7=89=88bug=EF=BC=8Ctimer=E7=B1=BB=E5=9B=9E=E8=B0=83=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E8=B6=85=E6=97=B6=E8=AE=BE=E7=BD=AE=E9=94=99=E8=AF=AF?= =?UTF-8?q?=EF=BC=81=E6=95=8C=E4=BA=BA=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TdGame/TdGame/animation.h | 6 +++--- TdGame/TdGame/enemy.h | 12 ++++++------ TdGame/TdGame/enemy_manager.h | 6 +++--- TdGame/TdGame/skeleton_enemy.h | 8 ++++---- TdGame/TdGame/timer.h | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/TdGame/TdGame/animation.h b/TdGame/TdGame/animation.h index beecfd0..ad0783f 100644 --- a/TdGame/TdGame/animation.h +++ b/TdGame/TdGame/animation.h @@ -61,7 +61,7 @@ public: rect_src.y = (idx / num_x) * height_frame; rect_src.w = width_frame; rect_src.h = height_frame; - }; + } } void set_loop(bool is_loop) @@ -89,8 +89,8 @@ public: { static SDL_Rect rect_dst; - rect_dst.x = pos_dst.x; rect_dst.y = pos_dst.y; - rect_dst.w = width_frame; rect_dst.h = height_frame; + rect_dst.x = pos_dst.x, rect_dst.y = pos_dst.y; + rect_dst.w = width_frame, rect_dst.h = height_frame; //渲染器,纹理,裁剪矩形,目标矩形,角度,旋转中心点(默认1/2),翻转。 纹理绘制 SDL_RenderCopyEx(renderer, texture, &rect_src_list[idx_frame], &rect_dst, angle, nullptr, SDL_RendererFlip::SDL_FLIP_NONE); diff --git a/TdGame/TdGame/enemy.h b/TdGame/TdGame/enemy.h index 2de09d6..82d83df 100644 --- a/TdGame/TdGame/enemy.h +++ b/TdGame/TdGame/enemy.h @@ -23,7 +23,7 @@ public: //闪白计时器 timer_sketch.set_one_shot(true); - timer_sketch.set_wait_time(0.001); + timer_sketch.set_wait_time(0.075); timer_sketch.set_on_timeout([&]() {is_show_sketch = false; }); //速度恢复计时器 @@ -57,7 +57,7 @@ public: velocity.y = direction.y * speed * SIZE_TILE; //是否展示水平动画 - bool is_show_x_anim = (velocity.x) >= abs(velocity.y); + bool is_show_x_anim = abs(velocity.x) >= abs(velocity.y); //1.是否展示剪影 2.展示动画左右 if (is_show_sketch) @@ -85,7 +85,7 @@ public: static SDL_Rect rect; static SDL_Point point; static const int offset_y = 2; - static Vector2 size_hp_bar = { 40,8 }; + static const Vector2 size_hp_bar = { 40,8 }; //血条外边框颜色 static const SDL_Color color_border = { 116,185,124,255 }; //血条内容物颜色 @@ -130,7 +130,7 @@ public: void decrease_hp(double val) { hp -= val; - if (hp < 0) + if (hp <= 0) { hp = 0; is_valid = false; @@ -287,8 +287,8 @@ private: const SDL_Point& point = idx_list[idx_target]; static const SDL_Rect& rect_tile_map = ConfigManager::instance()->rect_tile_map; - position.x = rect_tile_map.x + point.x * SIZE_TILE + SIZE_TILE / 2; - position.y = rect_tile_map.y + point.y * SIZE_TILE + SIZE_TILE / 2; + position_target.x = rect_tile_map.x + point.x * SIZE_TILE + SIZE_TILE / 2; + position_target.y = rect_tile_map.y + point.y * SIZE_TILE + SIZE_TILE / 2; } } }; diff --git a/TdGame/TdGame/enemy_manager.h b/TdGame/TdGame/enemy_manager.h index 93b45d6..1755f12 100644 --- a/TdGame/TdGame/enemy_manager.h +++ b/TdGame/TdGame/enemy_manager.h @@ -92,15 +92,15 @@ public: ( [&](Enemy* enemy_src) { - double revocer_radius = enemy_src->get_recover_radius(); - if (revocer_radius < 0) return; + double recover_radius = enemy_src->get_recover_radius(); + if (recover_radius < 0) return; const Vector2 pos_src = enemy_src->get_position(); for (Enemy* enemy_dst : enemy_list) { const Vector2& pos_dst = enemy_dst->get_position(); double distance = (pos_dst - pos_src).length(); - if (distance <= revocer_radius) + if (distance <= recover_radius) enemy_dst->increase_hp(enemy_src->get_recover_intensity()); } } diff --git a/TdGame/TdGame/skeleton_enemy.h b/TdGame/TdGame/skeleton_enemy.h index dc7f8e9..a07e7b3 100644 --- a/TdGame/TdGame/skeleton_enemy.h +++ b/TdGame/TdGame/skeleton_enemy.h @@ -26,13 +26,13 @@ public: static const std::vector idx_list_right = { 10, 11, 12, 13, 14 }; anim_up.set_loop(true); anim_up.set_interval(0.15); - anim_up.set_frame_data(tex_skeleton, 6, 4, idx_list_up); + anim_up.set_frame_data(tex_skeleton, 5, 4, idx_list_up); anim_down.set_loop(true); anim_down.set_interval(0.15); - anim_down.set_frame_data(tex_skeleton, 6, 4, idx_list_down); + anim_down.set_frame_data(tex_skeleton, 5, 4, idx_list_down); anim_left.set_loop(true); anim_left.set_interval(0.15); - anim_left.set_frame_data(tex_skeleton, 6, 4, idx_list_left); + anim_left.set_frame_data(tex_skeleton, 5, 4, idx_list_left); anim_right.set_loop(true); anim_right.set_interval(0.15); - anim_right.set_frame_data(tex_skeleton, 6, 4, idx_list_right); + anim_right.set_frame_data(tex_skeleton, 5, 4, idx_list_right); anim_up_sketch.set_loop(true); anim_up_sketch.set_interval(0.15); anim_up_sketch.set_frame_data(tex_skeleton_sketch, 5, 4, idx_list_up); diff --git a/TdGame/TdGame/timer.h b/TdGame/TdGame/timer.h index 5bc1b26..5744fb5 100644 --- a/TdGame/TdGame/timer.h +++ b/TdGame/TdGame/timer.h @@ -53,7 +53,7 @@ public: shotted = true; //如果能触发,且超时函数已经设置 if (can_shot && on_timeout) - on_timeout; + on_timeout(); pass_time -= wait_time; }