fun: smokin some kittens

This commit is contained in:
cha0s 2024-07-26 10:36:59 -05:00
parent c19beead68
commit 5ff4eb2991
7 changed files with 50 additions and 9 deletions

View File

@ -46,13 +46,19 @@ export default class Collider extends Component {
const script = this.$$collisionEnd.clone();
script.context.other = otherEntity;
script.context.pair = [body, otherBody];
thisEntity.Ticking.add(script.ticker());
const ticker = script.ticker();
ecs.addDestructionDependency(thisEntity.id, ticker);
ecs.addDestructionDependency(otherEntity.id, ticker);
thisEntity.Ticking.add(ticker);
}
if (other.$$collisionEnd) {
const script = other.$$collisionEnd.clone();
script.context.other = thisEntity;
script.context.pair = [otherBody, body];
otherEntity.Ticking.add(script.ticker());
const ticker = script.ticker();
ecs.addDestructionDependency(thisEntity.id, ticker);
ecs.addDestructionDependency(otherEntity.id, ticker);
otherEntity.Ticking.add(ticker);
}
}
this.$$intersections.delete(other);
@ -102,13 +108,19 @@ export default class Collider extends Component {
const script = this.$$collisionStart.clone();
script.context.other = otherEntity;
script.context.pair = [body, otherBody];
thisEntity.Ticking.add(script.ticker());
const ticker = script.ticker();
ecs.addDestructionDependency(otherEntity.id, ticker);
ecs.addDestructionDependency(thisEntity.id, ticker);
thisEntity.Ticking.add(ticker);
}
if (other.$$collisionStart) {
const script = other.$$collisionStart.clone();
script.context.other = thisEntity;
script.context.pair = [otherBody, body];
otherEntity.Ticking.add(script.ticker());
const ticker = script.ticker();
ecs.addDestructionDependency(otherEntity.id, ticker);
ecs.addDestructionDependency(thisEntity.id, ticker);
otherEntity.Ticking.add(ticker);
}
activeIntersections.add(intersection);
}

View File

@ -0,0 +1,7 @@
import Component from '@/ecs/component.js';
export default class Owned extends Component {
static properties = {
owner: {type: 'string'},
};
}

View File

@ -0,0 +1,4 @@
import Component from '@/ecs/component.js';
export default class Vulnerable extends Component {
}

View File

@ -191,8 +191,9 @@ export default async function createHomestead(id) {
Tags: {tags: ['kittan']},
Ticking: {},
VisibleAabb: {},
Vulnerable: {},
};
for (let i = 0; i < 30; ++i) {
for (let i = 0; i < 10; ++i) {
entities.push(kitty);
}
entities.push({

View File

@ -48,6 +48,9 @@ export default class Engine {
get frame() {
return engine.frame;
}
lookupPlayerEntity(id) {
return engine.lookupPlayerEntity(id);
}
async readAsset(uri) {
if (!cache.has(uri)) {
const {promise, resolve, reject} = withResolvers();
@ -325,6 +328,14 @@ export default class Engine {
return player;
}
lookupPlayerEntity(id) {
for (const [, player] of this.connectedPlayers) {
if (player.id == id) {
return player.entity;
}
}
}
async saveEcs(path, ecs) {
const view = this.Ecs.serialize(ecs);
await this.server.writeData(path, view);

View File

@ -0,0 +1,4 @@
const playerEntity = ecs.lookupPlayerEntity(entity.Owned.owner);
if (playerEntity !== other && other.Vulnerable) {
ecs.destroy(other.id);
}

View File

@ -1,4 +1,4 @@
const {Position} = wielder;
const {Player, Position} = wielder;
const shots = [];
@ -23,10 +23,12 @@ for (let i = 0; i < N; ++i) {
unstoppable: 1,
},
],
collisionStartScript: '/assets/magic-swords/collision-start.js',
},
Controlled: {},
Direction: {direction: Math.TAU * (i / N)},
Forces: {},
Owned: {owner: Player ? Player.id : 0},
Position: {x: Position.x, y: Position.y},
Speed: {},
Sprite: {
@ -73,6 +75,8 @@ while (shots.length > 0) {
shot.Direction.direction = (Math.TAU + toward) % Math.TAU;
if (Math.distance(where, shot.Position) < 4) {
delete accumulated[shot.id];
shot.Sprite.alpha = 0;
ecs.destroy(shot.id);
destroying.push(shot);
}
}
@ -80,8 +84,6 @@ while (shots.length > 0) {
}
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)
await wait(0);
}