refactor: creation

This commit is contained in:
cha0s 2024-09-28 07:56:12 -05:00
parent c1bdae1c8c
commit ffa391fcef
2 changed files with 289 additions and 160 deletions

View File

@ -22,10 +22,9 @@ function animal() {
};
}
export default async function createHomestead(id) {
function createMaster() {
const area = {x: 100, y: 60};
const entities = [];
entities.push({
return {
AreaSize: {x: area.x * 16, y: area.y * 16},
Ticking: {},
TileLayers: {
@ -46,8 +45,11 @@ export default async function createHomestead(id) {
},
Time: {},
Water: {water: {}},
});
entities.push({
};
}
function createShitShack(id) {
return {
Collider: {
bodies: [
{
@ -72,8 +74,11 @@ export default async function createHomestead(id) {
},
Ticking: {},
VisibleAabb: {},
});
entities.push({
};
}
function createHouseTeleport(id) {
return {
Collider: {
bodies: [
{
@ -102,8 +107,11 @@ export default async function createHomestead(id) {
},
Position: {x: 71, y: 113},
Ticking: {},
});
entities.push({
};
}
function createChest() {
return {
Collider: {
bodies: [
{
@ -160,162 +168,212 @@ export default async function createHomestead(id) {
},
Ticking: {},
VisibleAabb: {},
});
};
}
function createTomato() {
return {
Collider: {
bodies: [
{
points: [
{x: -4, y: -4},
{x: 3, y: -4},
{x: 3, y: 3},
{x: -4, y: 3},
],
},
],
collisionStartScript: [
'if (other.Inventory) {',
' other.Inventory.give({',
' qty: 1,',
" source: '/resources/tomato/tomato.json',",
' })',
' ecs.destroy(entity.id)',
' undefined;',
'}',
].join('\n'),
},
Forces: {},
Magnetic: {},
Position: {
x: 168 + Math.random() * 30,
y: 448 + Math.random() * 30,
},
Sprite: {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.333,
scaleY: 0.333,
source: '/resources/tomato/tomato-sprite.json',
},
Ticking: {},
VisibleAabb: {},
};
}
function createTestKitten() {
const animalJson = animal();
for (let i = 0; i < 10; ++i) {
entities.push({
...animalJson,
Behaving: {
routines: {
initial: '/resources/kitty/initial.js',
return {
...animalJson,
Behaving: {
routines: {
initial: '/resources/kitty/initial.js',
},
},
Collider: {
bodies: [
{
points: [
{x: -3.5, y: -3.5},
{x: 3.5, y: -3.5},
{x: 3.5, y: 3.5},
{x: -3.5, y: 3.5},
],
},
],
},
Interactive: {
interacting: 1,
interactScript: `
const lines = [
'mrowwr',
'p<shake>rrr</shake>o<wave>wwwww</wave>',
'mew<rate frequency={0.5}> </rate>mew!',
'me<wave>wwwww</wave>',
'\\\\*pu<shake>rrrrr</shake>\\\\*',
];
const line = lines[Math.floor(Math.random() * lines.length)];
subject.Interlocutor.dialogue({
body: line,
linger: 2,
offset: {x: 0, y: -16},
origin: 'track',
position: 'track',
})
`,
},
Position: {
x: 250 + (Math.random() - 0.5) * 300,
y: 250 + (Math.random() - 0.5) * 300,
},
Sprite: {
...animalJson.Sprite,
anchorX: 0.5,
anchorY: 0.7,
source: '/resources/kitty/kitty.json',
speed: 0.115,
},
Tags: {tags: ['kittan']},
};
}
function createTestCow() {
const animalJson = animal();
return {
...animalJson,
Behaving: {
routines: {
initial: '/resources/farm/animals/cow-adult/initial.js',
},
Collider: {
bodies: [
{
points: [
{x: -3.5, y: -3.5},
{x: 3.5, y: -3.5},
{x: 3.5, y: 3.5},
{x: -3.5, y: 3.5},
],
},
],
},
Interactive: {
interacting: 1,
interactScript: `
const lines = [
'mrowwr',
'p<shake>rrr</shake>o<wave>wwwww</wave>',
'mew<rate frequency={0.5}> </rate>mew!',
'me<wave>wwwww</wave>',
'\\\\*pu<shake>rrrrr</shake>\\\\*',
];
const line = lines[Math.floor(Math.random() * lines.length)];
subject.Interlocutor.dialogue({
body: line,
linger: 2,
offset: {x: 0, y: -16},
origin: 'track',
position: 'track',
})
`,
},
Position: {
x: 250 + (Math.random() - 0.5) * 300,
y: 250 + (Math.random() - 0.5) * 300,
},
Sprite: {
...animalJson.Sprite,
anchorX: 0.5,
anchorY: 0.7,
source: '/resources/kitty/kitty.json',
speed: 0.115,
},
Tags: {tags: ['kittan']},
});
}
for (let i = 0; i < 10; ++i) {
entities.push({
...animalJson,
Behaving: {
routines: {
initial: '/resources/farm/animals/cow-adult/initial.js',
},
Collider: {
bodies: [
{
points: [
{x: -3.5, y: -3.5},
{x: 3.5, y: -3.5},
{x: 3.5, y: 3.5},
{x: -3.5, y: 3.5},
],
},
],
},
Interactive: {
interacting: 1,
interactScript: `
const lines = [
'sno<shake>rr</shake>t',
'm<wave>ooooooooooo</wave>',
];
const line = lines[Math.floor(Math.random() * lines.length)];
subject.Interlocutor.dialogue({
body: line,
linger: 2,
offset: {x: 0, y: -16},
origin: 'track',
position: 'track',
})
`,
},
Position: {
x: 350 + (Math.random() - 0.5) * 300,
y: 350 + (Math.random() - 0.5) * 300,
},
Sprite: {
...animalJson.Sprite,
anchorX: 0.5,
anchorY: 0.8,
source: '/resources/farm/animals/cow-adult/cow-adult.json',
speed: 0.25,
},
};
}
function createTestGoat() {
const animalJson = animal();
return {
...animalJson,
Behaving: {
routines: {
initial: '/resources/farm/animals/goat-white/initial.js',
},
Collider: {
bodies: [
{
points: [
{x: -3.5, y: -3.5},
{x: 3.5, y: -3.5},
{x: 3.5, y: 3.5},
{x: -3.5, y: 3.5},
],
},
],
},
Interactive: {
interacting: 1,
interactScript: `
const lines = [
'sno<shake>rr</shake>t',
'm<wave>ooooooooooo</wave>',
];
const line = lines[Math.floor(Math.random() * lines.length)];
subject.Interlocutor.dialogue({
body: line,
linger: 2,
offset: {x: 0, y: -16},
origin: 'track',
position: 'track',
})
`,
},
Position: {
x: 350 + (Math.random() - 0.5) * 300,
y: 350 + (Math.random() - 0.5) * 300,
},
Sprite: {
...animalJson.Sprite,
anchorX: 0.5,
anchorY: 0.8,
source: '/resources/farm/animals/cow-adult/cow-adult.json',
speed: 0.25,
},
});
}
for (let i = 0; i < 10; ++i) {
entities.push({
...animalJson,
Behaving: {
routines: {
initial: '/resources/farm/animals/goat-white/initial.js',
},
Collider: {
bodies: [
{
points: [
{x: -7, y: -3.5},
{x: 7, y: -3.5},
{x: 7, y: 3.5},
{x: -7, y: 3.5},
],
},
},
Collider: {
bodies: [
{
points: [
{x: -7, y: -3.5},
{x: 7, y: -3.5},
{x: 7, y: 3.5},
{x: -7, y: 3.5},
],
},
],
},
Interactive: {
interacting: 1,
interactScript: `
const lines = [
'Mind your own business, buddy.\\n\\ner, I mean, <shake>MEEHHHHHH</shake>',
];
const line = lines[Math.floor(Math.random() * lines.length)];
subject.Interlocutor.dialogue({
body: line,
linger: 2,
offset: {x: 0, y: -16},
origin: 'track',
position: 'track',
})
`,
},
Position: {
x: 350 + (Math.random() - 0.5) * 300,
y: 150 + (Math.random() - 0.5) * 300,
},
Sprite: {
...animalJson.Sprite,
anchorX: 0.5,
anchorY: 0.8,
source: '/resources/farm/animals/goat-white/goat-white.json',
speed: 0.25,
},
});
}
entities.push({
],
},
Interactive: {
interacting: 1,
interactScript: `
const lines = [
'Mind your own business, buddy.\\n\\ner, I mean, <shake>MEEHHHHHH</shake>',
];
const line = lines[Math.floor(Math.random() * lines.length)];
subject.Interlocutor.dialogue({
body: line,
linger: 2,
offset: {x: 0, y: -16},
origin: 'track',
position: 'track',
})
`,
},
Position: {
x: 350 + (Math.random() - 0.5) * 300,
y: 150 + (Math.random() - 0.5) * 300,
},
Sprite: {
...animalJson.Sprite,
anchorX: 0.5,
anchorY: 0.8,
source: '/resources/farm/animals/goat-white/goat-white.json',
speed: 0.25,
},
};
}
function createTownTeleport() {
return {
Collider: {
bodies: [
{
@ -345,6 +403,65 @@ export default async function createHomestead(id) {
Position: {x: 8, y: 432},
Ticking: {},
});
};
}
function createTomatoPlant() {
return {
Collider: {
bodies: [
{
points: [
{x: -8, y: -8},
{x: 7, y: -8},
{x: -8, y: 7},
{x: 7, y: 7},
],
},
],
},
Interactive: {
interactScript: '/resources/tomato-plant/interact.js',
},
Plant: {
growScript: '/resources/tomato-plant/grow.js',
growthFactor: Math.floor(Math.random() * 256),
mayGrowScript: '/resources/tomato-plant/may-grow.js',
stages: [0.5, 0.5, 0.5, 0.5, 0.5],
},
Position: {
x: 168,
y: 440,
},
Sprite: {
anchorY: 0.75,
animation: 'stage/0',
source: '/resources/tomato-plant/tomato-plant.json',
},
Ticking: {},
VisibleAabb: {},
};
}
export default async function createHomestead(id) {
const entities = [];
entities.push(createMaster());
entities.push(createShitShack(id));
entities.push(createHouseTeleport(id));
entities.push(createChest());
// for (let i = 0; i < 200; ++i) {
// entities.push(createTomato());
// }
entities.push(createTomatoPlant());
// for (let i = 0; i < 10; ++i) {
// entities.push(createTestKitten());
// }
// for (let i = 0; i < 10; ++i) {
// entities.push(createTestCow());
// }
// for (let i = 0; i < 10; ++i) {
// entities.push(createTestGoat());
// }
entities.push(createTownTeleport());
return entities;
}

View File

@ -30,6 +30,18 @@ export default async function createPlayer(id) {
qty: 1,
source: '/resources/magic-swords/magic-swords.json',
},
3: {
qty: 1,
source: '/resources/watering-can/watering-can.json',
},
4: {
qty: 1,
source: '/resources/tomato-seeds/tomato-seeds.json',
},
5: {
qty: 1,
source: '/resources/hoe/hoe.json',
},
},
},
Health: {health: 100},