feat: genned and loaded entities

This commit is contained in:
cha0s 2019-05-16 23:02:25 -05:00
parent e06b3d5089
commit b7cd05732d
9 changed files with 70 additions and 4 deletions

View File

@ -0,0 +1 @@
{"traits": {"existent": {"state": {"isTicking": false, "name": "Base"}}}}

View File

@ -0,0 +1 @@
{"traits":{"animated":{"params":{"animations":{"idle":{"jitter":0.1,"offset":[0,0],"uri":"/blue-fire.animation.json"}}}},"audible":{"params":{"sounds":{"fire":{"uri":"/blue-fire.sound.json"}}}},"collider":{"params":{"isSensor":true}},"damaging":{"params":{"damagingSound":"fire","damageSpecs":[{"affinity":1,"lock":0.45,"power":-15,"variance":0.25}]}},"darkened":{"params":{"isDarkened":false}},"existent":{"state":{"name":"Blue fire"}},"layered":{},"listed":{},"physical":{},"positioned":{"state":{"x":0,"y":0}},"roomed":{},"shaped":{"params":{"shape":{"type":"rectangle","position":[0,0],"size":[16,16]}}},"visible":{"params":{"filter":"bloom"}}}}

View File

@ -0,0 +1 @@
{"base": "/base-test.entity.json", "traits": {"existent": {"state": {"name": "Extension"}}}}

View File

@ -0,0 +1 @@
{"traits":{"animated":{"params":{"animations":{"idle":{"jitter":0.1,"offset":[0,0],"uri":"/fire.animation.json"}}}},"audible":{"params":{"sounds":{"fire":{"uri":"/fire.sound.json"}}}},"collider":{"params":{"isSensor":true}},"damaging":{"params":{"damagingSound":"fire","damageSpecs":[{"affinity":1,"lock":0.45,"power":15,"variance":0.25}]}},"darkened":{"params":{"isDarkened":false}},"existent":{"state":{"name":"Fire"}},"layered":{},"listed":{},"physical":{},"positioned":{"state":{"x":0,"y":0}},"roomed":{},"shaped":{"params":{"shape":{"type":"rectangle","position":[0,0],"size":[16,16]}}},"visible":{"params":{"filter":"bloom"}}}}

View File

@ -0,0 +1 @@
{"traits":{"alive":{"state":{"maxLife":1000,"life":1000}},"collider":{},"emitter":{},"existent":{"state":{"name":"Flower Barrel"}},"layered":{},"listed":{},"physical":{},"pictured":{"params":{"images":{"initial":{"offset":[0,-8],"size":[32,32],"uri":"/flower-barrel.png"}}}},"positioned":{"state":{"x":0,"y":0}},"roomed":{},"shaped":{"params":{"shape":{"type":"rectangle","position":[0,0],"size":[20,10]}}},"visible":{},"vulnerable":{}}}

View File

@ -0,0 +1 @@
{"traits":{"alive":{},"animated":{"params":{"animations":{"idle":{"offset":[0,-3],"uri":"/kitty.animation.json"}}}},"audible":{"params":{"sounds":{"deathSound":{"uri":"/ded.sound.json"}}}},"behaved":{"params":{"routines":{"type":"routines","routines":{"initial":{"type":"routine","routine":{"type":"actions","traversals":[{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"moveFor"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":0.25},{"type":"literal","value":2.5},{"type":"literal","value":false}]}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"isAnimating"}],"value":{"type":"literal","value":false}},{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"wait"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":1},{"type":"literal","value":4},{"type":"literal","value":false}]}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"direction"}],"value":{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":0},{"type":"literal","value":3}]}]}},{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"wait"},{"type":"invoke","args":[{"type":"traversal","steps":[{"type":"key","key":"global"},{"type":"key","key":"randomNumber"},{"type":"invoke","args":[{"type":"literal","value":0.5},{"type":"literal","value":3},{"type":"literal","value":false}]}]}]}]},{"type":"traversal","steps":[{"type":"key","key":"entity"},{"type":"key","key":"isAnimating"}],"value":{"type":"literal","value":true}}]}}}}}},"collider":{},"directional":{"params":{"directionCount":4},"state":{"direction":2}},"emitter":{},"existent":{"state":{"name":"Kitty"}},"visible":{"state":{"visibleScale":[1,1]}},"layered":{},"listed":{},"mobile":{"state":{"speed":40}},"physical":{},"positioned":{"state":{"x":0,"y":0}},"roomed":{},"shaped":{"params":{"shape":{"type":"rectangle","position":[0,0],"size":[8,4]}}},"vulnerable":{}}}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,6 @@
import fs from 'fs';
import path from 'path';
import {buildInvoke, buildTraversal} from '@avocado/behavior'; import {buildInvoke, buildTraversal} from '@avocado/behavior';
import {Vector} from '@avocado/math'; import {Vector} from '@avocado/math';
import {World} from '@avocado/physics/matter/world'; import {World} from '@avocado/physics/matter/world';
@ -476,26 +479,81 @@ function mamaKittySpawnerJSON() {
}; };
} }
const RESOURCE_PATH = path.resolve(process.cwd(), 'resource');
fs.writeFileSync(
path.join(RESOURCE_PATH, 'flower-barrel.entity.json'),
JSON.stringify(flowerBarrelJSON([0, 0]))
);
fs.writeFileSync(
path.join(RESOURCE_PATH, 'kitty.entity.json'),
JSON.stringify(kittyJSON([0, 0]))
);
fs.writeFileSync(
path.join(RESOURCE_PATH, 'mama-kitty.entity.json'),
JSON.stringify(mamaKittyJSON([0, 0]))
);
fs.writeFileSync(
path.join(RESOURCE_PATH, 'mama-kitty-spawner.entity.json'),
JSON.stringify(mamaKittySpawnerJSON([0, 0]))
);
fs.writeFileSync(
path.join(RESOURCE_PATH, 'fire.entity.json'),
JSON.stringify(fireJSON([0, 0]))
);
fs.writeFileSync(
path.join(RESOURCE_PATH, 'blue-fire.entity.json'),
JSON.stringify(blueFireJSON([0, 0]))
);
function positionedEntityJSON(uri, position) {
return {
uri,
traits: {
positioned: {
state: {
x: position[0] * 4,
y: position[1] * 4,
},
},
},
};
}
for (let i = 0; i < 50; ++i) { for (let i = 0; i < 50; ++i) {
const x = Math.floor(Math.random() * (roomSize[0] - 100)) + 50; const x = Math.floor(Math.random() * (roomSize[0] - 100)) + 50;
const y = Math.floor(Math.random() * (roomSize[1] - 100)) + 50; const y = Math.floor(Math.random() * (roomSize[1] - 100)) + 50;
roomJSON.layers[0].entities.push(flowerBarrelJSON([x * 4, y * 4])); roomJSON.layers[0].entities.push(
positionedEntityJSON('/flower-barrel.entity.json', [x, y])
);
} }
for (let i = 0; i < 5; ++i) { for (let i = 0; i < 5; ++i) {
const x = Math.floor(Math.random() * (roomSize[0] - 100)) + 50; const x = Math.floor(Math.random() * (roomSize[0] - 100)) + 50;
const y = Math.floor(Math.random() * (roomSize[1] - 100)) + 50; const y = Math.floor(Math.random() * (roomSize[1] - 100)) + 50;
roomJSON.layers[0].entities.push(mamaKittySpawnerJSON()); roomJSON.layers[0].entities.push(
positionedEntityJSON('/mama-kitty-spawner.entity.json', [x, y])
);
} }
for (let i = 0; i < 60; ++i) { for (let i = 0; i < 60; ++i) {
const x = Math.floor(Math.random() * (roomSize[0] - 100)) + 50; const x = Math.floor(Math.random() * (roomSize[0] - 100)) + 50;
const y = Math.floor(Math.random() * (roomSize[1] - 100)) + 50; const y = Math.floor(Math.random() * (roomSize[1] - 100)) + 50;
roomJSON.layers[0].entities.push(fireJSON([x * 4, y * 4])); roomJSON.layers[0].entities.push(
positionedEntityJSON('/fire.entity.json', [x, y])
);
} }
for (let i = 0; i < 5; ++i) { for (let i = 0; i < 5; ++i) {
const x = Math.floor(Math.random() * (roomSize[0] - 100)) + 50; const x = Math.floor(Math.random() * (roomSize[0] - 100)) + 50;
const y = Math.floor(Math.random() * (roomSize[1] - 100)) + 50; const y = Math.floor(Math.random() * (roomSize[1] - 100)) + 50;
roomJSON.layers[0].entities.push(blueFireJSON([x * 4, y * 4])); roomJSON.layers[0].entities.push(
positionedEntityJSON('/blue-fire.entity.json', [x, y])
);
} }
export function createRoom() { export function createRoom() {
const room = new Room(); const room = new Room();
room.fromJSON(roomJSON); room.fromJSON(roomJSON);