mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-19 12:49:25 +08:00
fix: 后退 & 移动速度
This commit is contained in:
parent
c6ec4971ee
commit
0b734762b0
@ -222,6 +222,7 @@ export class HeroRenderer
|
|||||||
* 进行下一步的移动准备,设置移动信息
|
* 进行下一步的移动准备,设置移动信息
|
||||||
*/
|
*/
|
||||||
private step() {
|
private step() {
|
||||||
|
this.stepDir = this.moveDir;
|
||||||
this.lastStepTime = Date.now();
|
this.lastStepTime = Date.now();
|
||||||
this.stepDelta = core.utils.scan2[this.stepDir];
|
this.stepDelta = core.utils.scan2[this.stepDir];
|
||||||
this.turn(this.stepDir);
|
this.turn(this.stepDir);
|
||||||
|
@ -61,6 +61,8 @@ export abstract class ObjectMoverBase extends EventEmitter<EObjectMovingEvent> {
|
|||||||
moveDir: Dir2 = 'down';
|
moveDir: Dir2 = 'down';
|
||||||
/** 当前是否正在移动 */
|
/** 当前是否正在移动 */
|
||||||
moving: boolean = false;
|
moving: boolean = false;
|
||||||
|
/** 面朝方向 */
|
||||||
|
faceDir: Dir2 = 'down';
|
||||||
|
|
||||||
/** 当前的控制对象 */
|
/** 当前的控制对象 */
|
||||||
controller?: IMoveController;
|
controller?: IMoveController;
|
||||||
@ -101,12 +103,43 @@ export abstract class ObjectMoverBase extends EventEmitter<EObjectMovingEvent> {
|
|||||||
controller: IMoveController
|
controller: IMoveController
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当移动速度被设置时执行的函数
|
||||||
|
* @param speed 设置为的移动速度
|
||||||
|
* @param controller 本次移动的控制对象
|
||||||
|
*/
|
||||||
|
protected abstract onSetMoveSpeed(
|
||||||
|
speed: number,
|
||||||
|
controller: IMoveController
|
||||||
|
): void;
|
||||||
|
|
||||||
private getMoveDir(move: Move2): Dir2 {
|
private getMoveDir(move: Move2): Dir2 {
|
||||||
if (move === 'forward') return this.moveDir;
|
if (move === 'forward') return this.moveDir;
|
||||||
if (move === 'backward') return backDir(this.moveDir);
|
if (move === 'backward') return backDir(this.faceDir);
|
||||||
return move;
|
return move;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getFaceDir(move: Move2): Dir2 {
|
||||||
|
if (move === 'forward' || move === 'backward') return this.faceDir;
|
||||||
|
return move;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置当前面朝方向,移动中设置无效
|
||||||
|
* @param dir 面朝方向
|
||||||
|
*/
|
||||||
|
setFaceDir(dir: Dir2) {
|
||||||
|
if (!this.moving) this.faceDir = dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置当前移动方向,移动中设置无效
|
||||||
|
* @param dir 移动方向
|
||||||
|
*/
|
||||||
|
setMoveDir(dir: Dir2) {
|
||||||
|
if (!this.moving) this.moveDir = dir;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始移动,这个操作后,本次移动将不能通过{@link insertMove}添加移动步骤,
|
* 开始移动,这个操作后,本次移动将不能通过{@link insertMove}添加移动步骤,
|
||||||
* 只能通过{@link IMoveController.push}添加,而通过前者添加的移动步骤会在下次移动生效
|
* 只能通过{@link IMoveController.push}添加,而通过前者添加的移动步骤会在下次移动生效
|
||||||
@ -130,12 +163,14 @@ export abstract class ObjectMoverBase extends EventEmitter<EObjectMovingEvent> {
|
|||||||
if (!step) break;
|
if (!step) break;
|
||||||
if (step.type === 'dir') {
|
if (step.type === 'dir') {
|
||||||
this.moveDir = this.getMoveDir(step.value);
|
this.moveDir = this.getMoveDir(step.value);
|
||||||
|
this.faceDir = this.getFaceDir(step.value);
|
||||||
const code = await this.onStepStart(step, controller);
|
const code = await this.onStepStart(step, controller);
|
||||||
await this.onStepEnd(step, code, controller);
|
await this.onStepEnd(step, code, controller);
|
||||||
} else {
|
} else {
|
||||||
const replay = core.status.replay.speed;
|
const replay = core.status.replay.speed;
|
||||||
const speed = replay === 24 ? 1 : step.value / replay;
|
const speed = replay === 24 ? 1 : step.value / replay;
|
||||||
this.moveSpeed = speed;
|
this.moveSpeed = speed;
|
||||||
|
this.onSetMoveSpeed(speed, controller);
|
||||||
}
|
}
|
||||||
this.emit('stepEnd', step);
|
this.emit('stepEnd', step);
|
||||||
}
|
}
|
||||||
@ -329,6 +364,11 @@ export class BlockMover extends ObjectMoverBase {
|
|||||||
controller: IMoveController
|
controller: IMoveController
|
||||||
): Promise<void> {}
|
): Promise<void> {}
|
||||||
|
|
||||||
|
protected onSetMoveSpeed(
|
||||||
|
speed: number,
|
||||||
|
controller: IMoveController
|
||||||
|
): void {}
|
||||||
|
|
||||||
private moveAnimate(step: MoveStepDir) {
|
private moveAnimate(step: MoveStepDir) {
|
||||||
const layer = this.layerItems[0];
|
const layer = this.layerItems[0];
|
||||||
if (!layer) return;
|
if (!layer) return;
|
||||||
@ -451,15 +491,15 @@ export class HeroMover extends ObjectMoverBase {
|
|||||||
step: MoveStepDir,
|
step: MoveStepDir,
|
||||||
controller: IMoveController
|
controller: IMoveController
|
||||||
): Promise<HeroMoveCode> {
|
): Promise<HeroMoveCode> {
|
||||||
const showDir = toDir(this.moveDir);
|
const showDir = toDir(this.faceDir);
|
||||||
core.setHeroLoc('direction', showDir);
|
core.setHeroLoc('direction', showDir);
|
||||||
const adapter = HeroMover.adapter;
|
|
||||||
adapter?.sync('setAnimateDir', showDir);
|
|
||||||
|
|
||||||
const { x, y } = core.status.hero.loc;
|
const { x, y } = core.status.hero.loc;
|
||||||
const { x: nx, y: ny } = this.nextLoc(x, y, this.moveDir);
|
const { x: nx, y: ny } = this.nextLoc(x, y, this.moveDir);
|
||||||
|
|
||||||
if (this.autoSave) this.checkAutoSave(x, y, nx, ny);
|
if (this.autoSave && !this.ignoreTerrain) {
|
||||||
|
this.checkAutoSave(x, y, nx, ny);
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.inLockControl && core.status.lockControl) {
|
if (!this.inLockControl && core.status.lockControl) {
|
||||||
controller.stop();
|
controller.stop();
|
||||||
@ -537,6 +577,7 @@ export class HeroMover extends ObjectMoverBase {
|
|||||||
core.setHeroLoc('y', ny, true);
|
core.setHeroLoc('y', ny, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.ignoreTerrain) {
|
||||||
const direction = core.getHeroLoc('direction');
|
const direction = core.getHeroLoc('direction');
|
||||||
core.control._moveAction_popAutomaticRoute();
|
core.control._moveAction_popAutomaticRoute();
|
||||||
if (!this.noRoute) core.status.route.push(direction);
|
if (!this.noRoute) core.status.route.push(direction);
|
||||||
@ -545,6 +586,13 @@ export class HeroMover extends ObjectMoverBase {
|
|||||||
core.checkRouteFolding();
|
core.checkRouteFolding();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onSetMoveSpeed(speed: number, controller: IMoveController): void {
|
||||||
|
const adapter = HeroMover.adapter;
|
||||||
|
if (!adapter) return;
|
||||||
|
adapter.sync('setMoveSpeed', speed);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移动动画
|
* 移动动画
|
||||||
@ -563,6 +611,7 @@ export class HeroMover extends ObjectMoverBase {
|
|||||||
const viewport = HeroMover.viewport;
|
const viewport = HeroMover.viewport;
|
||||||
if (!adapter || !viewport) return;
|
if (!adapter || !viewport) return;
|
||||||
viewport.all('moveTo', x, y);
|
viewport.all('moveTo', x, y);
|
||||||
|
adapter.sync('setAnimateDir', showDir);
|
||||||
await adapter.all('move', moveDir);
|
await adapter.all('move', moveDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ export function init() {
|
|||||||
else {
|
else {
|
||||||
if (type === 'speed') moveSteps.push(v);
|
if (type === 'speed') moveSteps.push(v);
|
||||||
else {
|
else {
|
||||||
moveSteps.push(...Array(number).fill(type));
|
moveSteps.push(...Array(Number(number)).fill(type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -149,10 +149,19 @@ export function init() {
|
|||||||
const start: MoveStep = { type: 'speed', value: time };
|
const start: MoveStep = { type: 'speed', value: time };
|
||||||
|
|
||||||
heroMover.insertMove(...[start, ...resolved]);
|
heroMover.insertMove(...[start, ...resolved]);
|
||||||
const controller = heroMover.startMove();
|
const controller = heroMover.startMove(true, true, true, false);
|
||||||
controller?.onEnd.then(() => {
|
if (!controller) {
|
||||||
|
callback?.();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
controller.onEnd.then(() => {
|
||||||
callback?.();
|
callback?.();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const animate = fallbackIds++;
|
||||||
|
|
||||||
|
core.animateFrame.lastAsyncId = animate;
|
||||||
|
core.animateFrame.asyncId[animate] = controller.stop;
|
||||||
};
|
};
|
||||||
|
|
||||||
control.prototype.setHeroLoc = function (
|
control.prototype.setHeroLoc = function (
|
||||||
|
Loading…
Reference in New Issue
Block a user