Завершить state machine персонажа

This commit is contained in:
2026-08-19 03:20:24 +03:00
parent 0943caa3cc
commit 62ee6877f9
12 changed files with 463 additions and 8 deletions
@@ -233,6 +233,8 @@ public final class GameView extends View implements Runnable {
private final ProceduralAudioEngine audioEngine;
private final SparseArray<PointF> pointers = new SparseArray<>();
private final Player player = new Player();
private final CharacterStateMachine characterStateMachine =
new CharacterStateMachine(PHYSICS);
private final ArrayList<Corpse> corpses = new ArrayList<>();
private final ArrayList<PlatformState> platformStates = new ArrayList<>();
private final Map<String, Boolean> toggleSignals = new HashMap<>();
@@ -427,6 +429,8 @@ public final class GameView extends View implements Runnable {
player.jumpBuffer = 0f;
player.supportIndex = -1;
player.facing = 1;
characterStateMachine.reset(player.alive, player.onGround,
player.vx, player.vy, player.facing);
if (deaths > 0) audioEngine.play(AudioCue.RESPAWN_VOICE);
}
@@ -496,6 +500,10 @@ public final class GameView extends View implements Runnable {
emitHaptic(HapticFeedbackConstants.KEYBOARD_TAP);
}
if (contact && !previous) audioEngine.play(AudioCue.SWITCH);
if (contact && !previous && player.alive
&& intersects(player.x, player.y, PLAYER_WIDTH, PLAYER_HEIGHT, item.box)) {
characterStateMachine.beginInteraction();
}
previousSwitchContact.put(contactKey, contact);
}
}
@@ -594,6 +602,8 @@ public final class GameView extends View implements Runnable {
movePlayerVertical(player.vy * dt);
player.x = GameMath.clamp(player.x, 0f, level.worldWidth - PLAYER_WIDTH);
if (player.y > VIEW_HEIGHT + 180f) kill(DeathType.PIT, null);
characterStateMachine.observe(dt, player.alive, player.onGround,
player.vx, player.vy, player.facing);
}
private void movePlayerHorizontal(float amount) {
@@ -757,6 +767,8 @@ public final class GameView extends View implements Runnable {
player.alive = false;
player.vx = player.vy = 0f;
player.supportIndex = -1;
characterStateMachine.observe(0f, false, player.onGround,
player.vx, player.vy, player.facing);
deaths++;
respawnTimer = RESPAWN_SECONDS;
emitHaptic(Build.VERSION.SDK_INT >= 27
@@ -893,8 +905,7 @@ public final class GameView extends View implements Runnable {
for (Corpse corpse : corpses) drawCorpse(canvas, corpse);
VolunteerRig.Skin skin = VolunteerRig.Skin.forLevel(level.number);
if (player.alive) {
VolunteerRig.Motion motion = VolunteerRig.aliveMotion(
player.onGround, player.vx, player.vy);
VolunteerRig.Motion motion = VolunteerRig.motionFor(characterStateMachine.state());
volunteerRenderer.draw(canvas, paint, stroke, path,
player.x, player.y, PLAYER_WIDTH, PLAYER_HEIGHT,
skin, motion, volunteerPhase(motion), player.facing, 1f,
@@ -2339,6 +2350,8 @@ public final class GameView extends View implements Runnable {
player.jumpBuffer = savedPlayer.jumpBufferSeconds();
player.supportIndex = savedPlayer.supportIndex();
player.facing = savedPlayer.facing();
characterStateMachine.reset(player.alive, player.onGround,
player.vx, player.vy, player.facing);
corpses.clear();
for (GameSessionSnapshot.BodyData savedBody : snapshot.bodies()) {
@@ -2427,4 +2440,16 @@ public final class GameView extends View implements Runnable {
player.vy
);
}
public CharacterStateMachine.State characterStateForAutomation() {
return characterStateMachine.state();
}
public void triggerInteractionForAutomation() {
characterStateMachine.beginInteraction();
}
public void triggerStunForAutomation() {
characterStateMachine.stun();
}
}