fix: 优化移动手感

This commit is contained in:
AncTe committed 2024-08-26 21:55:42 +08:00
1 parent 1c369251b1
commit e5afdb73fd
3 files changed
+46 -41

No files matched your search

+38 -37
View File
@@ -25,45 +25,47 @@ export function init() {
const pressedArrow: Set<Dir> = new Set();
Mota.r(() => {
const gameKey = Mota.require('var', 'gameKey');
gameKey
.realize('moveUp', onMoveKeyDown('up'), { type: 'down' })
.realize('moveUp', onMoveKeyUp('up'))
.realize('moveDown', onMoveKeyDown('down'), { type: 'down' })
.realize('moveDown', onMoveKeyUp('down'))
.realize('moveLeft', onMoveKeyDown('left'), { type: 'down' })
.realize('moveLeft', onMoveKeyUp('left'))
.realize('moveRight', onMoveKeyDown('right'), { type: 'down' })
.realize('moveRight', onMoveKeyUp('right'));
const { moveUp, moveDown, moveLeft, moveRight } = gameKey.data;
const symbol = Symbol.for('@key_main');
gameKey.on('press', code => {
if (core.status.lockControl || gameKey.scope !== symbol) return;
if (code === moveUp.key) onMoveKeyDown('up');
if (code === moveDown.key) onMoveKeyDown('down');
if (code === moveLeft.key) onMoveKeyDown('left');
if (code === moveRight.key) onMoveKeyDown('right');
});
gameKey.on('release', code => {
if (code === moveUp.key) onMoveKeyUp('up');
if (code === moveDown.key) onMoveKeyUp('down');
if (code === moveLeft.key) onMoveKeyUp('left');
if (code === moveRight.key) onMoveKeyUp('right');
});
});
function onMoveKeyDown(type: Dir) {
return () => {
pressedArrow.add(type);
moveDir = type;
pressedArrow.add(type);
moveDir = type;
if (!moving) {
stepDir = moveDir;
readyMove();
}
if (moving && stopChian) {
stopChian = false;
}
}
function onMoveKeyUp(type: Dir) {
pressedArrow.delete(type);
if (pressedArrow.size === 0) {
stopChian = true;
} else {
const arr = [...pressedArrow];
moveDir = arr[0];
if (!moving) {
stepDir = moveDir;
readyMove();
}
if (moving && stopChian) {
stopChian = false;
}
};
}
function onMoveKeyUp(type: Dir) {
return () => {
pressedArrow.delete(type);
if (pressedArrow.size === 0) {
stopChian = true;
} else {
const arr = [...pressedArrow];
moveDir = arr[0];
if (!moving) {
stepDir = moveDir;
readyMove();
}
}
};
}
}
async function readyMove() {
@@ -108,11 +110,6 @@ export function init() {
stopChian = true;
return;
}
if (core.status.lockControl) {
pressedArrow.clear();
stopChian = true;
return;
}
if (checkCanMoveStatus()) {
if (!moving) {
stepDir = moveDir;
@@ -275,6 +272,10 @@ export function init() {
adapters['hero-adapter']?.all('setImage', img);
};
control.prototype.isMoving = function () {
return moving;
};
hook.on('reset', () => {
moveDir = core.status.hero.loc.direction;
stepDir = moveDir;