refactor: entity json
This commit is contained in:
parent
2fe09d3cb2
commit
6e8f74b369
47
resources/magic-swords/shot.entity.json
Normal file
47
resources/magic-swords/shot.entity.json
Normal file
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"Behaving": {
|
||||
"routines": {
|
||||
"initial": "/resources/magic-swords/initial.js"
|
||||
}
|
||||
},
|
||||
"Collider": {
|
||||
"bodies": [
|
||||
{
|
||||
"group": -1,
|
||||
"points": [
|
||||
{
|
||||
"x": -2.5,
|
||||
"y": -2.5
|
||||
},
|
||||
{
|
||||
"x": 14,
|
||||
"y": -2.5
|
||||
},
|
||||
{
|
||||
"x": 14,
|
||||
"y": 2.5
|
||||
},
|
||||
{
|
||||
"x": -2.5,
|
||||
"y": 2.5
|
||||
}
|
||||
],
|
||||
"unstoppable": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
"Controlled": {},
|
||||
"Forces": {},
|
||||
"Harmful": {
|
||||
"harmScript": "/resources/magic-swords/harm.js"
|
||||
},
|
||||
"Light": {
|
||||
"brightness": 0
|
||||
},
|
||||
"Speed": {},
|
||||
"Sprite": {
|
||||
"source": "/resources/magic-swords/magic-sword-shot.sprite.json"
|
||||
},
|
||||
"Ticking": {},
|
||||
"VisibleAabb": {}
|
||||
}
|
|
@ -3,56 +3,27 @@ import Ticker from '@/util/ticker.js';
|
|||
|
||||
const SHOTS = 14;
|
||||
|
||||
function createShots(where, wielder) {
|
||||
function createShots(ecs, where, wielder) {
|
||||
const offset = Math.random() * Math.TAU;
|
||||
const {Player, Position} = wielder;
|
||||
const json = ecs.readJson('/resources/magic-swords/shot.entity.json');
|
||||
const shots = [];
|
||||
for (let i = 0; i < SHOTS; ++i) {
|
||||
shots.push({
|
||||
...json,
|
||||
Arbitrary: {
|
||||
blob: JSON.stringify({where}),
|
||||
},
|
||||
Behaving: {
|
||||
routines: {
|
||||
initial: '/resources/magic-swords/initial.js',
|
||||
},
|
||||
},
|
||||
Collider: {
|
||||
bodies: [
|
||||
{
|
||||
group: -1,
|
||||
points: [
|
||||
{x: -2.5, y: -2.5},
|
||||
{x: 14, y: -2.5},
|
||||
{x: 14, y: 2.5},
|
||||
{x: -2.5, y: 2.5},
|
||||
],
|
||||
unstoppable: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
Controlled: {},
|
||||
Direction: {direction: offset + Math.TAU * (i / SHOTS)},
|
||||
Forces: {},
|
||||
Harmful: {
|
||||
harmScript: '/resources/magic-swords/harm.js',
|
||||
},
|
||||
Light: {brightness: 0},
|
||||
Owned: {owner: Player ? Player.id : 0},
|
||||
Position: {x: Position.x, y: Position.y},
|
||||
Speed: {},
|
||||
Sprite: {
|
||||
source: '/resources/magic-swords/magic-sword-shot.sprite.json',
|
||||
},
|
||||
Ticking: {},
|
||||
VisibleAabb: {},
|
||||
});
|
||||
}
|
||||
return shots;
|
||||
}
|
||||
|
||||
export default function*({ecs, where, wielder}) {
|
||||
const shots = createShots(where, wielder);
|
||||
const shots = createShots(ecs, where, wielder);
|
||||
do {
|
||||
ecs.create(shots.shift());
|
||||
yield Ticker.wait(0.03);
|
||||
|
|
Loading…
Reference in New Issue
Block a user