75 lines
1.5 KiB
JavaScript
75 lines
1.5 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: {
|
|
state: {
|
|
name: socket.socket.id,
|
|
},
|
|
},
|
|
followed: {},
|
|
informed: {},
|
|
layered: {},
|
|
listed: {},
|
|
mobile: {
|
|
state: {
|
|
speed: 100,
|
|
},
|
|
},
|
|
physical: {},
|
|
positioned: {
|
|
state: {
|
|
x: x * 4,
|
|
y: y * 4,
|
|
},
|
|
},
|
|
roomed: {},
|
|
shaped: {
|
|
params: {
|
|
shape: {
|
|
type: 'circle',
|
|
radius: 4,
|
|
},
|
|
},
|
|
},
|
|
visible: {},
|
|
vulnerable: {},
|
|
},
|
|
});
|
|
// Embed socket.
|
|
entity.socket = socket;
|
|
return entity;
|
|
}
|