humus-old/server/create-server-room.js

310 lines
8.2 KiB
JavaScript
Raw Normal View History

2019-03-27 15:51:58 -05:00
import {World} from '@avocado/physics/matter/world';
import {Room} from '@avocado/topdown';
// A fire.
function fireJSON(position) {
return {
traits: {
collider: {
params: {
isSensor: true,
},
},
damaging: {
params: {
power: 70,
affinities: ['fire'],
},
},
existent: {},
visible: {},
physical: {},
pictured: {
params: {
images: {
initial: {
offset: [0, 0],
size: [16, 16], // Derive?
uri: '/fire.png',
},
}
},
},
positioned: {
state: {
x: position[0],
y: position[1],
},
},
shaped: {
params: {
shape: {
type: 'rectangle',
position: [0, 0],
size: [16, 16],
},
},
},
},
};
}
2019-03-27 15:51:58 -05:00
// A flower barrel.
function flowerBarrelJSON(position) {
return {
traits: {
2019-04-08 15:20:43 -05:00
collider: {},
existent: {},
2019-04-14 18:42:23 -05:00
visible: {},
2019-04-08 15:20:43 -05:00
physical: {},
2019-03-27 15:51:58 -05:00
pictured: {
params: {
images: {
initial: {
offset: [0, -8],
size: [32, 32], // Derive?
uri: '/flower-barrel.png',
},
}
},
},
2019-04-08 13:32:52 -05:00
positioned: {
state: {
x: position[0],
y: position[1],
},
},
shaped: {
2019-03-27 15:51:58 -05:00
params: {
shape: {
type: 'rectangle',
position: [0, 0],
size: [20, 10],
2019-04-08 13:32:52 -05:00
},
2019-03-27 15:51:58 -05:00
},
},
},
};
}
2019-04-08 21:23:00 -05:00
// A kitteh.
function kittyJSON(position) {
2019-04-09 09:43:51 -05:00
const buildRandom = (min, max, floor = true) => {
return {
type: 'traversal',
2019-04-15 22:30:35 -05:00
hash: 1,
2019-04-09 09:43:51 -05:00
steps: [
{
type: 'key',
key: 'global',
},
{
type: 'key',
key: 'randomNumber',
},
{
type: 'invoke',
args: [
{
type: 'literal',
value: min,
},
{
type: 'literal',
value: max,
},
{
type: 'literal',
value: floor,
},
],
},
],
};
}
2019-04-08 21:23:00 -05:00
return {
traits: {
animated: {
params: {
animations: {
idle: {
offset: [0, -3],
uri: '/kitty.animation.json',
},
}
},
},
2019-04-09 09:43:51 -05:00
behaved: {
params: {
routines: {
initial: {
actions: [
{
type: 'action',
2019-04-15 22:30:35 -05:00
hash: 2,
2019-04-09 09:43:51 -05:00
steps: [
{
type: 'key',
key: 'entity',
},
{
type: 'key',
key: 'moveFor',
},
{
type: 'invoke',
args: [
buildRandom(0.25, 1, false),
],
},
],
},
{
type: 'action',
2019-04-15 22:30:35 -05:00
hash: 3,
2019-04-09 09:43:51 -05:00
steps: [
{
type: 'key',
key: 'global',
},
{
type: 'key',
key: 'wait',
},
{
type: 'invoke',
args: [
buildRandom(1, 4),
],
},
],
},
{
type: 'action',
2019-04-15 22:30:35 -05:00
hash: 4,
2019-04-09 09:43:51 -05:00
steps: [
{
type: 'key',
key: 'entity',
},
{
type: 'key',
key: 'direction',
},
],
value: buildRandom(0, 3),
},
{
type: 'action',
2019-04-15 22:30:35 -05:00
hash: 5,
2019-04-09 09:43:51 -05:00
steps: [
{
type: 'key',
key: 'global',
},
{
type: 'key',
key: 'wait',
},
{
type: 'invoke',
args: [
buildRandom(0.5, 3),
],
},
],
},
],
},
},
},
},
2019-04-08 21:23:00 -05:00
collider: {},
directional: {
params: {
directionCount: 4,
},
state: {
direction: 2,
},
},
existent: {},
2019-04-14 18:42:23 -05:00
visible: {},
2019-04-08 21:23:00 -05:00
mobile: {
state: {
2019-04-09 09:43:51 -05:00
speed: 40,
2019-04-08 21:23:00 -05:00
},
},
physical: {},
positioned: {
state: {
x: position[0],
y: position[1],
},
},
shaped: {
params: {
shape: {
type: 'rectangle',
position: [0, 0],
size: [8, 4],
},
},
},
vulnerable: {},
2019-04-08 21:23:00 -05:00
},
};
}
2019-03-27 15:51:58 -05:00
// Room.
const roomJSON = {
2019-04-08 21:23:00 -05:00
size: [384, 384],
2019-03-27 17:16:09 -05:00
layers: {
everything: {
2019-03-27 15:51:58 -05:00
entities: [],
tiles: {
2019-04-08 21:23:00 -05:00
size: [24, 24],
2019-03-27 15:51:58 -05:00
data: [
2019-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 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1 , 2 , 3 , 4 , 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1 , 2 , 3 , 4 , 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1 , 2 , 3 , 4 , 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1 , 2 , 3 , 4 , 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1 , 2 , 3 , 4 , 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1 , 2 , 3 , 4 , 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1 , 2 , 3 , 4 , 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1 , 2 , 3 , 4 , 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1 , 2 , 3 , 4 , 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1 , 2 , 3 , 4 , 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1 , 2 , 3 , 4 , 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
2019-03-27 15:51:58 -05:00
],
},
tilesetUri: '/tileset.json',
2019-03-27 15:51:58 -05:00
},
2019-03-27 17:16:09 -05:00
},
2019-03-27 15:51:58 -05:00
};
roomJSON.layers.everything.entities.push(fireJSON([200, 200]));
2019-04-08 21:23:00 -05:00
for (let i = 0; i < 4; ++i) {
2019-04-09 15:59:26 -05:00
const x = Math.floor(Math.random() * 284) + 50;
const y = Math.floor(Math.random() * 284) + 50;
roomJSON.layers.everything.entities.push(flowerBarrelJSON([x * 4, y * 4]));
2019-03-27 15:51:58 -05:00
}
2019-04-09 09:55:34 -05:00
for (let i = 0; i < 40; ++i) {
2019-04-09 15:59:26 -05:00
const x = Math.floor(Math.random() * 284) + 50;
const y = Math.floor(Math.random() * 284) + 50;
roomJSON.layers.everything.entities.push(kittyJSON([x * 4, y * 4]));
2019-04-08 21:23:00 -05:00
}
2019-03-27 15:51:58 -05:00
export function createRoom() {
2019-03-27 16:11:49 -05:00
const room = (new Room()).fromJSON(roomJSON);
2019-03-27 15:51:58 -05:00
room.world = new World();
2019-03-27 16:11:49 -05:00
return room;
2019-03-27 15:51:58 -05:00
}