一个里程碑(可以联机了)
This commit is contained in:
@@ -9,7 +9,7 @@ import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
public class Alice extends Fighter {
|
||||
|
||||
public Alice() {
|
||||
super(new TextureAtlas(Gdx.files.internal("src/main/resources/character/alice/精灵1.2.atlas")));
|
||||
super("Alice", new TextureAtlas(Gdx.files.internal("src/main/resources/character/alice/精灵1.2.atlas")));
|
||||
|
||||
// 设置角色属性
|
||||
speed = 350f; // 更快的移动速度
|
||||
@@ -20,22 +20,27 @@ public class Alice extends Fighter {
|
||||
|
||||
@Override
|
||||
protected void loadAnimations() {
|
||||
// 加载基础动作动画
|
||||
loadAnimationFromAtlas(Action.IDLE, "stand/stand", 15, true);
|
||||
loadAnimationFromAtlas(Action.WALK, "walkFront/walkFront", 9, true);
|
||||
loadAnimationFromAtlas(Action.JUMP, "jump/jump", 8, false);
|
||||
loadAnimationFromAtlas(Action.FALL, "hitSpin/hitSpin", 5, false);
|
||||
// 基础动作
|
||||
loadLoopingAnimation(Action.IDLE, "stand/stand", 15);
|
||||
loadLoopingAnimation(Action.WALK, "walkFront/walkFront", 9);
|
||||
loadOneShotAnimation(Action.JUMP, "jump/jump", 8);
|
||||
loadOneShotAnimation(Action.FALL, "hitSpin/hitSpin", 5);
|
||||
|
||||
// 加载攻击动作动画
|
||||
loadAnimationFromAtlas(Action.ATTACK1, "attackAa/attackAa", 6, false);
|
||||
loadAnimationFromAtlas(Action.ATTACK2, "attackAb/attackAb", 6, false);
|
||||
loadAnimationFromAtlas(Action.ATTACK3, "attackAc/attackAc", 6, false);
|
||||
loadAnimationFromAtlas(Action.ATTACK4, "attackAd/attackAd", 6, false);
|
||||
// 攻击动作
|
||||
loadOneShotAnimation(Action.ATTACK1, "attackAa/attackAa", 6);
|
||||
loadOneShotAnimation(Action.ATTACK2, "attackAb/attackAb", 6);
|
||||
loadOneShotAnimation(Action.ATTACK3, "attackAc/attackAc", 6);
|
||||
loadOneShotAnimation(Action.ATTACK4, "attackAd/attackAd", 6);
|
||||
|
||||
// 加载受击动画
|
||||
loadAnimationFromAtlas(Action.HIT, "hitSpin/hitSpin", 5, false);
|
||||
// // 特殊动作(可扩展)
|
||||
// loadOneShotAnimation(Action.SPECIAL1, "special/special1", 6);
|
||||
// loadOneShotAnimation(Action.SPECIAL2, "special/special2", 6);
|
||||
|
||||
// 设置帧间隔(动作速度)
|
||||
// 受击与死亡
|
||||
loadOneShotAnimation(Action.HIT, "hitSpin/hitSpin", 5);
|
||||
// loadOneShotAnimation(Action.DEATH, "death/death", 8);
|
||||
|
||||
// 帧速率调整
|
||||
setFrameDuration(Action.IDLE, 0.04f);
|
||||
setFrameDuration(Action.WALK, 0.08f);
|
||||
setFrameDuration(Action.ATTACK1, 0.07f);
|
||||
@@ -50,6 +55,7 @@ public class Alice extends Fighter {
|
||||
if (currentAction != Action.ATTACK1 &&
|
||||
currentAction != Action.ATTACK2 &&
|
||||
currentAction != Action.ATTACK3 &&
|
||||
currentAction != Action.ATTACK4 &&
|
||||
currentAction != Action.SPECIAL1 &&
|
||||
currentAction != Action.SPECIAL2 &&
|
||||
currentAction != Action.DEFEND &&
|
||||
|
||||
@@ -1,21 +1,14 @@
|
||||
package uno.mloluyu.characters;
|
||||
|
||||
import uno.mloluyu.util.SimpleFormatter;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.g2d.Animation;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.graphics.g2d.*;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import uno.mloluyu.util.SimpleFormatter;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
/**
|
||||
* 格斗角色父类,封装所有角色共有的动画和状态管理逻辑
|
||||
*/
|
||||
public abstract class Fighter implements Disposable {
|
||||
|
||||
public enum Action {
|
||||
@@ -51,10 +44,10 @@ public abstract class Fighter implements Disposable {
|
||||
protected float scaleX = 1.0f;
|
||||
protected float scaleY = 1.0f;
|
||||
|
||||
public Fighter() {
|
||||
}
|
||||
public Fighter() {}
|
||||
|
||||
public Fighter(TextureAtlas atlas) {
|
||||
public Fighter(String name, TextureAtlas atlas) {
|
||||
this.name = name;
|
||||
this.atlas = atlas;
|
||||
for (Action action : Action.values()) {
|
||||
frameDurations.put(action, DEFAULT_FRAME_DURATION);
|
||||
@@ -85,6 +78,14 @@ public abstract class Fighter implements Disposable {
|
||||
animations.put(action, animation);
|
||||
}
|
||||
|
||||
protected void loadLoopingAnimation(Action action, String prefix, int count) {
|
||||
loadAnimationFromAtlas(action, prefix, count, true);
|
||||
}
|
||||
|
||||
protected void loadOneShotAnimation(Action action, String prefix, int count) {
|
||||
loadAnimationFromAtlas(action, prefix, count, false);
|
||||
}
|
||||
|
||||
protected void setFrameDuration(Action action, float duration) {
|
||||
frameDurations.put(action, duration);
|
||||
Animation<TextureRegion> anim = animations.get(action);
|
||||
@@ -103,23 +104,12 @@ public abstract class Fighter implements Disposable {
|
||||
}
|
||||
|
||||
protected void handleAnimationTransitions() {
|
||||
if (!isAnimationFinished)
|
||||
return;
|
||||
if (!isAnimationFinished) return;
|
||||
|
||||
switch (currentAction) {
|
||||
case ATTACK1:
|
||||
case ATTACK2:
|
||||
case ATTACK3:
|
||||
case SPECIAL1:
|
||||
case SPECIAL2:
|
||||
case HIT:
|
||||
changeAction(Action.IDLE);
|
||||
break;
|
||||
case JUMP:
|
||||
changeAction(Action.FALL);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case ATTACK1, ATTACK2, ATTACK3, SPECIAL1, SPECIAL2, HIT -> changeAction(Action.IDLE);
|
||||
case JUMP -> changeAction(Action.FALL);
|
||||
default -> {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,8 +140,7 @@ public abstract class Fighter implements Disposable {
|
||||
}
|
||||
|
||||
public boolean changeAction(Action newAction) {
|
||||
if (isActionUninterruptible(currentAction))
|
||||
return false;
|
||||
if (isActionUninterruptible(currentAction)) return false;
|
||||
if (currentAction != newAction) {
|
||||
currentAction = newAction;
|
||||
stateTime = 0f;
|
||||
@@ -182,18 +171,17 @@ public abstract class Fighter implements Disposable {
|
||||
|
||||
protected void handleMoveState() {
|
||||
if (!isActionUninterruptible(currentAction) &&
|
||||
currentAction != Action.JUMP &&
|
||||
currentAction != Action.FALL &&
|
||||
currentAction != Action.DEFEND &&
|
||||
!currentAction.name().startsWith("ATTACK") &&
|
||||
!currentAction.name().startsWith("SPECIAL")) {
|
||||
currentAction != Action.JUMP &&
|
||||
currentAction != Action.FALL &&
|
||||
currentAction != Action.DEFEND &&
|
||||
!currentAction.name().startsWith("ATTACK") &&
|
||||
!currentAction.name().startsWith("SPECIAL")) {
|
||||
changeAction(Action.WALK);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean attack(int attackType) {
|
||||
if (!canAttack())
|
||||
return false;
|
||||
if (!canAttack()) return false;
|
||||
|
||||
Action attackAction = switch (attackType) {
|
||||
case 1 -> Action.ATTACK1;
|
||||
@@ -212,13 +200,24 @@ public abstract class Fighter implements Disposable {
|
||||
}
|
||||
|
||||
public void takeHit(int damage) {
|
||||
if (currentAction == Action.DEATH)
|
||||
return;
|
||||
if (currentAction == Action.DEATH) return;
|
||||
|
||||
health = Math.max(0, health - damage);
|
||||
changeAction(health == 0 ? Action.DEATH : Action.HIT);
|
||||
}
|
||||
|
||||
public void setPosition(float x, float y) {
|
||||
hitbox.setPosition(x, y);
|
||||
}
|
||||
|
||||
public void setFacingRight(boolean facingRight) {
|
||||
this.isFacingRight = facingRight;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Rectangle getHitbox() {
|
||||
return hitbox;
|
||||
}
|
||||
@@ -235,12 +234,6 @@ public abstract class Fighter implements Disposable {
|
||||
return health;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (atlas != null)
|
||||
atlas.dispose();
|
||||
}
|
||||
|
||||
public Action getCurrentAction() {
|
||||
return currentAction;
|
||||
}
|
||||
@@ -260,4 +253,9 @@ public abstract class Fighter implements Disposable {
|
||||
public float getCenterY() {
|
||||
return hitbox.y + hitbox.height / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (atlas != null) atlas.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user