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++) { // Correct key
const element = this.player.items.keys[index]; this.pointer.anims.play("white");
console.log(this.key); if (this.keys.action) {
console.log(element); this.action();
if (element == this.key) { console.warn("action");
// 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;
}
}
} }
} else { } else {
// No keys at all // No key or not the correct key
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;