Composite for Sprite Enchantment
Treat a solitary enchanted sprite and a swarm of them uniformly.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Composite
ARCANUM SCHOOL: Conjuration // Sprite Enchantment
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
function EnchantmentNode() constructor {
static render_magic = function() {};
}
function SingleSpriteNode(_sprite) : EnchantmentNode() constructor {
sprite = _sprite;
static render_magic = function() { draw_sprite(sprite, 0, x, y); };
}
function SpriteSwarm() : EnchantmentNode() constructor {
children = [];
static add = function(_node) { array_push(children, _node); };
static render_magic = function() {
for (var i = 0; i < array_length(children); i++) {
children[i].render_magic();
}
};
}
The Composite pattern weaves individual sparks and roaring infernos into the same abstraction. The spellcaster evokes render_magic() upon a single ember or a swirling vortex of a thousand composite sprites without distinguishing between them.
Runic Tags:
#gml
#structural
#composite