68 lines
1.4 KiB
JavaScript
68 lines
1.4 KiB
JavaScript
import {Entity} from '@avocado/entity';
|
|
// Create an entity for a new connection.
|
|
export function createEntityForConnection(socket) {
|
|
let entity = new Entity();
|
|
const x = Math.floor(Math.random() * 284) + 50;
|
|
const y = Math.floor(Math.random() * 284) + 50;
|
|
entity = entity.fromJSON({
|
|
traits: {
|
|
alive: {
|
|
state: {
|
|
life: 100,
|
|
maxLife: 100,
|
|
},
|
|
},
|
|
animated: {
|
|
params: {
|
|
animations: {
|
|
idle: {
|
|
offset: [0, -12],
|
|
uri: '/idle.animation.json',
|
|
},
|
|
moving: {
|
|
offset: [0, -12],
|
|
uri: '/moving.animation.json',
|
|
},
|
|
}
|
|
},
|
|
},
|
|
collider: {},
|
|
directional: {
|
|
params: {
|
|
directionCount: 4,
|
|
},
|
|
},
|
|
emitter: {},
|
|
existent: {},
|
|
followed: {},
|
|
visible: {},
|
|
mobile: {
|
|
state: {
|
|
speed: 100,
|
|
},
|
|
},
|
|
physical: {},
|
|
positioned: {
|
|
state: {
|
|
x: x * 4,
|
|
y: y * 4,
|
|
},
|
|
},
|
|
shaped: {
|
|
params: {
|
|
shape: {
|
|
type: 'circle',
|
|
radius: 4,
|
|
},
|
|
},
|
|
},
|
|
vulnerable: {},
|
|
},
|
|
});
|
|
entity.addTrait('controllable');
|
|
entity.addTrait('informed');
|
|
// Embed socket.
|
|
entity.socket = socket;
|
|
return entity;
|
|
}
|