forked from mozilla/BrowserQuest
-
Notifications
You must be signed in to change notification settings - Fork 219
How to add a non playing character
lulalala edited this page Mar 29, 2020
·
3 revisions
Like for adding an item start by drawing your sprite. As an example, we'll add a character called librarian.
The link between the entity and the sprite is to be defined in shared/js/gametypes.js.
Assign a constant to the entity (in variable Types.Entities
— attribute Entities
of the variable Types
—: LIBRARIAN: 58
) and then make the link, by creating a kind (in variable kinds
, add epigraphist: [Types.Entities.LIBRARIAN, "npc"]
).
Edit Npc with the sentences your character is supposed to say to the user.
In client/js/npcs.js, create a class for your npc. E.g.:
Librarian: Npc.extend({
init: function(id) {
this._super(id,Types.Entities.LIBRARIAN,1);
}
}),`
Associate the constructor of the class that was just created, to the entity ID it corresponds to:
EntityFactory.builders[Types.Entities.LIBRARIAN] = function(id){
return new NPCs.Librarian(id);
};
Add it to the spriteNames array.