fun: magic swords
This commit is contained in:
parent
5fe346372b
commit
adcdc81423
|
@ -142,6 +142,7 @@ export default class Collider extends Component {
|
|||
type: 'array',
|
||||
subtype: {type: 'string'},
|
||||
},
|
||||
unstoppable: {type: 'uint8'},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -89,8 +89,9 @@ export default class Colliders extends System {
|
|||
}
|
||||
for (const i in intersections) {
|
||||
const [body, otherBody] = intersections[i];
|
||||
const {unstoppable} = body;
|
||||
const {impassable} = otherBody;
|
||||
if (impassable) {
|
||||
if (!unstoppable && impassable) {
|
||||
const j = entity.Collider.bodies.indexOf(body);
|
||||
const oj = other.Collider.bodies.indexOf(otherBody);
|
||||
const aabb = entity.Collider.$$aabbs[j];
|
||||
|
|
|
@ -26,6 +26,10 @@ export default async function createPlayer(id) {
|
|||
qty: 100,
|
||||
source: '/assets/potion/potion.json',
|
||||
},
|
||||
2: {
|
||||
qty: 1,
|
||||
source: '/assets/magic-swords/magic-swords.json',
|
||||
},
|
||||
},
|
||||
},
|
||||
Health: {health: 100},
|
||||
|
|
BIN
public/assets/magic-swords/icon.png
Normal file
BIN
public/assets/magic-swords/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
1
public/assets/magic-swords/magic-sword-shot.json
Normal file
1
public/assets/magic-swords/magic-sword-shot.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"frames":{"":{"frame":{"x":0,"y":0,"w":22,"h":22},"spriteSourceSize":{"x":0,"y":0,"w":22,"h":22},"sourceSize":{"w":22,"h":22}}},"meta":{"format":"RGBA8888","image":"./magic-sword-shot.png","rotation":2.356194490192345,"scale":1,"size":{"w":22,"h":22}}}
|
BIN
public/assets/magic-swords/magic-sword-shot.png
Normal file
BIN
public/assets/magic-swords/magic-sword-shot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
5
public/assets/magic-swords/magic-swords.json
Normal file
5
public/assets/magic-swords/magic-swords.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"icon": "/assets/magic-swords/icon.png",
|
||||
"label": "Magic swords",
|
||||
"start": "/assets/magic-swords/start.js"
|
||||
}
|
87
public/assets/magic-swords/start.js
Normal file
87
public/assets/magic-swords/start.js
Normal file
|
@ -0,0 +1,87 @@
|
|||
const {Position} = wielder;
|
||||
|
||||
const shots = [];
|
||||
|
||||
const EVERY = 0.03;
|
||||
const N = 14;
|
||||
const SPREAD = 1;
|
||||
|
||||
const creating = [];
|
||||
const promises = []
|
||||
|
||||
for (let i = 0; i < N; ++i) {
|
||||
promises.push(ecs.create({
|
||||
Collider: {
|
||||
bodies: [
|
||||
{
|
||||
points: [
|
||||
{x: -3, y: -2},
|
||||
{x: 12, y: -2},
|
||||
{x: 12, y: 2},
|
||||
{x: -3, y: 2},
|
||||
],
|
||||
unstoppable: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
Controlled: {},
|
||||
Direction: {direction: Math.TAU * (i / N)},
|
||||
Forces: {},
|
||||
Position: {x: Position.x, y: Position.y},
|
||||
Speed: {},
|
||||
Sprite: {
|
||||
alpha: 0,
|
||||
source: '/assets/magic-swords/magic-sword-shot.json',
|
||||
},
|
||||
Ticking: {},
|
||||
VisibleAabb: {},
|
||||
}));
|
||||
}
|
||||
|
||||
for (const id of await Promise.all(promises)) {
|
||||
creating.push(ecs.get(id));
|
||||
}
|
||||
|
||||
const accumulated = {};
|
||||
const shot = creating.shift();
|
||||
shot.Sprite.alpha = 1;
|
||||
accumulated[shot.id] = 0;
|
||||
shots.push(shot)
|
||||
|
||||
let spawner = 0;
|
||||
while (shots.length > 0) {
|
||||
spawner += elapsed;
|
||||
if (creating.length > 0 && spawner >= EVERY) {
|
||||
const shot = creating.shift();
|
||||
shot.Sprite.alpha = 1;
|
||||
accumulated[shot.id] = 0;
|
||||
shots.push(shot)
|
||||
spawner -= EVERY;
|
||||
}
|
||||
const destroying = [];
|
||||
for (const shot of shots) {
|
||||
accumulated[shot.id] += elapsed;
|
||||
if (accumulated[shot.id] <= SPREAD) {
|
||||
shot.Speed.speed = 100 * (1 - (accumulated[shot.id] / SPREAD))
|
||||
}
|
||||
else {
|
||||
const toward = Math.atan2(
|
||||
where.y - shot.Position.y,
|
||||
where.x - shot.Position.x,
|
||||
)
|
||||
shot.Speed.speed = 400;
|
||||
shot.Direction.direction = (Math.TAU + toward) % Math.TAU;
|
||||
if (Math.distance(where, shot.Position) < 4) {
|
||||
delete accumulated[shot.id];
|
||||
destroying.push(shot);
|
||||
}
|
||||
}
|
||||
shot.Controlled.directionMove(shot.Direction.direction);
|
||||
}
|
||||
for (let i = 0; i < destroying.length; ++i) {
|
||||
shots.splice(shots.indexOf(destroying[i]), 1);
|
||||
destroying[i] = destroying[i].id;
|
||||
}
|
||||
ecs.destroyMany(destroying);
|
||||
await wait(0)
|
||||
}
|
Loading…
Reference in New Issue
Block a user