Я пишу простую платформерную игру.Я использую мозаичные карты для создания слоев уровней для перекрытий и столкновений.У меня возникла проблема: я пытаюсь сделать так, чтобы игрок мог подниматься по лестнице, когда происходит перекрытие с плитой лестницы.
У меня есть переменная в объекте gameSettings playerMoveY: false (поэтому по умолчанию игрок можеттолько идти влево или вправо)
Когда игрок перекрывает плитку лестницы, он может подниматься, но после этого он всегда может подниматься, потому что переменная playerMoveY по-прежнему = true.Я не знаю, как переключить его обратно.Может быть, использование флага не очень хорошая идея.Мне нужен совет.Спасибо.
let gameSettings = {
playerSpeed: 60,
playerMoveY: false,
}
//here's the code from gameScene class
this.laddersLayer.setTileIndexCallback(29, this.allowClimb, this);
this.physics.add.overlap(this.player, this.laddersLayer);
movePlayerManager() {
if (this.cursorKeys.left.isDown) {
this.player.anims.play('playerWalkLeft', true);
this.player.setVelocityX(-gameSettings.playerSpeed);
} else if (this.cursorKeys.right.isDown) {
this.player.anims.play('playerWalkRight', true);
this.player.setVelocityX(gameSettings.playerSpeed);
} else {
this.player.setVelocityX(0);
this.player.anims.play('playerStand');
}
if (gameSettings.playerMoveY) {
if (this.cursorKeys.up.isDown) {
this.player.anims.play('playerClimb', true);
this.player.setVelocityY(-gameSettings.playerSpeed);
} else if (this.cursorKeys.down.isDown) {
this.player.anims.play('playerClimb', true);
this.player.setVelocityY(gameSettings.playerSpeed);
} else {
this.player.setVelocityY(0);
}
}
}
//and here's the callback function when overlap
allowClimb() {
gameSettings.playerMoveY = true;
}