fun: mama kitteh!

This commit is contained in:
cha0s 2019-04-21 01:31:07 -05:00
parent a5af91bd70
commit 78d655fe02
2 changed files with 142 additions and 110 deletions

View File

@ -1,5 +1,67 @@
import {World} from '@avocado/physics/matter/world'; import {World} from '@avocado/physics/matter/world';
import {Room} from '@avocado/topdown'; import {Room} from '@avocado/topdown';
// Helpers to make scripts for now.
const behaviorTraversal = (path, value) => {
const traversal = {
type: 'traversal',
steps: path.map((key) => {
return {
type: 'key',
key: key,
};
}),
};
if ('undefined' !== typeof value) {
if ('object' === typeof value && 'traversal' === value.type) {
traversal.value = value;
}
else {
traversal.value = {
type: 'literal',
value,
};
}
}
return traversal;
}
const behaviorInvoke = (path, args) => {
const traversal = behaviorTraversal(path);
traversal.steps.push({
type: 'invoke',
args: args.map((arg) => {
if ('object' === typeof arg && 'traversal' === arg.type) {
return arg;
}
return {
type: 'literal',
value: arg,
};
}),
});
return traversal;
}
// Behaviors!
const move = behaviorInvoke(['entity', 'moveFor'], [
behaviorInvoke(['global', 'randomNumber'], [0.25, 1, false])
]);
const firstWait = behaviorInvoke(['global', 'wait'], [
behaviorInvoke(['global', 'randomNumber'], [1, 4, false])
]);
const turn = behaviorTraversal(
['entity', 'direction'],
behaviorInvoke(['global', 'randomNumber'], [0, 3])
);
const secondWait = behaviorInvoke(['global', 'wait'], [
behaviorInvoke(['global', 'randomNumber'], [0.5, 3, false])
]);
// A fire. // A fire.
function fireJSON(position) { function fireJSON(position) {
return { return {
@ -115,38 +177,6 @@ function flowerBarrelJSON(position) {
} }
// A kitteh. // A kitteh.
function kittyJSON(position) { function kittyJSON(position) {
const buildRandom = (min, max, floor = true) => {
return {
type: 'traversal',
steps: [
{
type: 'key',
key: 'global',
},
{
type: 'key',
key: 'randomNumber',
},
{
type: 'invoke',
args: [
{
type: 'literal',
value: min,
},
{
type: 'literal',
value: max,
},
{
type: 'literal',
value: floor,
},
],
},
],
};
}
return { return {
traits: { traits: {
alive: {}, alive: {},
@ -154,7 +184,7 @@ function kittyJSON(position) {
params: { params: {
animations: { animations: {
idle: { idle: {
offset: [0, -6], offset: [0, -3],
uri: '/kitty.animation.json', uri: '/kitty.animation.json',
}, },
} }
@ -180,77 +210,10 @@ function kittyJSON(position) {
routine: { routine: {
type: 'actions', type: 'actions',
traversals: [ traversals: [
{ move,
type: 'action', firstWait,
steps: [ turn,
{ secondWait,
type: 'key',
key: 'entity',
},
{
type: 'key',
key: 'moveFor',
},
{
type: 'invoke',
args: [
buildRandom(0.25, 1, false),
],
},
],
},
{
type: 'action',
steps: [
{
type: 'key',
key: 'global',
},
{
type: 'key',
key: 'wait',
},
{
type: 'invoke',
args: [
buildRandom(1, 4),
],
},
],
},
{
type: 'action',
steps: [
{
type: 'key',
key: 'entity',
},
{
type: 'key',
key: 'direction',
},
],
value: buildRandom(0, 3),
},
{
type: 'action',
steps: [
{
type: 'key',
key: 'global',
},
{
type: 'key',
key: 'wait',
},
{
type: 'invoke',
args: [
buildRandom(0.5, 3),
],
},
],
},
], ],
} }
}, },
@ -271,7 +234,7 @@ function kittyJSON(position) {
existent: {}, existent: {},
visible: { visible: {
state: { state: {
visibleScale: [1.5, 1.5], visibleScale: [1, 1],
} }
}, },
mobile: { mobile: {
@ -291,7 +254,7 @@ function kittyJSON(position) {
shape: { shape: {
type: 'rectangle', type: 'rectangle',
position: [0, 0], position: [0, 0],
size: [12, 6], size: [8, 4],
}, },
}, },
}, },
@ -299,6 +262,70 @@ function kittyJSON(position) {
}, },
}; };
} }
// A MAMA kitteh.
function mamaKittyJSON(position) {
const storeJSON = behaviorTraversal(
['context', 'json'],
{
traits: {
positioned: {
state: {},
},
},
},
);
const setJSONX = behaviorTraversal(
['context', 'json', 'traits', 'positioned', 'state', 'x'],
behaviorInvoke(['global', 'multiply'], [
behaviorTraversal(['entity', 'x']), 4
]),
);
const setJSONY = behaviorTraversal(
['context', 'json', 'traits', 'positioned', 'state', 'y'],
behaviorInvoke(['global', 'multiply'], [
behaviorTraversal(['entity', 'y']), 4
]),
);
const spawn = behaviorInvoke(['entity', 'spawn'], [
'kitteh',
behaviorTraversal(['context', 'json']),
]);
const json = JSON.parse(JSON.stringify(kittyJSON(position)));
const {traits} = json;
traits.alive.state ={
life: 5000,
maxLife: 5000,
};
traits.animated.params.animations.idle.offset = [0, -8];
traits.behaved.params.routines.routines.initial.routine.traversals = [
move,
firstWait,
turn,
storeJSON,
setJSONX,
setJSONY,
spawn,
secondWait,
];
traits.visible.state.visibleScale = [2, 2];
traits.shaped.params.shape.size = [16, 8];
traits.spawner = {
params: {
spawns: {
kitteh: kittyJSON([100, 100]),
},
},
state: {
maxSpawns: 15,
},
};
return json;
}
// Room. // Room.
const roomJSON = { const roomJSON = {
size: [384, 384], size: [384, 384],
@ -348,10 +375,10 @@ for (let i = 0; i < 20; ++i) {
const y = Math.floor(Math.random() * 284) + 50; const y = Math.floor(Math.random() * 284) + 50;
roomJSON.layers.everything.entities.push(flowerBarrelJSON([x * 4, y * 4])); roomJSON.layers.everything.entities.push(flowerBarrelJSON([x * 4, y * 4]));
} }
for (let i = 0; i < 50; ++i) { for (let i = 0; i < 4; ++i) {
const x = Math.floor(Math.random() * 284) + 50; const x = Math.floor(Math.random() * 284) + 50;
const y = Math.floor(Math.random() * 284) + 50; const y = Math.floor(Math.random() * 284) + 50;
roomJSON.layers.everything.entities.push(kittyJSON([x * 4, y * 4])); roomJSON.layers.everything.entities.push(mamaKittyJSON([x * 4, y * 4]));
} }
for (let i = 0; i < 15; ++i) { for (let i = 0; i < 15; ++i) {
const x = Math.floor(Math.random() * 284) + 50; const x = Math.floor(Math.random() * 284) + 50;

View File

@ -21,8 +21,8 @@
resolved "https://npm.i12e.cha0s.io/@avocado%2fcore/-/core-1.0.4.tgz#ca0c9c91f91b51d02655808f3f85cf7f9b845b29" resolved "https://npm.i12e.cha0s.io/@avocado%2fcore/-/core-1.0.4.tgz#ca0c9c91f91b51d02655808f3f85cf7f9b845b29"
"@avocado/entity@1.x": "@avocado/entity@1.x":
version "1.0.9" version "1.0.10"
resolved "https://npm.i12e.cha0s.io/@avocado%2fentity/-/entity-1.0.9.tgz#aea08882c343b2a534d6cfc86d42263686c481cc" resolved "https://npm.i12e.cha0s.io/@avocado%2fentity/-/entity-1.0.10.tgz#ff39fcbe41bb20b75d7defc4eb069d535dd9543a"
dependencies: dependencies:
"@avocado/core" "1.x" "@avocado/core" "1.x"
"@avocado/graphics" "1.x" "@avocado/graphics" "1.x"
@ -34,6 +34,7 @@
debug "^3.1.0" debug "^3.1.0"
immutable "4.0.0-rc.12" immutable "4.0.0-rc.12"
lodash.mapvalues "4.6.0" lodash.mapvalues "4.6.0"
lodash.merge "4.6.1"
lodash.without "4.4.0" lodash.without "4.4.0"
"@avocado/graphics@1.x": "@avocado/graphics@1.x":
@ -2874,6 +2875,10 @@ lodash.mapvalues@4.6.0:
version "4.6.0" version "4.6.0"
resolved "https://npm.i12e.cha0s.io/lodash.mapvalues/-/lodash.mapvalues-4.6.0.tgz#1bafa5005de9dd6f4f26668c30ca37230cc9689c" resolved "https://npm.i12e.cha0s.io/lodash.mapvalues/-/lodash.mapvalues-4.6.0.tgz#1bafa5005de9dd6f4f26668c30ca37230cc9689c"
lodash.merge@4.6.1:
version "4.6.1"
resolved "https://npm.i12e.cha0s.io/lodash.merge/-/lodash.merge-4.6.1.tgz#adc25d9cb99b9391c59624f379fbba60d7111d54"
lodash.without@4.4.0: lodash.without@4.4.0:
version "4.4.0" version "4.4.0"
resolved "https://npm.i12e.cha0s.io/lodash.without/-/lodash.without-4.4.0.tgz#3cd4574a00b67bae373a94b748772640507b7aac" resolved "https://npm.i12e.cha0s.io/lodash.without/-/lodash.without-4.4.0.tgz#3cd4574a00b67bae373a94b748772640507b7aac"