Skip to content

Commit

Permalink
added a chest_treasure to the game objects: map_start (#149)
Browse files Browse the repository at this point in the history
Part of #2
  • Loading branch information
r4pt0s authored Oct 14, 2024
2 parents 993b23b + c76f6bd commit 048d0c2
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
Binary file added public/assets/sounds/chest_opening.wav
Binary file not shown.
Binary file added public/assets/sprites/treasure_chest_closed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/sprites/treasure_chest_open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/gameObjects/map_start/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { misterFu } from './misterFu.gameObject';
import { jokeTellerNPC } from './jokeTellerNPC.gameObject';
import { tvVideo } from './tv_main_room_video.gameObject';
import { randNpcsOnRestroomSinkCounch } from './randNpcsOnRestroomSinkCounch.gameObject';
import { treasureChest } from './treasureChest.gameObject';

export const gameObjects = [
bruno,
Expand All @@ -21,6 +22,7 @@ export const gameObjects = [
randNpcsOnRestroomSinkCounch,
misterFu,
tvVideo,
treasureChest,
];

export default gameObjects;
50 changes: 50 additions & 0 deletions src/gameObjects/map_start/treasureChest.gameObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { scaleFactor } from '../../constants';

export const treasureChest = (k, map) => {
k.loadSprite(
'treasureChestClosed',
'./assets/sprites/treasure_chest_closed.png'
);
k.loadSprite(
'treasureChestOpen',
'./assets/sprites/treasure_chest_open.png'
);

k.loadSound('chestOpen', './assets/sounds/chest_opening.wav');

const chestPosition = { x: 200, y: 100 };

let isOpen = false;

const chestObj = k.make([
k.sprite('treasureChestClosed'),
k.area(),
k.pos(
map.pos.x + chestPosition.x / scaleFactor,
map.pos.y + chestPosition.y / scaleFactor
),
k.scale(0.5),
'treasureChest',
]);

chestObj.onCollide('player', () => {
if (!isOpen) {
isOpen = true;
k.play('chestOpen');

chestObj.use(k.sprite('treasureChestOpen'));
const msg = k.add([
k.text('ohh you found the secret treasure!', {
size: 15,
}),
k.pos(chestObj.pos.x, chestObj.pos.y + 20),
]);

k.wait(4, () => {
msg.destroy();
});
}
});

return chestObj;
};

0 comments on commit 048d0c2

Please sign in to comment.