Files
MI2Mario/src/entities/Chest.js
T
Pascal 9194dc50ed added jump
Signed-off-by: Pascal Syma <pascal@syma.dev>
2020-07-17 03:40:42 +02:00

41 lines
921 B
JavaScript

/*
* Copyright (c) 2020. Antonio Martinez Casadesus and Pascal Syma.
* All rights reserved.
*/
import Interactable from "./Interactable";
import Item from "./Item";
export default class Chest extends Interactable {
constructor(scene, item) {
super(scene, item.x, item.y, 'chest');
this.setFrame(4);
this.body.setAllowGravity(false);
this.setOrigin(0.5, 1);
this.setData('opened', false);
}
canInteract() {
return !this.getData('opened');
}
interact() {
super.interact();
this.setData('opened', true);
this.play('chest_open');
const options = [/*"storm", "slow", */"jump", "speed", "heal"];
let item = new Item(this.scene, {
x: this.x,
y: this.y - this.height
}, options[Math.floor(Math.random() * options.length)])
this.scene.interactables.add(item);
}
}