Alternatives to Component Based Architecture?
- by Ben Lakey
Usually when I develop a game I will use an architecture like what you see below. What other architectures are popular for simple game development? I'm concerned about having a narrow view of what exists out there for architectures beyond this. Is this an example of component-based architecture? Or is this something else? What would that look like? What alternatives exist?
public abstract class ComponentBase {
protected final Collection<ComponentBase> subComponents = new LinkedList<ComponentBase>();
private boolean enableInput;
private boolean isVisible;
protected ComponentBase(boolean enableInput, boolean isVisible) {
this.enableInput = enableInput;
this.isVisible = isVisible;
}
public void render(Graphics2D graphics) {
for(ComponentBase gameComponent : this.subComponents) {
if(gameComponent.isVisible()) {
gameComponent.render(graphics);
}
}
}
public void input(InputData input) {
for(ComponentBase gameComponent : this.subComponents) {
if(gameComponent.inputIsEnabled()) {
gameComponent.input(input);
}
}
}
... getters/setters ...
public void update(long elapsedTimeMillis) {
for(ComponentBase gameComponent : this.subComponents) {
gameComponent.update(elapsedTimeMillis);
}
}
}