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.key != "") {
if (this.player.items.keys.length > 0) { if (this.player.items.keys.includes(this.key)) {
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 // Correct key
this.pointer.anims.play("white"); this.pointer.anims.play("white");
if (this.keys.action) { if (this.keys.action) {
this.action(); this.action();
console.warn("action"); console.warn("action");
} }
break;
} else { } else {
// Not the correct key // No key or 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;
}
}
}
} else {
// No keys at all
console.log("You have no keys");
this.pointer.anims.play("red"); this.pointer.anims.play("red");
if (this.keys.action) { if (this.keys.action) {
if (!sounds.forbidden.playing && !this.pressed) { if (!sounds.forbidden.playing && !this.pressed) {

View File

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