caa-game/src/entities/portal.js

65 lines
1.2 KiB
JavaScript

var asdf = require("asdf-games");
// eslint-disable-next-line no-unused-vars
const { Texture, TileSprite, entity } = asdf;
var texture = new Texture("./res/tilemap.png");
class Portal extends TileSprite {
constructor(pos, player, keys, type, action, key) {
super(texture, 32, 32);
this.pos = pos;
this.scale = { x: 1, y: 1 };
this.player = player;
this.action = action;
this.keys = keys;
this.key = key;
switch (type) {
case "Door":
this.frame = { x: 1, y: 7 };
this.hitBox = {
x: 1,
y: 1,
w: 30,
h: 30
};
break;
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);
if (entity.hit(this, this.player) && this.keys.action) {
if (this.key) {
if (this.player.key) {
this.action();
} else {
console.log("keyn't");
}
} else {
this.action();
}
}
}
}
module.exports = Portal;