修复一部分bug
This commit is contained in:
@@ -116,13 +116,13 @@ public class SimpleFighter {
|
||||
if (!isAttacking) {
|
||||
if (keycode == Input.Keys.Z || keycode == Input.Keys.J) {
|
||||
attack("light");
|
||||
NetworkManager.getInstance().sendAttack("light");
|
||||
NetworkManager.getInstance().sendAttack("light", getFacingDir());
|
||||
} else if (keycode == Input.Keys.X || keycode == Input.Keys.K) {
|
||||
attack("heavy");
|
||||
NetworkManager.getInstance().sendAttack("heavy");
|
||||
NetworkManager.getInstance().sendAttack("heavy", getFacingDir());
|
||||
} else if (keycode == Input.Keys.SHIFT_LEFT || keycode == Input.Keys.SHIFT_RIGHT) {
|
||||
attack("special");
|
||||
NetworkManager.getInstance().sendAttack("special");
|
||||
NetworkManager.getInstance().sendAttack("special", getFacingDir());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -172,6 +172,14 @@ public class SimpleFighter {
|
||||
return isFacingRight;
|
||||
}
|
||||
|
||||
public void setFacingRight(boolean facingRight) {
|
||||
this.isFacingRight = facingRight;
|
||||
}
|
||||
|
||||
public String getFacingDir() {
|
||||
return isFacingRight ? "R" : "L";
|
||||
}
|
||||
|
||||
private void updateAttackbox(String attackType) {
|
||||
float offsetX, offsetY = 20, width = 80, height = 80;
|
||||
switch (attackType) {
|
||||
@@ -209,14 +217,21 @@ public class SimpleFighter {
|
||||
}
|
||||
|
||||
public void takeHit(int damage) {
|
||||
takeHit(damage, 0);
|
||||
}
|
||||
|
||||
public void takeHit(int damage, int dirSign) {
|
||||
if (invulnerableTimer > 0 || health <= 0)
|
||||
return; // 无敌或已死亡
|
||||
health = Math.max(0, health - damage);
|
||||
changeAction(health > 0 ? Action.HIT : Action.DEAD);
|
||||
// 设置无敌 & 击退
|
||||
invulnerableTimer = INVULNERABLE_DURATION;
|
||||
// 击退方向与幅度
|
||||
knockbackX = isFacingRight ? -600f : 600f;
|
||||
// dirSign: -1 表示从右向左击中(目标向左被推), 1 表示从左向右击中(目标向右被推)
|
||||
if (dirSign == 0) { // 没有提供方向则沿用基于自身面向的旧逻辑
|
||||
knockbackX = isFacingRight ? -600f : 600f;
|
||||
} else {
|
||||
knockbackX = dirSign * 600f;
|
||||
}
|
||||
knockbackTimer = KNOCKBACK_DURATION;
|
||||
}
|
||||
|
||||
@@ -292,4 +307,16 @@ public class SimpleFighter {
|
||||
public float getAttackTimer() {
|
||||
return attackTimer;
|
||||
}
|
||||
|
||||
// 重生时重置状态
|
||||
public void resetForRespawn() {
|
||||
health = 100;
|
||||
isAttacking = false;
|
||||
attackTimer = 0f;
|
||||
attackJustStarted = false;
|
||||
changeAction(Action.IDLE);
|
||||
invulnerableTimer = 0f;
|
||||
knockbackTimer = 0f;
|
||||
knockbackX = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user