Inventory Items and prototypal inheritance in Javascript

18 January 2015

Having a bunch of items in Polo’s House game inventory, requires a lot of typing and the majority of the items are quite similar. For example an apple, a pear, other fruits, share most of the same features.

For instance, we can define an apple item in JSON (which can be converted to a JS object with ease using JSON.parse()) like this:

      "type"       : "food",
      "name"       : "apple",
      "display"    : "apple",
      "description": "shiny red apple",
      "image"      : "apple.png",

      "..."        : ".. other stuff excluded for simplicity ...",

      "activity"   : "Eat",
      "animation"  : {
        "names": "..."

Wouldn’t be great if we can reuse the definition of the apple in other fruit? Well, this is Javascript, we can take advantage of the prototypal inheritance.

Read more

Polo's House

19 April 2014

This is the name of the virtual pet game in development now, this is an alpha version screenshot of Polo eating.

You can see the Life status icons (Energy, Health, Hunger, Fun). In the left, you see the inventory menu, where some cheese is dragged to feed Polo. Stay tuned, I will keep posting updates .