Add basic gameobject system

This commit is contained in:
schmelczerandras 2020-07-19 13:50:03 +02:00
parent d5be727040
commit efb01476b2
33 changed files with 399 additions and 171 deletions

View file

@ -1,8 +1,24 @@
import { GameObject } from './game-object';
import { Camera } from './types/camera';
import { Id } from '../identity/identity';
import { Command } from '../commands/command';
import { CommandReceiver } from '../commands/command-receiver';
export class ObjectContainer {
private objects: Array<GameObject> = [];
export class ObjectContainer implements CommandReceiver {
private objects: Map<Id, GameObject> = new Map();
constructor(public camera: Camera) {}
public addObject(o: GameObject) {
this.objects.set(o.id, o);
}
public removeObject(o: GameObject) {
this.objects.delete(o.id);
}
public sendCommandToSingleObject(id: Id, e: Command) {
this.objects.get(id)?.sendCommand(e);
}
public sendCommand(e: Command) {
this.objects.forEach((o, _) => o.sendCommand(e));
}
}