humus-old/server/create-entity-for-connection.js
2019-05-04 11:39:43 -05:00

68 lines
1.3 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;
const entity = new Entity({
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: {},
controllable: {},
directional: {
params: {
directionCount: 4,
},
},
emitter: {},
existent: {},
followed: {},
informed: {},
mobile: {
state: {
speed: 100,
},
},
physical: {},
positioned: {
state: {
x: x * 4,
y: y * 4,
},
},
shaped: {
params: {
shape: {
type: 'circle',
radius: 4,
},
},
},
visible: {},
vulnerable: {},
},
});
// Embed socket.
entity.socket = socket;
return entity;
}