-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacter.js
More file actions
76 lines (61 loc) · 2.35 KB
/
Copy pathCharacter.js
File metadata and controls
76 lines (61 loc) · 2.35 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class Character {
constructor(config) {
this.name = config.name;
this.x = config.x || 0;
this.y = config.y || 372;
this.direction = config.direction || "right";
this.sprite = new Sprite ({
character: this,
src: config.src || "images/characters/Emery.png",
spriteHeight: config.spriteHeight || 96
});
this.movingProgressRemaining = 0;
this.directionUpdate = {
"right": ["x", 1],
"left": ["x", -1],
};
this.dialogueNodes = config.dialogue || [];
this.dialogueNodesIndex = 0;
}
update() {
this.updatePosition();
this.updateSprite();
}
updatePosition() {
if (this.movingProgressRemaining > 0) {
const [property, change] = this.directionUpdate[this.direction];
this[property] += change;
this.movingProgressRemaining -= 1
}
}
updateSprite() {
this.sprite.setAnimation("idle-" + this.direction);
}
async doDialogueNode(map) {
// Get the character's name and its dialogue node from window.GameState
const characterName = this.name;
const dialogueNode = window.gameState.dialogueNodes[characterName];
// If there is no dialogue node for this character, return
if (!dialogueNode) {
return;
}
map.isCutscenePlaying = true;
// Get the event config from this.dialogueNodes using dialogueNode as the key
const eventConfig = this.dialogueNodes[dialogueNode];
// Loop through all the events in the eventConfig array and await each event
for (let i = 0; i < eventConfig.length; i++) {
const eventHandler = new GameEvent({ event: eventConfig[i], map: this.map });
await eventHandler.init();
}
// Increment the dialogueNodesIndex
this.dialogueNodesIndex += 1;
if (this.dialogueNodesIndex === this.dialogueNodes.length) {
this.dialogueNodesIndex = 0;
}
// Update the dialogue node in window.GameState for this character
// window.gameState.dialogueNodes[characterName] = this.dialogueNodes[this.dialogueNodesIndex];
// Set isCutscenePlaying to false
map.isCutscenePlaying = false;
map.exitThrone();
}
}