From 839ba56b5a6feae7d4c799d799e86bb3a686d688 Mon Sep 17 00:00:00 2001 From: poschuler Date: Thu, 10 Oct 2024 19:51:15 -0500 Subject: [PATCH] feat: add mage object and iteraction --- src/gameObjects/map_campus_house_1/index.js | 2 + .../map_campus_house_1/mage.gameObject.js | 35 ++++++ .../map_campus_house_1/bed.interaction.js | 2 +- .../computer.interaction.js | 76 ++++++++---- src/interactions/map_campus_house_1/index.js | 2 + .../map_campus_house_1/mage.interaction.js | 109 ++++++++++++++++++ 6 files changed, 200 insertions(+), 26 deletions(-) create mode 100644 src/gameObjects/map_campus_house_1/mage.gameObject.js create mode 100644 src/interactions/map_campus_house_1/mage.interaction.js diff --git a/src/gameObjects/map_campus_house_1/index.js b/src/gameObjects/map_campus_house_1/index.js index 937c3011..6d1d2c26 100644 --- a/src/gameObjects/map_campus_house_1/index.js +++ b/src/gameObjects/map_campus_house_1/index.js @@ -1,7 +1,9 @@ import { computer } from './computer.gameObject'; +import { mage } from './mage.gameObject'; const gameObjects = [ computer, + mage, // Add more game objects here ]; diff --git a/src/gameObjects/map_campus_house_1/mage.gameObject.js b/src/gameObjects/map_campus_house_1/mage.gameObject.js new file mode 100644 index 00000000..ca5d6c8d --- /dev/null +++ b/src/gameObjects/map_campus_house_1/mage.gameObject.js @@ -0,0 +1,35 @@ +import { scaleFactor } from '../../constants'; + +export const mage = (k, map, spawnpoints) => { + k.loadSprite('mage', './assets/sprites/characters.png', { + sliceX: 10, + sliceY: 20, + anims: { + 'idle-down': 140, + 'walk-down': { from: 144, to: 145, loop: true, speed: 4 }, + 'idle-up': 141, + 'walk-up': { from: 146, to: 147, loop: true, speed: 4 }, + 'idle-right': 142, + }, + }); + + const [bedRoomTable] = map.query({ include: 'bedroom_table' }); + + const mageObj = k.make([ + k.sprite('mage', { anim: 'idle-right' }), + k.area({ + shape: new k.Rect(k.vec2(0), 16, 16), + }), + k.body({ isStatic: true }), + k.anchor('center'), + k.pos( + bedRoomTable.pos.x + 5, + bedRoomTable.pos.y - 70 + ), + k.scale(scaleFactor * 0.5), + k.offscreen({ hide: true, distance: 10 }), + 'mage', + ]); + + return mageObj; +}; diff --git a/src/interactions/map_campus_house_1/bed.interaction.js b/src/interactions/map_campus_house_1/bed.interaction.js index 6c797d72..ef5aac55 100644 --- a/src/interactions/map_campus_house_1/bed.interaction.js +++ b/src/interactions/map_campus_house_1/bed.interaction.js @@ -29,7 +29,7 @@ export const bedInteractions = (player, k, map) => { } } - //player.isInDialog = true; + player.isInDialog = true; displayDialogue({ k, player, diff --git a/src/interactions/map_campus_house_1/computer.interaction.js b/src/interactions/map_campus_house_1/computer.interaction.js index 641b6e0b..b785cbee 100644 --- a/src/interactions/map_campus_house_1/computer.interaction.js +++ b/src/interactions/map_campus_house_1/computer.interaction.js @@ -27,45 +27,71 @@ const options = [ ]; export const computerInteractions = async (player, k, map) => { - player.onCollide('computer', async () => { - const energyUI = document.getElementById('energy-container'); - energyUI.style.display = 'none'; - const [computer] = k.query({ include: 'computer' }); - computer.play('on'); - player.isInDialog = true; - - showCustomPrompt(challengeText, options, async (selectedOption) => { - const response = []; - - if (selectedOption == 'C') { - updateEnergyState(player.state, -10); - response.push("Correct!, you're a genius!"); - response.push('It was a tough one!, You look tired'); - } else { - updateEnergyState(player.state, -30); - response.push('Incorrect! Try again next time!'); - response.push('Anyway it was a good effort, You look tired'); - } + const [computer] = map.query({ include: 'computer' }); - response.push( - 'You should take a nap before you continue exploring the campus' - ); + player.onCollide('computer', async () => { + if (!player.state.alreadyTalkedToMage) { + player.isInDialog = true; + computer.play('on'); await displayDialogue({ k, player, - text: response, + text: [ + 'It looks like the computer has a interesting challenge for you but it is locked.', + 'It has some kind of protection spell.', + 'You should talk to the house mage to unlock it.', + ], onDisplayEnd: () => { player.isInDialog = false; }, }); - }); + + computer.play('off'); + } + + if (player.state.alreadyTalkedToMage) { + const energyUI = document.getElementById('energy-container'); + energyUI.style.display = 'none'; + + player.isInDialog = true; + computer.play('on'); + + showCustomPrompt(challengeText, options, async (selectedOption) => { + const response = []; + + if (selectedOption == 'C') { + updateEnergyState(player.state, -10); + response.push("Correct!, you're a genius!"); + response.push('It was a tough one!, You look tired'); + } else { + updateEnergyState(player.state, -30); + response.push('Incorrect! Try again next time!'); + response.push( + 'Anyway it was a good effort, You look tired' + ); + } + + response.push( + 'You should take a nap before you continue exploring the campus' + ); + + await displayDialogue({ + k, + player, + text: response, + onDisplayEnd: () => { + player.isInDialog = false; + player.state.alreadyTalkedToMage = false; + }, + }); + }); + } }); player.onCollideEnd('computer', () => { const energyUI = document.getElementById('energy-container'); energyUI.style.display = 'flex'; - const [computer] = k.query({ include: 'computer' }); computer.play('off'); }); }; diff --git a/src/interactions/map_campus_house_1/index.js b/src/interactions/map_campus_house_1/index.js index a6811be6..e7d36167 100644 --- a/src/interactions/map_campus_house_1/index.js +++ b/src/interactions/map_campus_house_1/index.js @@ -1,12 +1,14 @@ import { enterMapCityInteraction } from './enterMapCity.interactions'; import { bedInteractions } from './bed.interaction'; import { computerInteractions } from './computer.interaction'; +import { mageInteractions } from './mage.interaction'; const interactions = [ // Add more interactions here enterMapCityInteraction, bedInteractions, computerInteractions, + mageInteractions, ]; export default interactions; diff --git a/src/interactions/map_campus_house_1/mage.interaction.js b/src/interactions/map_campus_house_1/mage.interaction.js new file mode 100644 index 00000000..48e4f350 --- /dev/null +++ b/src/interactions/map_campus_house_1/mage.interaction.js @@ -0,0 +1,109 @@ +import { displayDialogue, displayPermissionBox } from '../../utils'; + +const alredyUnlockText = ['The challenge is waiting for you!']; + +const firstText = [ + 'You shall not pass! Bruruuuuu!', + 'Hehe, you’ve found me, just as I was practicing my lines!', + 'Cof cof… the dust of ancient tomes, no doubt!', + 'I am the Mage of the House, keeper of secrets, and I hold a special challenge within the depths of this computer!', + 'I can unlock the computer for thee, but beware—thou shalt have but one chance to find the right answer!', +]; + +const questionText = [ + 'Do you dare to try thy hand at this most perilous trial?', +]; + +const spell = [ + 'By the stars above, and the code beneath, unlock this mystery, to test their wit and feat!', + 'The computer suddenly glows with a bright light, and the screen changes to show a challenge.', +]; + +const noSpell = [ + 'It does not seem like thou art yet prepared for the challenge...', +]; + +export const mageInteractions = async (player, k, map) => { + const [computer] = map.query({ include: 'computer' }); + let mageInteractionCounter = 0; + player.state.alreadyTalkedToMage = false; + + //TODO: You can add some prize for the player if they solve the challenge and get back to the mage + player.onCollide('mage', async () => { + computer.play('on'); + + if (!player.state.alreadyTalkedToMage) { + mageInteractionCounter++; + + if (mageInteractionCounter === 1) { + player.isInDialog = true; + await displayDialogue({ + k, + player, + text: firstText, + characterName: 'Mage', + onDisplayEnd: () => { + player.isInDialog = false; + }, + }); + } + + if (mageInteractionCounter >= 2) { + player.isInDialog = true; + + let tryChallenge = await displayPermissionBox({ + k, + player, + text: questionText, + onDisplayEnd: () => { + player.isInDialog = false; + }, + }); + + if (tryChallenge) { + player.isInDialog = true; + await displayDialogue({ + k, + player, + text: spell, + characterName: 'Mage', + onDisplayEnd: () => { + player.isInDialog = false; + }, + }); + + //TODO: You can add a flickering effect to the dialog box to make it more magical + + player.state.alreadyTalkedToMage = true; + } else { + player.isInDialog = true; + await displayDialogue({ + k, + player, + text: noSpell, + characterName: 'Mage', + onDisplayEnd: () => { + player.isInDialog = false; + }, + }); + } + } + } else { + player.isInDialog = true; + computer.play('on'); + + await displayDialogue({ + k, + player, + text: alredyUnlockText, + onDisplayEnd: () => { + player.isInDialog = false; + }, + }); + } + }); + + player.onCollideEnd('mage', () => { + computer.play('off'); + }); +};