Posted March 10, 2023 by Melky
#point and click #phaser #javascript #html5 #adventure #game jam
I'm back at it again! The great thing about this #weeksauce game jam is that we have the whole month of March to do 7 days of game dev. It's perfect for those of us with busy lives T_T
On day 2, I focused on inventory! Namely:
A question I got asked was "How did you do collisions in Phaser?" Here is what I did, although there are many ways to do it:
initPlayer () {
...
this.physics.add.existing(player); // this right here!
this.add.existing(player);
...
}
const hitObj = this.physics.add.sprite(pickup.x, pickup.y, null, null).setVisible(false).setActive(true).setOrigin(0, 0);
hitObj.body.setOffset(10, 10);
hitObj.body.width = pickup.width;
hitObj.body.height = pickup.height;
hitObj.body.setBounce(0).setImmovable(true);
this.physics.add.overlap(player, hitObj, (player, hitObj) => {
hitObj.destroy();
pickup.setVisible(false);
inventory.addItem(pickupName);
}, null, this);
However, as this is a point-and-click game, I'm going to have to make some changes on how pickups are handled! So you can expect this in the upcoming updates:
Nonetheless, doing collisions was a great way to test out the inventory. At least we know that pickups can be added to the inventory, and displayed properly in the UI.
To view the source code, check out: https://github.com/melkypop/phaser3-pnc-template
By the way, super cute artwork by @florassence at https://florassence.itch.io/tiny-pixel-shop!