Skip to content

Commit

Permalink
added a chest_treasure to the game objects: map_start
Browse files Browse the repository at this point in the history
  • Loading branch information
HossamGouda committed Oct 13, 2024
1 parent cca8cdb commit dd45ce7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
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;
};

0 comments on commit dd45ce7

Please sign in to comment.