-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameObject.js
62 lines (46 loc) · 1.54 KB
/
GameObject.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class GameObject {
constructor(config) {
this.id = null;
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 || "./assets/sprite/hero.png",
});
this.behaviorLoop = config.behaviorLoop || [];
this.behaviorLoopIndex = 0;
this.talking = config.talking || [];
}
mount(map) {
console.log("mounting!")
this.isMounted = true;
map.addWall(this.x, this.y);
// if we have a behvaior kick off after a delay
setTimeout( () =>{
this.doBehaviorEvent(map)
}, 10)
}
update() {
}
async doBehaviorEvent(map){
//basically if there is a cutscene going on, dont fire off the global behaviors
if(map.isCutscenePlaying || this.behaviorLoop.length === 0 || this.isStanding){
return
}
//setting up event with relevant info
let eventConfig = this.behaviorLoop[this.behaviorLoopIndex];
eventConfig.who = this.id;
// will hold events for things like cutscenes, map changes, and texts
const eventHandler = new OverworldEvent ({map, event: eventConfig});
await eventHandler.init();
//setting next event to fire
this.behaviorLoopIndex += 1;
if( this.behaviorLoopIndex === this.behaviorLoop.length) {
this.behaviorLoopIndex= 0;
}
// after the loop on line 42 is done then do it again
this.doBehaviorEvent(map);
}
}