Skip to main content
changed terminology
Source Link
jhocking
  • 15.8k
  • 2
  • 45
  • 59

I alwaysusually go with a design where objects handle themselves (that's what methods are for, after all) but the base World has a listlists of all the objects thatand it uses those lists to coordinate them. So something like:

class World { var entitieswalls = [];  var actors = [];  function update() { for each (entityactor in entitiesactors) { entityactor.update(entitieswalls); } } } class EntityActor { function update(entitieswalls) { this.move(); for each (entitywall in entitieswalls) { this.collide(entitywall); } } } 

I always go with a design where objects handle themselves (that's what methods are for, after all) but the base World has a list of all the objects that it uses to coordinate them. So something like:

class World { var entities = []; function update() { for each (entity in entities) { entity.update(entities); } } } class Entity { function update(entities) { this.move(); for each (entity in entities) { this.collide(entity); } } } 

I usually go with a design where objects handle themselves (that's what methods are for, after all) but the base World has lists of all the objects and it uses those lists to coordinate them. So something like:

class World { var walls = [];  var actors = [];  function update() { for each (actor in actors) { actor.update(walls); } } } class Actor { function update(walls) { this.move(); for each (wall in walls) { this.collide(wall); } } } 
Source Link
jhocking
  • 15.8k
  • 2
  • 45
  • 59

I always go with a design where objects handle themselves (that's what methods are for, after all) but the base World has a list of all the objects that it uses to coordinate them. So something like:

class World { var entities = []; function update() { for each (entity in entities) { entity.update(entities); } } } class Entity { function update(entities) { this.move(); for each (entity in entities) { this.collide(entity); } } }