Skip to content

Commit

Permalink
Merge branch 'main' into bird_npc_city_map
Browse files Browse the repository at this point in the history
  • Loading branch information
r4pt0s authored Oct 31, 2024
2 parents 75a92e2 + 6fa3118 commit e458bc2
Show file tree
Hide file tree
Showing 17 changed files with 1,311 additions and 1 deletion.
Binary file added public/exports/maps/map_realtor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
999 changes: 999 additions & 0 deletions public/maps/map_realtor.json

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions src/gameObjects/map_realtor/clerk.gameObjects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { scaleFactor } from '../../constants';

export const clerk = (k, map, spawnpoints) => {
k.loadSprite('clerk', './assets/sprites/characters.png', {
sliceX: 10,
sliceY: 20,
anims: {
'idle-down': 160,
'walk-down': { from: 184, to: 185, loop: true, speed: 4 },
'idle-side': 52,
'walk-side': { from: 188, to: 190, loop: true, speed: 4 },
'idle-up': 181,
'walk-up': { from: 186, to: 199, loop: true, speed: 4 },
},
});

return k.make([
k.sprite('clerk', { anim: 'idle-down' }),
k.area({
shape: new k.Rect(k.vec2(0), 16, 16),
}),
k.body({ isStatic: true }),
k.anchor('center'),
k.pos(
map.pos.x + spawnpoints.clerk.x / scaleFactor,
map.pos.y + spawnpoints.clerk.y / scaleFactor
),
k.offscreen({ hide: true, distance: 10 }),
'clerk',
]);
};
5 changes: 5 additions & 0 deletions src/gameObjects/map_realtor/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { clerk } from './clerk.gameObjects';

const gameObjects = [clerk];

export default gameObjects;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const enterMapRealtor = (player, k) => {
player.onCollide('enter_map_realtor_office', () => {
k.go('realtor');
});
};
2 changes: 2 additions & 0 deletions src/interactions/map_extended_campus/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { enterMapCityLeft } from './enterMapCityLeft.interactions';
import { enterMapCityTop } from './enterMapCityTop.interactions';
import { enterMapRealtor } from './enterMapRealtor.interactions';
import { campusTreeInteraction } from './campusTreeInteraction.interactions';
import { fountainInteraction } from './fountainInteraction.interactions';
import { signLeftInteraction } from './signLeftInteraction.interactions';
Expand All @@ -9,6 +10,7 @@ import { treeSignInteraction } from './treeSignInteraction.interactions';
const interactions = [
enterMapCityLeft,
enterMapCityTop,
enterMapRealtor,
campusTreeInteraction,
fountainInteraction,
signLeftInteraction,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { interactionHandler } from '../handler.interactions';
import { displayDialogue } from '../../utils';

export const behindDeskClerkInteraction = (player, k) => {
interactionHandler(player, 'behind_desk', k, async () => {
displayDialogue({
k,
player,
text: [
"Uhh... You aren't supposed to be behind here",
'Get out dude',
],
});
});
};
14 changes: 14 additions & 0 deletions src/interactions/map_realtor/boxesInteraction.interactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { interactionHandler } from '../handler.interactions';
import { displayDialogue } from '../../utils';

export const boxesInteraction = (player, k) => {
interactionHandler(player, 'boxes', k, async () => {
displayDialogue({
k,
player,
text: [
'Bunch of boxes here... nothing to see (Just an Xbox One laying in the corner hehehe)',
],
});
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { interactionHandler } from '../handler.interactions';
import { displayDialogue } from '../../utils';

export const computerOneInteraction = (player, k) => {
interactionHandler(player, 'computer_1', k, async () => {
displayDialogue({
k,
player,
text: [
'You currently see nothing that you understand what so ever on this computer',
'It looks like so techy that you question your life choices',
],
});
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { interactionHandler } from '../handler.interactions';
import { displayDialogue } from '../../utils';

export const computerTwoInteraction = (player, k) => {
interactionHandler(player, 'computer_2', k, async () => {
displayDialogue({
k,
player,
text: [
'You see "Hello, world!" printed on the screen in C++',
"You think to yourself, wasn't the other screen way more complex?",
"What's going on here?",
],
});
});
};
135 changes: 135 additions & 0 deletions src/interactions/map_realtor/counterClerkInteraction.interactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { interactionHandler } from '../handler.interactions';
import { displayDialogue, displayPermissionBox } from '../../utils';
import {
completeQuest,
completeQuestObjective,
recieveQuest,
} from '../../utils/questHandler';
import { map_realtor } from '../quests/constants.quests';

export const counterClerkInteraction = (player, k) => {
interactionHandler(player, 'counter_clerk', k, async () => {
await displayDialogue({
k,
player,
characterName: 'Realtor Clerk',
text: [
'Hello, we are a firm that gives out houses to residents attending Zero To Mastery.',
'Would you like to purchase a house?',
],
});
recieveQuest(player, map_realtor['Buy a house!']);
completeQuestObjective(
player,
'Buy a house!',
'hasTalkedToRealtorClerk'
);
const answer = await displayPermissionBox({ k, player, text: [''] });
if (answer) {
showCustomPrompt(
'Which house would you like to buy?',
['Orange House', 'Red House', "Neither, I've changed my mind"],
(selectedOption) => {
if (!selectedOption.split(' ').includes('House')) {
displayDialogue({
k,
player,
characterName: 'Realtor Clerk',
text: [
"Okay, well let me know if you change your mind and we'll see if we can set you up!",
],
});
return;
}
if (player.state.coinsCollected >= 100) {
displayDialogue({
k,
player,
characterName: 'Realtor Clerk',
text: [
'Congratulations!',
`You now own the ${selectedOption}!`,
],
onDisplayEnd: () => {
completeQuestObjective(
player,
'Buy a house!',
'hasBoughtHouse'
);
completeQuest(player, 'Buy a house!');
},
});
} else {
displayDialogue({
k,
player,
characterName: 'Realtor Clerk',
text: [
"Oooooof, I'm sorry.",
"It looks like you don't have enough coins for the house...",
],
});
}
}
);
} else {
await displayDialogue({
k,
player,
characterName: 'Realtor Clerk',
text: [
"Okay, well let me know if you change your mind and we'll see if we can set you up!",
],
});
}
});
};

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

// Clear any existing options in the container
const optionsContainer = document.getElementById('options-container');
optionsContainer.innerHTML = '';

// Create buttons for each option
options.forEach((option) => {
const button = document.createElement('button');
button.textContent = option;
button.classList.add('option-btn');
button.setAttribute('tabindex', '0'); // Make the button focusable

// Add click event for mouse interactions
button.onclick = function () {
callback(option);
closeCustomPrompt();
};

// Add keyboard event listener for accessibility
button.addEventListener('keydown', function (e) {
if (e.key === 'Enter' || e.key === ' ') {
// Enter or Space key
e.preventDefault(); // Prevent the default behavior (e.g., form submission)
callback(option);
closeCustomPrompt();
}
});

optionsContainer.appendChild(button);
});

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

// Set focus on the first button
if (optionsContainer.children.length > 0) {
optionsContainer.children[0].focus();
}
}

// Function to close the custom prompt
function closeCustomPrompt() {
// Hide the custom prompt
document.getElementById('custom-prompt').style.display = 'none';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const enterMapExtendedCampus = (player, k) => {
player.onCollide('enter_map_extended_campus', () => {
k.go('extended_campus', 'spawn_realtor_office');
});
};
14 changes: 14 additions & 0 deletions src/interactions/map_realtor/fridgeInteraction.interactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { interactionHandler } from '../handler.interactions';
import { displayDialogue } from '../../utils';

export const fridgeInteraction = (player, k) => {
interactionHandler(player, 'fridge', k, async () => {
displayDialogue({
k,
player,
text: [
'No, you cannot go looking for food here, this is for employees only...',
],
});
});
};
19 changes: 19 additions & 0 deletions src/interactions/map_realtor/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { behindDeskClerkInteraction } from './behindDeskClerkInteraction.interactions';
import { boxesInteraction } from './boxesInteraction.interactions';
import { computerOneInteraction } from './computerOneInteraction.interactions';
import { computerTwoInteraction } from './computerTwoInteraction.interactions';
import { fridgeInteraction } from './fridgeInteraction.interactions';
import { counterClerkInteraction } from './counterClerkInteraction.interactions';
import { enterMapExtendedCampus } from './enterMapExtendedCampus.interactions';

const interactions = [
enterMapExtendedCampus,
behindDeskClerkInteraction,
boxesInteraction,
computerOneInteraction,
computerTwoInteraction,
counterClerkInteraction,
fridgeInteraction,
];

export default interactions;
11 changes: 11 additions & 0 deletions src/interactions/quests/constants.quests.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ export const map_start_quests = {
}
),
};

export const map_realtor = {
'Buy a house!': makeQuest(
'Buy a house!',
"Go to the realtor's office in the extended campus to buy a house!",
{
hasTalkedToRealtorClerk: false,
hasBoughtHouse: false,
}
),
};
4 changes: 3 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { loseScreen } from './scenes/gameMachine/lose';
import { classroom } from './scenes/classroom';
import { seaside } from './scenes/seaside';
import { downtown } from './scenes/downtown';
import { realtor } from './scenes/realtor';
import { extendedCampus } from './scenes/extended_campus';

k.scene('start', (enter_tag) => bootstrap(start, { enter_tag }));
Expand All @@ -35,10 +36,11 @@ k.scene('campus_house_1', (enter_tag) =>
k.scene('classroom', (enter_tag) => bootstrap(classroom, { enter_tag }));
k.scene('seaside', (enter_tag) => bootstrap(seaside, { enter_tag }));
k.scene('downtown', (enter_tag) => bootstrap(downtown, { enter_tag }));
k.scene('fishing', (enter_tag) => miniGameBootstrap(fishing, { enter_tag }));
k.scene('extended_campus', (enter_tag) =>
bootstrap(extendedCampus, { enter_tag })
);
k.scene('fishing', (enter_tag) => miniGameBootstrap(fishing, { enter_tag }));
k.scene('realtor', (enter_tag) => bootstrap(realtor, { enter_tag }));

// Game Machine Scenes
k.scene('startScreen', gameStartScreen);
Expand Down
22 changes: 22 additions & 0 deletions src/scenes/realtor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import gameObjects from '../gameObjects/map_realtor';
import { initMap } from '../init/map.init';
import interactions from '../interactions/map_realtor';

export async function realtor() {
const objectConfig = {
static: [
'map_boundaries',
'building_boundaries',
'enter_new_map_boundaries',
],
spawnpoints: ['spawnpoints'],
interactionObjects: ['interaction_objects'],
};
const [map, spawnpoint] = await initMap(
objectConfig,
'./exports/maps/map_realtor.png',
'./maps/map_realtor.json'
);

return [map, spawnpoint, gameObjects, interactions];
}

0 comments on commit e458bc2

Please sign in to comment.