diff --git a/src/entities/portal.js b/src/entities/portal.js index 6ec2143..f1700e8 100644 --- a/src/entities/portal.js +++ b/src/entities/portal.js @@ -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) { diff --git a/src/screens/game.js b/src/screens/game.js index c37e9d8..92d648e 100644 --- a/src/screens/game.js +++ b/src/screens/game.js @@ -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;