-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a chest_treasure to the game objects: map_start
- Loading branch information
1 parent
cca8cdb
commit dd45ce7
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |