-
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 (#149)
Part of #2
- Loading branch information
Showing
5 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,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; | ||
}; |