Fixed key checking on portal

This commit is contained in:
Arne van Iterson 2020-04-13 22:46:02 +02:00
parent 643ca24bad
commit 082dca9bd4
2 changed files with 8 additions and 28 deletions

View File

@ -78,36 +78,15 @@ class Portal extends TileSprite {
}
if (this.key != "") {
if (this.player.items.keys.length > 0) {
for (let index = 0; index < this.player.items.keys.length; index++) {
const element = this.player.items.keys[index];
console.log(this.key);
console.log(element);
if (element == this.key) {
// Correct key
this.pointer.anims.play("white");
if (this.keys.action) {
this.action();
console.warn("action");
}
break;
} else {
// Not the correct key
console.log("correct keyn't");
this.pointer.anims.play("red");
if (this.keys.action) {
if (!sounds.forbidden.playing && !this.pressed) {
sounds.forbidden.play();
this.pressed = true;
}
} else {
this.pressed = false;
}
}
if (this.player.items.keys.includes(this.key)) {
// Correct key
this.pointer.anims.play("white");
if (this.keys.action) {
this.action();
console.warn("action");
}
} else {
// No keys at all
console.log("You have no keys");
// No key or not the correct key
this.pointer.anims.play("red");
if (this.keys.action) {
if (!sounds.forbidden.playing && !this.pressed) {

View File

@ -12,6 +12,7 @@ class GameScreen extends Container {
constructor(game, window, keys, onGameOver) {
super();
this.game = game;
this.window = window;
this.keys = keys;
this.onGameOver = onGameOver;