2020-04-06 22:49:32 +02:00
|
|
|
var asdf = require("asdf-games");
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
2020-04-13 11:48:48 +02:00
|
|
|
const { Texture, Sound, TileSprite, entity } = asdf;
|
|
|
|
|
|
|
|
const texture = new Texture(__dirname + "/../../res/images/tilemap.png");
|
|
|
|
const sounds = {
|
|
|
|
forbidden: new Sound(__dirname + "/../../res/sounds/forbidden.wav")
|
|
|
|
};
|
2020-04-06 22:49:32 +02:00
|
|
|
|
2020-04-11 20:58:55 +02:00
|
|
|
var Pointer = require("./pointer.js");
|
2020-04-06 22:49:32 +02:00
|
|
|
|
|
|
|
class Portal extends TileSprite {
|
2020-04-11 20:58:55 +02:00
|
|
|
constructor(pos, player, keys, level, type, action, key) {
|
2020-04-06 22:49:32 +02:00
|
|
|
super(texture, 32, 32);
|
|
|
|
this.pos = pos;
|
|
|
|
this.scale = { x: 1, y: 1 };
|
|
|
|
this.player = player;
|
2020-04-11 20:58:55 +02:00
|
|
|
this.level = level;
|
2020-04-06 22:49:32 +02:00
|
|
|
this.action = action;
|
|
|
|
|
2020-04-11 20:58:55 +02:00
|
|
|
this.pointer = false;
|
2020-04-13 11:48:48 +02:00
|
|
|
this.pressed = false;
|
|
|
|
|
2020-04-07 12:14:22 +02:00
|
|
|
this.keys = keys;
|
|
|
|
this.key = key;
|
|
|
|
|
2020-04-06 22:49:32 +02:00
|
|
|
switch (type) {
|
2020-04-08 16:59:49 +02:00
|
|
|
case "Door_n":
|
2020-04-06 22:49:32 +02:00
|
|
|
this.frame = { x: 1, y: 7 };
|
|
|
|
this.hitBox = {
|
|
|
|
x: 1,
|
|
|
|
y: 1,
|
|
|
|
w: 30,
|
2020-04-08 12:36:03 +02:00
|
|
|
h: 45
|
2020-04-06 22:49:32 +02:00
|
|
|
};
|
|
|
|
break;
|
2020-04-08 16:59:49 +02:00
|
|
|
case "Door_s":
|
|
|
|
this.frame = { x: 2, y: 9 };
|
|
|
|
this.hitBox = {
|
|
|
|
x: 0,
|
|
|
|
y: -13,
|
|
|
|
w: 32,
|
|
|
|
h: 45
|
|
|
|
};
|
|
|
|
break;
|
2020-04-06 22:49:32 +02:00
|
|
|
case "Ladder":
|
|
|
|
this.frame = { x: 2, y: 7 };
|
|
|
|
this.hitBox = {
|
|
|
|
x: 4,
|
|
|
|
y: 0,
|
|
|
|
w: 24,
|
|
|
|
h: 32
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case "Stairs":
|
|
|
|
this.frame = { x: 4, y: 7 };
|
|
|
|
this.hitBox = {
|
|
|
|
x: 1,
|
|
|
|
y: 1,
|
|
|
|
w: 30,
|
|
|
|
h: 30
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update(dt) {
|
|
|
|
super.update(dt);
|
2020-04-11 20:58:55 +02:00
|
|
|
|
|
|
|
if (entity.hit(this, this.player)) {
|
|
|
|
if (!this.pointer) {
|
|
|
|
var pointer = new Pointer({
|
|
|
|
x: (this.pos.x + this.tileW / 2) - 8,
|
|
|
|
y: this.pos.y - 16
|
|
|
|
});
|
|
|
|
this.level.entities.add(pointer);
|
|
|
|
this.pointer = pointer;
|
|
|
|
}
|
|
|
|
|
2020-04-08 16:59:49 +02:00
|
|
|
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];
|
2020-04-13 11:48:48 +02:00
|
|
|
console.log(this.key);
|
|
|
|
console.log(element);
|
2020-04-08 16:59:49 +02:00
|
|
|
if (element == this.key) {
|
2020-04-11 20:58:55 +02:00
|
|
|
// Correct key
|
|
|
|
this.pointer.anims.play("white");
|
|
|
|
if (this.keys.action) {
|
|
|
|
this.action();
|
2020-04-13 11:48:48 +02:00
|
|
|
console.warn("action");
|
2020-04-11 20:58:55 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-04-08 16:59:49 +02:00
|
|
|
} else {
|
|
|
|
// Not the correct key
|
|
|
|
console.log("correct keyn't");
|
2020-04-13 11:48:48 +02:00
|
|
|
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;
|
|
|
|
}
|
2020-04-08 16:59:49 +02:00
|
|
|
}
|
|
|
|
}
|
2020-04-07 12:14:22 +02:00
|
|
|
} else {
|
2020-04-08 16:59:49 +02:00
|
|
|
// No keys at all
|
2020-04-13 11:48:48 +02:00
|
|
|
console.log("You have no keys");
|
2020-04-11 20:58:55 +02:00
|
|
|
this.pointer.anims.play("red");
|
2020-04-13 11:48:48 +02:00
|
|
|
if (this.keys.action) {
|
|
|
|
if (!sounds.forbidden.playing && !this.pressed) {
|
|
|
|
sounds.forbidden.play();
|
|
|
|
this.pressed = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.pressed = false;
|
|
|
|
}
|
2020-04-07 12:14:22 +02:00
|
|
|
}
|
|
|
|
} else {
|
2020-04-11 20:58:55 +02:00
|
|
|
if (this.keys.action) {
|
|
|
|
this.action();
|
|
|
|
}
|
2020-04-07 12:14:22 +02:00
|
|
|
}
|
2020-04-11 20:58:55 +02:00
|
|
|
} else {
|
|
|
|
this.level.entities.remove(this.pointer);
|
|
|
|
this.pointer = false;
|
2020-04-06 22:49:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Portal;
|