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

367 lines
9.6 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: {
audible: {
params: {
sounds: {
fire: {
src: '/fire.wav',
volume: 0.05,
},
}
}
},
collider: {
params: {
isSensor: true,
},
},
damaging: {
params: {
damagingSound: 'fire',
2019-04-19 12:16:28 -05:00
damageSpecs: [
{
affinity: 'fire',
lock: 0.15,
power: 5,
variance: 0.25,
},
],
},
},
existent: {},
2019-04-19 19:39:24 -05:00
visible: {
state: {
zIndex: -1,
},
},
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-20 22:37:59 -05:00
alive: {
state: {
maxLife: 1000,
life: 1000,
},
},
2019-04-08 15:20:43 -05:00
collider: {},
2019-04-20 22:37:59 -05:00
emitter: {},
2019-04-08 15:20:43 -05:00
existent: {},
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-20 22:37:59 -05:00
visible: {},
vulnerable: {},
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: {
2019-04-19 14:51:05 -05:00
alive: {},
2019-04-08 21:23:00 -05:00
animated: {
params: {
animations: {
idle: {
2019-04-20 22:37:59 -05:00
offset: [0, -6],
2019-04-08 21:23:00 -05:00
uri: '/kitty.animation.json',
},
}
},
},
audible: {
params: {
sounds: {
deathSound: {
src: '/ded.wav',
volume: 0.1,
},
}
}
},
2019-04-09 09:43:51 -05:00
behaved: {
params: {
routines: {
2019-04-19 15:40:14 -05:00
type: 'routines',
routines: {
initial: {
type: 'routine',
routine: {
type: 'actions',
traversals: [
2019-04-09 09:43:51 -05:00
{
2019-04-19 15:40:14 -05:00
type: 'action',
hash: 2,
steps: [
{
type: 'key',
key: 'entity',
},
{
type: 'key',
key: 'moveFor',
},
{
type: 'invoke',
args: [
buildRandom(0.25, 1, false),
],
},
2019-04-09 09:43:51 -05:00
],
},
{
2019-04-19 15:40:14 -05:00
type: 'action',
hash: 3,
steps: [
{
type: 'key',
key: 'global',
},
{
type: 'key',
key: 'wait',
},
{
type: 'invoke',
args: [
buildRandom(1, 4),
],
},
2019-04-09 09:43:51 -05:00
],
},
{
2019-04-19 15:40:14 -05:00
type: 'action',
hash: 4,
steps: [
{
type: 'key',
key: 'entity',
},
{
type: 'key',
key: 'direction',
},
],
value: buildRandom(0, 3),
2019-04-09 09:43:51 -05:00
},
{
2019-04-19 15:40:14 -05:00
type: 'action',
hash: 5,
steps: [
{
type: 'key',
key: 'global',
},
{
type: 'key',
key: 'wait',
},
{
type: 'invoke',
args: [
buildRandom(0.5, 3),
],
},
2019-04-09 09:43:51 -05:00
],
},
],
2019-04-19 15:40:14 -05:00
}
},
2019-04-09 09:43:51 -05:00
},
},
},
},
2019-04-08 21:23:00 -05:00
collider: {},
directional: {
params: {
directionCount: 4,
},
state: {
direction: 2,
},
},
emitter: {},
2019-04-08 21:23:00 -05:00
existent: {},
2019-04-20 22:37:59 -05:00
visible: {
state: {
visibleScale: [1.5, 1.5],
}
},
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],
2019-04-20 22:37:59 -05:00
size: [12, 6],
2019-04-08 21:23:00 -05:00
},
},
},
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-04-12 20:16:58 -05:00
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, 5 , 6 , 7 , 8 , 1, 2, 3, 4, 1, 2, 3, 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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,
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
};
2019-04-20 22:37:59 -05:00
for (let i = 0; i < 20; ++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-20 22:37:59 -05:00
for (let i = 0; i < 50; ++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-04-20 22:37:59 -05:00
for (let i = 0; i < 15; ++i) {
const x = Math.floor(Math.random() * 284) + 50;
const y = Math.floor(Math.random() * 284) + 50;
roomJSON.layers.everything.entities.push(fireJSON([x * 4, y * 4]));
}
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
}