-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add mage object and iteraction (#136)
Part of #130
- Loading branch information
Showing
6 changed files
with
198 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/interactions/map_campus_house_1/mage.interaction.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}; |