2024-07-30 18:56:24 +00:00
|
|
|
class GameObject {
|
|
|
|
constructor(config) {
|
2024-08-02 14:01:51 +00:00
|
|
|
this.id = null;
|
2024-07-30 18:56:24 +00:00
|
|
|
this.isMounted = false;
|
|
|
|
this.x = config.x || 0;
|
|
|
|
this.y = config.y || 0;
|
|
|
|
this.direction = config.direction || "down";
|
|
|
|
this.sprite = new Sprite({
|
|
|
|
gameObject: this,
|
|
|
|
src: config.src || "/images/characters/people/hero.png",
|
|
|
|
|
|
|
|
});
|
2024-08-02 14:01:51 +00:00
|
|
|
|
|
|
|
this.behaviorLoop = config.behaviorLoop || [];
|
|
|
|
this.behaviorLoopIndex = 0;
|
2024-07-30 18:56:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mount(map) {
|
|
|
|
this.isMounted = true;
|
|
|
|
map.addWall(this.x, this.y);
|
2024-08-02 14:01:51 +00:00
|
|
|
|
|
|
|
// when behavior kick off after delay
|
|
|
|
setTimeout(() => {
|
|
|
|
this.doBehaviorEvent(map);
|
|
|
|
}, 10);
|
2024-07-30 18:56:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
update() {
|
|
|
|
|
|
|
|
}
|
2024-08-02 14:01:51 +00:00
|
|
|
|
|
|
|
async doBehaviorEvent(map) {
|
|
|
|
// stop if cutscene is playing
|
2024-08-05 16:14:13 +00:00
|
|
|
if (map.isCutscenePlaying || this.behaviorLoop.length === 0 || this.isStanding) {
|
2024-08-02 14:01:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let eventConfig = this.behaviorLoop[this.behaviorLoopIndex];
|
|
|
|
eventConfig.who = this.id;
|
|
|
|
|
|
|
|
const eventHandler = new OverworldEvent({ map, event: eventConfig });
|
|
|
|
await eventHandler.init();
|
|
|
|
|
|
|
|
this.behaviorLoopIndex += 1;
|
|
|
|
if (this.behaviorLoopIndex === this.behaviorLoop.length) {
|
|
|
|
this.behaviorLoopIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.doBehaviorEvent(map);
|
|
|
|
}
|
2024-07-30 18:56:24 +00:00
|
|
|
}
|