silphius/public/assets/tomato-seeds/start.js

151 lines
3.2 KiB
JavaScript
Raw Normal View History

2024-06-28 14:36:49 -05:00
const {Direction, Position, Wielder} = wielder
2024-07-24 09:28:35 -05:00
const projected = Wielder.activeItem()?.project(Position.tile, Direction.quantize(4))
2024-06-28 14:36:49 -05:00
if (projected?.length > 0) {
const {Controlled, Emitter, Sound, Sprite} = wielder
const {TileLayers} = ecs.get(1)
const layer = TileLayers.layer(0)
Controlled.locked = 1;
const [, direction] = Sprite.animation.split(':')
const plant = {
2024-07-02 16:16:39 -05:00
Collider: {
bodies: [
2024-07-03 16:13:14 -05:00
{
points: [
{x: -8, y: -8},
{x: 7, y: -8},
{x: -8, y: 7},
{x: 7, y: 7},
],
},
2024-07-02 16:16:39 -05:00
],
},
2024-07-01 18:12:53 -05:00
Interactive: {
interactScript: '/assets/tomato-plant/interact.js',
},
2024-06-28 14:36:49 -05:00
Plant: {
growScript: '/assets/tomato-plant/grow.js',
mayGrowScript: '/assets/tomato-plant/may-grow.js',
2024-07-20 07:20:32 -05:00
stages: [0.5, 0.5, 0.5, 0.5, 0.5],
2024-06-28 14:36:49 -05:00
},
Sprite: {
2024-07-03 21:56:55 -05:00
anchorY: 0.75,
2024-06-28 14:36:49 -05:00
animation: 'stage/0',
source: '/assets/tomato-plant/tomato-plant.json',
},
Ticking: {},
VisibleAabb: {},
};
const seedParticles = {
behaviors: [
{
type: 'moveAcceleration',
config: {
accel: {
x: 0,
y: 400,
},
minStart: 0,
maxStart: 0,
rotate: false,
}
},
{
type: 'moveSpeed',
config: {
speed: {
list: [
{
time: 0,
value: 100
},
{
time: 1,
value: 10
}
]
}
}
},
{
type: 'rotation',
config: {
accel: 0,
minSpeed: 0,
maxSpeed: 0,
minStart: 225,
maxStart: 320
}
},
{
type: 'scale',
config: {
scale: {
list: [
{
value: 0.75,
time: 0,
},
{
value: 0.5,
time: 1,
},
]
}
}
},
{
type: 'textureSingle',
config: {
texture: 'tomato-plant/tomato-plant/0',
}
},
],
lifetime: {
min: 0.25,
max: 0.25,
},
frequency: 0.01,
emitterLifetime: 0.75,
pos: {
x: Position.x,
y: Position.y,
},
};
Emitter.emit(seedParticles)
Sound.play('/assets/sow.wav');
Sprite.animation = ['moving', direction].join(':');
2024-07-24 09:28:35 -05:00
const directionMap = {0: 'right', 1: 'down', 2: 'left', 3: 'up'};
2024-06-28 14:36:49 -05:00
for (let i = 0; i < 6; ++i) {
2024-07-24 09:28:35 -05:00
Direction.direction = Math.HALF_PI * Math.floor(Math.random() * 4);
Sprite.animation = ['moving', directionMap[Direction.quantize(4)]].join(':');
2024-06-28 14:36:49 -05:00
await wait(0.125);
}
Sprite.animation = ['idle', direction].join(':');
const promises = [];
2024-07-12 17:41:55 -05:00
for (const {x, y} of projected) {
2024-06-28 14:36:49 -05:00
promises.push(ecs.create({
...plant,
Plant: {
...plant.Plant,
growthFactor: Math.floor(Math.random() * 256),
},
Position: {
2024-07-12 17:41:55 -05:00
x: x * layer.tileSize.x + (0.5 * layer.tileSize.x),
y: y * layer.tileSize.y + (0.5 * layer.tileSize.y),
2024-06-28 14:36:49 -05:00
},
}))
}
await Promise.all(promises)
Controlled.locked = 0;
}