添加角色类Alice,继承自Fighter,设置属性和动画,
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
package uno.mloluyu.desktop.character;
|
||||
import uno.mloluyu.characters.Fighter;
|
||||
package uno.mloluyu.characters;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
|
||||
/**
|
||||
@@ -17,27 +17,27 @@ public class Alice extends Fighter {
|
||||
|
||||
@Override
|
||||
protected void loadAnimations() {
|
||||
loadAnimationFromAtlas(Action.IDLE, "stand", 15, true);
|
||||
loadAnimationFromAtlas(Action.WALK, "walkFront", 9, true);
|
||||
loadAnimationFromAtlas(Action.JUMP, "jump", 8, false);
|
||||
loadAnimationFromAtlas(Action.FALL, "hitSpin", 5, false);
|
||||
loadAnimationFromAtlas(Action.ATTACK1, "attackAa", 6, false);
|
||||
loadAnimationFromAtlas(Action.ATTACK2, "attackAb", 6, false);
|
||||
loadAnimationFromAtlas(Action.ATTACK3, "attackAc", 6, false);
|
||||
loadAnimationFromAtlas(Action.ATTACK4, "attackAd", 6, false);
|
||||
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);
|
||||
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);
|
||||
|
||||
loadAnimationFromAtlas(Action.HIT, "hitSpin", 5, false);
|
||||
loadAnimationFromAtlas(Action.HIT, "hitSpin/hitSpin", 5, false);
|
||||
|
||||
// 为忍者特定动作设置帧间隔
|
||||
// 为特定动作设置帧间隔
|
||||
setFrameDuration(Action.WALK, 0.08f); // 行走更快
|
||||
setFrameDuration(Action.ATTACK1, 0.07f); // 攻击更快
|
||||
setFrameDuration(Action.SPECIAL2, 0.06f); // 特殊技能2非常快
|
||||
}
|
||||
|
||||
// 忍者特定的移动状态处理
|
||||
// 特定的移动状态处理
|
||||
@Override
|
||||
protected void handleMoveState() {
|
||||
// 忍者在跳跃时也能移动
|
||||
// 在跳跃时也能移动
|
||||
if (currentAction != Action.ATTACK1 && currentAction != Action.ATTACK2 &&
|
||||
currentAction != Action.ATTACK3 && currentAction != Action.SPECIAL1 &&
|
||||
currentAction != Action.SPECIAL2 && currentAction != Action.DEFEND) {
|
||||
@@ -48,10 +48,9 @@ public class Alice extends Fighter {
|
||||
}
|
||||
}
|
||||
|
||||
// 忍者可以在空中攻击
|
||||
// 可以在空中攻击
|
||||
@Override
|
||||
protected boolean canAttack() {
|
||||
return super.canAttack() || currentAction == Action.JUMP || currentAction == Action.FALL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package uno.mloluyu.characters;
|
||||
|
||||
import uno.mloluyu.util.SimpleFormatter;
|
||||
import com.badlogic.gdx.graphics.g2d.Animation;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
@@ -15,7 +16,7 @@ public abstract class Fighter implements Disposable {
|
||||
// 动作类型枚举 - 所有角色共用的基础动作
|
||||
public enum Action {
|
||||
IDLE, WALK, JUMP, FALL,
|
||||
ATTACK1, ATTACK2, ATTACK3,ATTACK4,
|
||||
ATTACK1, ATTACK2, ATTACK3, ATTACK4,
|
||||
HIT, DEFEND,
|
||||
SPECIAL1, SPECIAL2,
|
||||
DEATH
|
||||
@@ -88,6 +89,7 @@ public abstract class Fighter implements Disposable {
|
||||
|
||||
/**
|
||||
* 从精灵图表加载动画
|
||||
*
|
||||
* @param action 动作类型
|
||||
* @param regionPrefix 该动作在图表中的区域前缀
|
||||
* @param frameCount 帧数
|
||||
@@ -99,7 +101,11 @@ public abstract class Fighter implements Disposable {
|
||||
|
||||
// 从精灵图表中获取所有帧
|
||||
for (int i = 0; i < frameCount; i++) {
|
||||
String regionName = regionPrefix + i;
|
||||
// 生成带三位前导零的序号(000, 001, 002...)
|
||||
String formattedIndex = SimpleFormatter.addLeadingZeros(i, 3);
|
||||
// 拼接完整的区域名称(如"stand/stand" + "000" → "stand/stand000")
|
||||
String regionName = regionPrefix + formattedIndex;
|
||||
|
||||
TextureRegion region = atlas.findRegion(regionName);
|
||||
|
||||
if (region == null) {
|
||||
@@ -112,8 +118,7 @@ public abstract class Fighter implements Disposable {
|
||||
// 创建动画
|
||||
Animation<TextureRegion> animation = new Animation<>(
|
||||
frameDurations[action.ordinal()],
|
||||
frames
|
||||
);
|
||||
frames);
|
||||
animation.setPlayMode(loop ? Animation.PlayMode.LOOP : Animation.PlayMode.NORMAL);
|
||||
animations[action.ordinal()] = animation;
|
||||
}
|
||||
@@ -350,4 +355,3 @@ public abstract class Fighter implements Disposable {
|
||||
public void dispose() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
|
||||
import uno.mloluyu.desktop.character.Alice;
|
||||
import uno.mloluyu.characters.Alice;
|
||||
|
||||
public class GameCore implements ApplicationListener {
|
||||
private SpriteBatch batch;
|
||||
@@ -17,8 +17,9 @@ public class GameCore implements ApplicationListener {
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
atlas = new TextureAtlas(Gdx.files.internal("characters/alice.atlas"));
|
||||
alice1= new Alice();
|
||||
batch = new SpriteBatch();
|
||||
atlas = new TextureAtlas(Gdx.files.internal("src\\main\\resources\\character\\alice\\alice.atlas"));
|
||||
alice1= new Alice(atlas);
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +32,7 @@ public class GameCore implements ApplicationListener {
|
||||
alice1.update(Gdx.graphics.getDeltaTime());
|
||||
batch.begin();
|
||||
alice1.render(batch);
|
||||
batch.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user