var asdf = require("asdf-games"); // eslint-disable-next-line no-unused-vars const { Texture, TileSprite, AnimManager, entity } = asdf; var texture = new Texture("./res/tilemap.png"); const state = { open: 0, closed: 1 }; class Chest extends TileSprite { constructor(pos, player, keys, action) { super(texture, 32, 32); this.pos = pos; this.scale = { x: 1, y: 1 }; this.anims = new AnimManager(this); this.anims.add("open", [{ x: 3, y: 6 }], 0.1); this.anims.add("closed", [{ x: 2, y: 6 }], 0.1); this.anims.play("closed"); this.state = state.closed; this.player = player; this.keys = keys; this.action = action; this.hitBox = { x: 1, y: 1, w: 28, h: 28 }; } update(dt) { super.update(dt); if (entity.hit(this, this.player) && this.keys.action && this.state == state.closed) { this.state = state.open; this.action(); } if (this.state == state.closed) { this.anims.play("closed"); } else if (this.state == state.open) { this.anims.play("open"); } } } module.exports = Chest;