Skip to content

Commit

Permalink
add: welcome ztm npc interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangnv170752 committed Oct 31, 2024
1 parent 2638604 commit 26cb885
Show file tree
Hide file tree
Showing 6 changed files with 1,814 additions and 0 deletions.
Binary file added public/assets/sprites/akashi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions src/gameObjects/map_start/akashi.gameObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { scaleFactor } from '../../constants';

export const akashi = (k, map, spawnpoints) => {
k.loadSprite('akashi', './assets/sprites/akashi.png', {
sliceX: 9,
sliceY: 1,
anims: {
'idle-down': 0,
'walk-down': { from: 3, to: 4, loop: true, speed: 4 },
'idle-side': 2,
'walk-side': { from: 7, to: 8, loop: true, speed: 4 },
'idle-up': 1,
'walk-up': { from: 5, to: 6, loop: true, speed: 4 },
},
});

const spawnX = spawnpoints.bruno.x / scaleFactor;
const spawnY = spawnpoints.bruno.y / scaleFactor;

const oppositeX = map.width - spawnX;
const oppositeY = map.height - spawnY;

const akashiObj = k.make([
k.sprite('akashi', { anim: 'idle-down' }),
k.area({
shape: new k.Rect(k.vec2(0), 16, 16),
}),
k.body({ isStatic: true }),
k.anchor('center'),
k.pos(spawnX, spawnY),
k.scale(1.1),
k.offscreen({ hide: true, distance: 10 }),
'akashi',
]);

akashiObj.moveTo(k.vec2(oppositeX, oppositeY), 50);

return akashiObj;
};
2 changes: 2 additions & 0 deletions src/gameObjects/map_start/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { jokeTellerNPC } from './jokeTellerNPC.gameObject';
import { tvVideo } from './tv_main_room_video.gameObject';
import { randNpcsOnRestroomSinkCounch } from './randNpcsOnRestroomSinkCounch.gameObject';
import { treasureChest } from './treasureChest.gameObject';
import { akashi } from './akashi.gameObject';

export const gameObjects = [
bruno,
Expand All @@ -25,6 +26,7 @@ export const gameObjects = [
tvVideo,
treasureChest,
cat,
akashi
];

export default gameObjects;
41 changes: 41 additions & 0 deletions src/interactions/map_start/akashi.interaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { speedByScaleFactor } from '../../constants';
import { displayDialogue } from '../../utils';

const akashiDialogue = [
`
<div>
<h2>Welcome to ZTM Hacktoberfest!</h2>
<p>
You've arrived at the perfect place to start contributing to open-source projects.
</p>
<p>
Hacktoberfest is a month-long celebration of open-source, and it's a great chance to sharpen your skills, connect with other developers, and make a real impact.
</p>
<p>
Let's get coding and make some meaningful contributions together!
</p>
</div>
`,
];

export const interactionWithAkashi = (player, k, map) => {
player.onCollide('akashi', () => {
player.state.speed = speedByScaleFactor * 2.5;
displayDialogue({
k,
player,
text: akashiDialogue,
});
});

player.onCollideEnd('akashi', () => {
setTimeout(() => {
player.state.speed = speedByScaleFactor;
displayDialogue({
k,
player,
text: ['Meeting elders'],
});
}, 10000);
});
};
2 changes: 2 additions & 0 deletions src/interactions/map_start/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { interactionWithTV } from './tv_main_room.interaction';
import { interactionWithCake } from './cake.interaction';
import { interactionWithLocker } from './locker.interaction';
import { interactionWithCat } from './cat.interaction';
import { interactionWithAkashi } from './akashi.interaction';

const interactions = [
restroomInteractions,
Expand All @@ -28,6 +29,7 @@ const interactions = [
interactionWithCake,
interactionWithLocker,
interactionWithCat,
interactionWithAkashi
];

export default interactions;
Loading

0 comments on commit 26cb885

Please sign in to comment.