Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a chest_treasure to the game objects: map_start #149

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added public/assets/sprites/treasure_chest.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;
33 changes: 33 additions & 0 deletions src/gameObjects/map_start/treasureChest.gameObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// src/gameObjects/map_start/treasureChest.gameObject.js
import { scaleFactor } from '../../constants';

export const treasureChest = (k, map, spawnpoints) => {
// Load the sprite for the treasure chest
k.loadSprite('treasureChest', './assets/sprites/treasure_chest.png', {
sliceX: 1,
sliceY: 1,
anims: {
idle: 0,
},
});

// Create the treasure chest object
const chestObj = k.make([
k.sprite('treasureChest', { anim: 'idle' }),
k.area({
shape: new k.Rect(k.vec2(0), 32, 32), // Adjust dimensions
}),
k.body({ isStatic: true }), // Set to static if it shouldn’t move
k.anchor('center'),
// make sure to define it in Tiled
k.pos(
spawnpoints.treasureChest.x / scaleFactor,
spawnpoints.treasureChest.y / scaleFactor
),
k.scale(1.0), // Adjust scale if necessary
k.offscreen({ hide: false, distance: 10 }), // Optional
'treasureChest', // Tag for identifying this object type
]);

return chestObj;
};