Day 2: Week Sauce (March 2023) 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:

  • Making an inventory class and keeping track of items. 
  • Picking up items and placing them in the inventory.  
  • Displaying the picked up items in the UI. 

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:

  • I had to add physics to the player (which is a sprite) in order for it to be collide-able with the pickup items:
initPlayer () {
    ...
    this.physics.add.existing(player); // this right here!
    this.add.existing(player);
    ...
}
  • I made a sprite that had the same position and size of the pickup item, and made that sprite be what collides with the 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);
  • I used Phaser's overlap method to check if the player and the hit object ever overlap, and if so, add the pickup item to the inventory:
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:

  1. When you click on the pickup item, and the player walks to it, once the player reaches the item, a dialog will pop up instead.
  2. The dialog will describe the pickup item. And then, it will ask, "Pick up?" And you can choose "Yes" or "No."
  3. If Yes, then the pickup item gets added to your inventory!
  4. If No, then maybe some message in the dialog that says something to the effect of, "Nah... I don't want it right now."

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!

Comments

Log in with itch.io to leave a comment.

(+1)

Looking very great!! I like the inventory system!! Good luck working on the game:D

(+1)

Thanks so much. Your game is looking awesome as well :-)

(+1)

You’re more than welcome!! Thanks!! I really appreciate it a lot!! I’m very glad to hear that :D