Add basic gameobject system
This commit is contained in:
parent
d5be727040
commit
efb01476b2
33 changed files with 399 additions and 171 deletions
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue