Skip to content

Commit

Permalink
Added a cat interaction (#170)
Browse files Browse the repository at this point in the history
Part of #2
  • Loading branch information
r4pt0s authored Oct 21, 2024
2 parents 7b18c57 + 2e7c653 commit 990cfe9
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
79 changes: 79 additions & 0 deletions src/interactions/map_start/cat.interaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { displayDialogue } from '../../utils';
import { updateEnergyState } from '../../utils/energyUpdate';



export const interactionWithCat = (player, k, map) => {
player.onCollide('cat', () => {
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);
}
},
});
}
}
);
});
};


function showCustomPrompt(message, options, callback) {
document.getElementById('prompt-message').textContent = message;


const optionsContainer = document.getElementById('options-container');
optionsContainer.innerHTML = '';


options.forEach((option) => {
const button = document.createElement('button');
button.textContent = option;
button.classList.add('option-btn');
button.setAttribute('tabindex', '0');


button.onclick = function () {
callback(option);
closeCustomPrompt();
};


button.addEventListener('keydown', function (e) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
callback(option);
closeCustomPrompt();
}
});

optionsContainer.appendChild(button);
});


document.getElementById('custom-prompt').style.display = 'flex';


if (optionsContainer.children.length > 0) {
optionsContainer.children[0].focus();
}
}


function closeCustomPrompt() {

document.getElementById('custom-prompt').style.display = 'none';
}
2 changes: 2 additions & 0 deletions src/interactions/map_start/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { interactionWithMisterFu } from './misterFu.interaction';
import { interactionWithTV } from './tv_main_room.interaction';
import { interactionWithCake } from './cake.interaction';
import { interactionWithLocker } from './locker.interaction';
import { interactionWithCat } from './cat.interaction';

const interactions = [
restroomInteractions,
Expand All @@ -26,6 +27,7 @@ const interactions = [
interactionWithTV,
interactionWithCake,
interactionWithLocker,
interactionWithCat
];

export default interactions;

0 comments on commit 990cfe9

Please sign in to comment.