import Rect from './Rect'; import Vec2 from './Vec2'; export class Trait { constructor(entity, name) { this.name = name; this.entity = entity; this.enabled = true; } init() {} update(dt) {} } export default class Entity { constructor(level) { this.level = level; this.bounds = new Rect(); this.velocity = new Vec2(); this.t = {}; this.traits = []; } init() { for (let trait of this.traits) { trait.init(); } } update(dt) { for (let trait of this.traits) { if (trait.enabled) trait.update(dt); } this.bounds.pos.x += this.velocity.x * dt; this.bounds.pos.y += this.velocity.y * dt; } draw(ctx) {} has(name) { let t = this.t[name]; return t != null && t.enabled; } addTrait(t) { this.t[t.name] = t; this.traits.push(t); } }