Trigger Cocept

Hey there.I want to implement a trigger-system into my game.
I thought of something like that:

Enemies, Traps, Doors, Music, etc. implement an interface namend “Triggerable”
A switch, keyhole, or a simple area within the level, has an Attribute called “whatToTrigger” and is an ArrayList.

But I have no Idea how to put the triggerable Objects into the Trigger of the Swtich/Keyhole/whatever.
Any ideas for that?

perhaps let this triggers take a collection/varargs of triggerable in the constructor

What’s wrong with adding a method to your Switch/Keyhole classes (or their common base class) to add a single Triggerable?


public void addTriggerable(Triggerable triggerable) {
    triggerables.add(triggerable);
}

How to put the triggerable objects into the trigger? Just add them to your ArrayList… or have I missed something???

Or do you mean when to add them? Perhaps your trigger object could have an add(Triggerable triggerable) method? You could then populate this as needed either during, or shortly after the trigger is instantiated… or whenever you want really.

PS. Might be worth making ‘Trigger’ an interface as well???