forked from zero-to-mastery/ZTM-Quest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcat.interaction.js
More file actions
38 lines (36 loc) · 1.21 KB
/
Copy pathcat.interaction.js
File metadata and controls
38 lines (36 loc) · 1.21 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
import { time } from '../../kplayCtx';
import { displayDialogue, showCustomPrompt } from '../../utils';
import { updateEnergyState } from '../../utils/energyUpdate';
let abort;
export const interactionWithCat = (player, k, map) => {
player.onCollide('cat', () => {
time.paused = true;
player.state.isInDialog = true;
abort = new AbortController();
showCustomPrompt(
'Cat wants to play with you',
['Play', 'Leave'],
(selectedOption) => {
const texts = {
Play: ['Wow, I feel fresh and energetic!'],
Leave: ['Maybe next time!'],
};
if (texts[selectedOption]) {
displayDialogue({
k,
player,
text: texts[selectedOption],
onDisplayEnd: () => {
if (selectedOption === 'Play') {
updateEnergyState(player.state, 10);
}
},
});
}
},
player,
k,
abort
);
});
};