Pixi’VN

Navigation and map

How to define, organize, and navigate rooms, locations, and maps in Pixi’VN, including custom classes and usage examples.

Nomenclature

Usually in video games, navigation elements used to identify the position of characters are called room, location (e.g. restaurant, house, hospital, etc.), and map. For this reason, names that follow this logic are used.

This does not prevent you from using these elements to manage navigation with the same logic but with different terms. For example, in a game set in space where the player moves between planets, rooms can be the planets, locations can be the solar systems, and maps can be the galaxy.

The navigation system is composed of the following elements:

ElementDescription
roomsThe core elements of navigation, from which the position of the mc and npc is deduced.
locationsA container of rooms.
mapsA container of locations.

The player can move between rooms. The location and the map are also determined based on the room in which the player is located.

Initialize

To initialize a room/location/map, create a new instance of the RoomBaseModel / LocationBaseModel / MapBaseModel class (or your custom class) and add it to the game room/location/map dictionary when the game is initialized.

Custom classes

It is recommended to use custom classes to adapt rooms/locations/maps to your game as best as possible. The default templates already use custom classes.

RegisteredRooms.add / RegisteredLocations.add / RegisteredMaps.add is required to save the rooms/locations/maps in the game.

import { RegisteredRooms, RoomBaseModel } from "@drincs/nqtr";
import { mcHome } from "@/content/locations";

export const mcRoom = new RoomBaseModel("mc_room", mcHome, {
    name: "MC room",
    image: "location_myroom",
    activities: ["bed"],
});

export const aliceRoom = new RoomBaseModel("alice_room", mcHome, {
    name: "Alice room",
    image: "location_aliceroom",
    routine: ["alice_sleep"],
});

export const bathroom = new RoomBaseModel("bathroom", mcHome, {
    name: "Bathroom",
    image: "location_bathroom",
});

export const terrace = new RoomBaseModel("terrace", mcHome, {
    name: "Terrace",
    image: "location_terrace",
    routine: ["alice_smokes"],
});

RegisteredRooms.add(mcRoom, aliceRoom, bathroom, terrace);

It is also recommended to set the current room during the start of the game.

content/labels/start.label.ts
import { navigator } from "@drincs/nqtr";
import { newLabel } from "@drincs/pixi-vn";
import { mcRoom } from "@/content/rooms";

export const startLabel = newLabel("start", [
    async () => {
        navigator.currentRoom = mcRoom;
        // ... other initialization logic
    },
]);

Get

To get a room/location/map by its id, use the RegisteredRooms.get / RegisteredLocations.get / RegisteredMaps.get function.

import { RegisteredRooms } from "@drincs/nqtr";

const mcRoom = RegisteredRooms.get("mc_room");

Get all

To get all rooms/locations/maps, use the RegisteredRooms.values / RegisteredLocations.values / RegisteredMaps.values function.

import { RegisteredRooms } from "@drincs/nqtr";

const rooms = RegisteredRooms.values();

As explained above, the player can navigate between rooms, and the current room determines the current location and map.

To navigate to a room, set the navigator.currentRoom property to the desired room instance. This will automatically update the current location and map based on the room's location and map.

index.ts
import { navigator } from "@drincs/nqtr";
import { mcRoom } from "@/content/rooms";

navigator.currentRoom = mcRoom;

Other features

On this page