Skip to content

Commit eb53f47

Browse files
authored
feat: add mage object and iteraction (#136)
Part of #130
2 parents db79ea6 + 0f16506 commit eb53f47

File tree

6 files changed

+198
-26
lines changed

6 files changed

+198
-26
lines changed

src/gameObjects/map_campus_house_1/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { computer } from './computer.gameObject';
2+
import { mage } from './mage.gameObject';
23

34
const gameObjects = [
45
computer,
6+
mage,
57
// Add more game objects here
68
];
79

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { scaleFactor } from '../../constants';
2+
3+
export const mage = (k, map, spawnpoints) => {
4+
k.loadSprite('mage', './assets/sprites/characters.png', {
5+
sliceX: 10,
6+
sliceY: 20,
7+
anims: {
8+
'idle-down': 140,
9+
'walk-down': { from: 144, to: 145, loop: true, speed: 4 },
10+
'idle-up': 141,
11+
'walk-up': { from: 146, to: 147, loop: true, speed: 4 },
12+
'idle-right': 142,
13+
},
14+
});
15+
16+
const [bedRoomTable] = map.query({ include: 'bedroom_table' });
17+
18+
const mageObj = k.make([
19+
k.sprite('mage', { anim: 'idle-right' }),
20+
k.area({
21+
shape: new k.Rect(k.vec2(0), 16, 16),
22+
}),
23+
k.body({ isStatic: true }),
24+
k.anchor('center'),
25+
k.pos(
26+
bedRoomTable.pos.x + 5,
27+
bedRoomTable.pos.y - 70
28+
),
29+
k.scale(scaleFactor * 0.5),
30+
k.offscreen({ hide: true, distance: 10 }),
31+
'mage',
32+
]);
33+
34+
return mageObj;
35+
};

src/interactions/map_campus_house_1/bed.interaction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const bedInteractions = (player, k, map) => {
2929
}
3030
}
3131

32-
//player.isInDialog = true;
32+
player.isInDialog = true;
3333
displayDialogue({
3434
k,
3535
player,

src/interactions/map_campus_house_1/computer.interaction.js

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,64 @@ const options = [
2828

2929
export const computerInteractions = async (player, k, map) => {
3030
const [computer] = map.query({ include: 'computer' });
31-
3231
player.onCollide('computer', async () => {
33-
const energyUI = document.getElementById('energy-container');
34-
energyUI.style.display = 'none';
35-
36-
player.isInDialog = true;
37-
computer.play('on');
38-
39-
showCustomPrompt(challengeText, options, async (selectedOption) => {
40-
const response = [];
41-
42-
if (selectedOption == 'C') {
43-
updateEnergyState(player.state, -10);
44-
response.push("Correct!, you're a genius!");
45-
response.push('It was a tough one!, You look tired');
46-
} else {
47-
updateEnergyState(player.state, -30);
48-
response.push('Incorrect! Try again next time!');
49-
response.push('Anyway it was a good effort, You look tired');
50-
}
51-
52-
response.push(
53-
'You should take a nap before you continue exploring the campus'
54-
);
32+
if (!player.state.alreadyTalkedToMage) {
33+
player.isInDialog = true;
34+
computer.play('on');
5535

5636
await displayDialogue({
5737
k,
5838
player,
59-
text: response,
39+
text: [
40+
'It looks like the computer has a interesting challenge for you but it is locked.',
41+
'It has some kind of protection spell.',
42+
'You should talk to the house mage to unlock it.',
43+
],
6044
onDisplayEnd: () => {
6145
player.isInDialog = false;
6246
},
6347
});
64-
});
48+
49+
computer.play('off');
50+
}
51+
52+
if (player.state.alreadyTalkedToMage) {
53+
const energyUI = document.getElementById('energy-container');
54+
energyUI.style.display = 'none';
55+
56+
player.isInDialog = true;
57+
computer.play('on');
58+
59+
showCustomPrompt(challengeText, options, async (selectedOption) => {
60+
const response = [];
61+
62+
if (selectedOption == 'C') {
63+
updateEnergyState(player.state, -10);
64+
response.push("Correct!, you're a genius!");
65+
response.push('It was a tough one!, You look tired');
66+
} else {
67+
updateEnergyState(player.state, -30);
68+
response.push('Incorrect! Try again next time!');
69+
response.push(
70+
'Anyway it was a good effort, You look tired'
71+
);
72+
}
73+
74+
response.push(
75+
'You should take a nap before you continue exploring the campus'
76+
);
77+
78+
await displayDialogue({
79+
k,
80+
player,
81+
text: response,
82+
onDisplayEnd: () => {
83+
player.isInDialog = false;
84+
player.state.alreadyTalkedToMage = false;
85+
},
86+
});
87+
});
88+
}
6589
});
6690

6791
player.onCollideEnd('computer', () => {

src/interactions/map_campus_house_1/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { enterMapCityInteraction } from './enterMapCity.interactions';
22
import { bedInteractions } from './bed.interaction';
33
import { computerInteractions } from './computer.interaction';
4+
import { mageInteractions } from './mage.interaction';
45
import { bedroomVanityInteractions } from './bedroomVanity.interaction';
56

67
const interactions = [
78
// Add more interactions here
89
enterMapCityInteraction,
910
bedInteractions,
1011
computerInteractions,
12+
mageInteractions,
1113
bedroomVanityInteractions,
1214
];
1315

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import { displayDialogue, displayPermissionBox } from '../../utils';
2+
3+
const alredyUnlockText = ['The challenge is waiting for you!'];
4+
5+
const firstText = [
6+
'You shall not pass! Bruruuuuu!',
7+
'Hehe, you’ve found me, just as I was practicing my lines!',
8+
'Cof cof… the dust of ancient tomes, no doubt!',
9+
'I am the Mage of the House, keeper of secrets, and I hold a special challenge within the depths of this computer!',
10+
'I can unlock the computer for thee, but beware—thou shalt have but one chance to find the right answer!',
11+
];
12+
13+
const questionText = [
14+
'Do you dare to try thy hand at this most perilous trial?',
15+
];
16+
17+
const spell = [
18+
'By the stars above, and the code beneath, unlock this mystery, to test their wit and feat!',
19+
'The computer suddenly glows with a bright light, and the screen changes to show a challenge.',
20+
];
21+
22+
const noSpell = [
23+
'It does not seem like thou art yet prepared for the challenge...',
24+
];
25+
26+
export const mageInteractions = async (player, k, map) => {
27+
const [computer] = map.query({ include: 'computer' });
28+
let mageInteractionCounter = 0;
29+
player.state.alreadyTalkedToMage = false;
30+
31+
//TODO: You can add some prize for the player if they solve the challenge and get back to the mage
32+
player.onCollide('mage', async () => {
33+
computer.play('on');
34+
35+
if (!player.state.alreadyTalkedToMage) {
36+
mageInteractionCounter++;
37+
38+
if (mageInteractionCounter === 1) {
39+
player.isInDialog = true;
40+
await displayDialogue({
41+
k,
42+
player,
43+
text: firstText,
44+
characterName: 'Mage',
45+
onDisplayEnd: () => {
46+
player.isInDialog = false;
47+
},
48+
});
49+
}
50+
51+
if (mageInteractionCounter >= 2) {
52+
player.isInDialog = true;
53+
54+
let tryChallenge = await displayPermissionBox({
55+
k,
56+
player,
57+
text: questionText,
58+
onDisplayEnd: () => {
59+
player.isInDialog = false;
60+
},
61+
});
62+
63+
if (tryChallenge) {
64+
player.isInDialog = true;
65+
await displayDialogue({
66+
k,
67+
player,
68+
text: spell,
69+
characterName: 'Mage',
70+
onDisplayEnd: () => {
71+
player.isInDialog = false;
72+
},
73+
});
74+
75+
//TODO: You can add a flickering effect to the dialog box to make it more magical
76+
77+
player.state.alreadyTalkedToMage = true;
78+
} else {
79+
player.isInDialog = true;
80+
await displayDialogue({
81+
k,
82+
player,
83+
text: noSpell,
84+
characterName: 'Mage',
85+
onDisplayEnd: () => {
86+
player.isInDialog = false;
87+
},
88+
});
89+
}
90+
}
91+
} else {
92+
player.isInDialog = true;
93+
computer.play('on');
94+
95+
await displayDialogue({
96+
k,
97+
player,
98+
text: alredyUnlockText,
99+
onDisplayEnd: () => {
100+
player.isInDialog = false;
101+
},
102+
});
103+
}
104+
});
105+
106+
player.onCollideEnd('mage', () => {
107+
computer.play('off');
108+
});
109+
};

0 commit comments

Comments
 (0)