hytopia
Version:
The HYTOPIA SDK makes it easy for developers to create massively multiplayer games using JavaScript or TypeScript.
32 lines (26 loc) • 878 B
text/typescript
import {
startServer,
PlayerEntity,
PlayerEvent,
} from 'hytopia';
import worldMap from './assets/map.json';
startServer(world => {
world.loadMap(worldMap);
// Spawn a player entity when a player joins the game.
world.on(PlayerEvent.JOINED_WORLD, ({ player }) => {
const playerEntity = new PlayerEntity({
player,
name: 'Player',
modelUri: 'models/players/player.gltf',
modelLoopedAnimations: [ 'idle' ],
modelScale: 0.5,
});
// Load our game UI for this player, this creates our mobile controls UI
player.ui.load('ui/index.html');
playerEntity.spawn(world, { x: 0, y: 10, z: 0 });
});
// Despawn all player entities when a player leaves the game.
world.on(PlayerEvent.LEFT_WORLD, ({ player }) => {
world.entityManager.getPlayerEntitiesByPlayer(player).forEach(entity => entity.despawn());
});
});