Skip to content
Mathieu edited this page Jun 30, 2022 · 14 revisions

This page is meant to guide you through the creation of a basic item.

Draw a sprite

See How to create a sprite.

Add it to the game

There are several steps in order to include the item in the game.

Define the entity and the kind of item

shared/js/gametypes.js holds the taxonomy of entities in the game.

First of all you need to provide an ID for the type of entity: in variable Types.Entities, you have to define the entity you will use and associate an integer constant to it (see gametype.js l.61).

Then, the variable kinds will make the link between your sprite and the entity. It also holds the different types of objects ("player", "mob", "weapon", "armor", "object", "npc"), add your item to the kinds. e.g.: rosettastone: [Types.Entities.ROSETTASTONE, "object"],

NB: This is where you associate the name of the sprite with the code. In this file the method used to enforce the 'item-'+name pattern is defined (cf. client/js/item.js).

You can further describe your object by adding it to the list of expandable items for instance:

Types.isExpendableItem = function(kind) {
    return Types.isHealingItem(kind)
        || kind === Types.Entities.FIREPOTION
        || kind === Types.Entities.CAKE
        || kind === Types.Entities.ROSETTASTONE;
};

This is the file that processes the list of entities of the map and decides associates them to a given kind.

In the items section of the file, add your entity. E.g.:

    EntityFactory.builders[Types.Entities.ROSETTASTONE] = function(id){
		return new Items.RosettaStone(id);
	}

This associate to the entity «Types.Entities.ROSETTASTONE» a builder

Define the item's behavior

This is done in client/js/items.js.

There are different kinds of items:

  • "weapon" → changes the user's weapon upon loot;
  • "armor" → changes the user's armor upon loot;
  • "object" → other (see shared/js/gametypes.js for subtypes of other objects).

The init() behavior, containing a constructor and the loot message has to be defined, but the behavior upon loot can also be specified.

###Effectively add the item to the game In client/js/game.js, add your sprite to this.spriteNames. In the examples above our spritename is item-rosettastone.

In this file, you can also associate an achievement to the item or add a silhouette to it.