Characters & NPCs

A character is one definition used everywhere: name and portraits in scenes, a sprite on the map, stats in the party, relationship points.

Defining a character

// src/content/characters/jack/index.ts
import { defineCharacter } from '@/core/define'
import { fromAseprite } from '@/core/portrait/aseprite'
import jack from './portraits/jack.gen'
import sprite from './sprites/jack.gen'
import battleSprite from './battle_sprite/jack.gen'

export default defineCharacter({
  name: 'Jack',
  color: '#90caf9',                // name plate colour (and placeholder portrait)
  blip: 'sfx/blip',                // short typing sound for lines without a voice clip
  // faceArea: { x, y, w, h },    // optional: where the face is (side image, Voices tiles); see art.html#face-box
  sprite,                          // map sprite (Aseprite with tags)
  battleSprite,                    // in battle (./battle_sprite/jack.gen); default: the map sprite
  layered: fromAseprite(jack, {    // portraits; or portraits: { neutral: url, happy: url }
    defaults: { eyes: 'open', mouth: 'smile' },
    expressions: { neutral: {}, happy: { eyes: 'happy', mouth: 'open' } },
    blink: { layer: 'eyes', closed: 'closed' },
    talk: { layer: 'mouth', open: 'open' },
  }),
  relationship: { start: 0, min: -50, max: 100 },    // optional
  battle: {                                          // optional: can join the party
    base: { hp: 30, attack: 5, magic: 6 }, growth: { hp: 5, attack: 1 },
    skills: ['heal', { skill: 'fire', level: 3 }],      // from the start, or from a level / a finished quest
    // elements: { fire: 0.5 }, immune: ['sleep'],     // what hurts them less, statuses that never stick
  },
})
FieldMore
name, colorShown on the name plate (translated)
portraits or layeredPortraits in scenes; the keys are the poses (typed). Neither = a coloured placeholder.Art
spriteThe map spriteArt
battleSpriteDrawn in battle (else the map sprite)Battles
blipTyping soundAudio
relationshipStart value and limits of their pointsbelow
battleStats, skills (also by level or quest), element rates and immunities as a party memberParty, skills
Character files load up front: don't import game in them.

Putting them on a map

Give a map object character. In Tiled, name the object (e.g. jack) and give it behaviour in the map's objects:

objects: {
  jack: {
    character: 'jack',
    facing: 'left',
    animation: 'idle',          // start animation
    speed: 3,                   // tiles per second for scripted walks
    turnToPlayer: true,         // look at the player while talking (default)
    onInteract: ({ game }) => game.events.start('jack/hello'),
  },
}

Scripting NPCs

const jack = game.maps.npc('jack')      // in map hooks: world.npc('jack')

await jack.walk({ up: 2 }, { right: 3, speed: 6 }, { down: 1 })   // tiles; speed per step
await jack.walkTo({ x: 10, y: 4 })      // around walls; false if it can't get there
await jack.play('wave')                  // any animation tag (typed for characters)
await jack.play('wave', { times: 2, facing: 'player' })
await jack.play('open', { hold: true })  // stay on the last frame
jack.idle(); jack.idle('sleep')          // back to idle / make 'sleep' the new idle
jack.face('left'); jack.face('player')
jack.teleport({ x: 3, y: 3 }, 'down')
jack.speed = 4
jack.hide(); jack.show(); jack.hidden    // hidden = not drawn, no collision, can't be talked to
jack.exists; jack.x; jack.y; jack.facing
void jack.bark('Over here!')             // speech bubble (below)

The player and the camera

await game.maps.player.walk({ left: 2 })        // player input is paused meanwhile
await game.maps.player.walkTo({ x: 5, y: 9 })
game.maps.player.face('up')
await game.maps.player.bark('Hmm…')

await game.maps.camera.follow('jack')           // follow an NPC
await game.maps.camera.panTo({ x: 12, y: 6 })   // look at a tile
await game.maps.camera.reset()                  // back to the player (default 600 ms each)

Walking there in a script doesn't fire onEnter of objects on the way.

Speech bubbles

void jack.bark('Nice weather today.')
await game.maps.player.bark('Hmm…', { duration: 2000 })   // resolves when it disappears

Emote balloons

await world.npc('jack').emote('surprise')                 // resolves when it is gone
await world.player.emote('question', { duration: 2000 })
game.maps.player.emote('love')                             // from anywhere

// src/content/emotes.ts — add a line and its name works (and autocompletes)
list: { surprise: { text: '!', color: '#d32f2f' }, sleep: 'z Z', /* … */ },

Included: surprise, question, love, anger, sweat, idea, music, sleep, dots, happy. Size, how long they stay and the balloon colours are in the same file.

Schedules

Where an NPC is by time of day, per map:

jack: {
  character: 'jack',
  schedule: [
    { from: '8', at: { x: 14, y: 9 }, facing: 'left' },
    { from: '12:30', at: { x: 9, y: 11 }, facing: 'down', animation: 'idle' },
    { from: '17', at: { x: 14, y: 9 }, walk: false },          // jumps instead of walking
    { from: '21:30', at: { x: 31, y: 10 }, hidden: true },     // walks off, then is gone
  ],
}

Names that change

A character can start hidden and change name during the story. Set unknownName and the game shows it until it is revealed:

// characters/god/index.ts
export default defineCharacter({ name: 'God', unknownName: '???' })

// in an event (from its context): any text as a fake name, changed as often as you like
rename('god', 'Stranger')
// the real name, from now on
reveal('god')

// anywhere else
game.characters.rename('god', 'Evil God'); game.characters.reveal('god')
game.characters.name('god')        // what is shown now (translated)
game.characters.known('god')       // false while the name is still hidden
game.characters.forget('god')      // back to the start
const name = useCharacterName('god')   // React, from '@/core/managers/characters'

Relationships

Points per character: how much they like the player.

game.relationships.get('anna')                          // the character's start value at first
game.relationships.change('anna', 5, { notify: true })  // toast "♥ Anna +5"; returns the new value
game.relationships.set('anna', 20)
game.relationships.all()                                // { anna: 20, jack: 0, … }
const points = useRelationship('anna')                  // React, from '@/core/managers/relationships'

Saved with the game and kept within the character's min…max (default −100…100). Use them in scenes, e.g. a choice that is disabled until Anna likes you enough. In .vn scripts: love anna +3 and if love('anna') >= 10:.