Class: Slickr::Reactor
- Inherits:
-
Object
- Object
- Slickr::Reactor
- Defined in:
- lib/slickr/reactor.rb
Overview
Reactors take info about the game world and tell relevant entities to do something. Emphasis is on the word “tell”.
Concerns
Reactors are always concerned with entities who implement one or more specific behaviors. For instance, an # InputReactor would care about entities who implement the Controllable behavior.
Using Ractors
Reactors are middleware of your game’s Engine. They are called during every update tick of your game. They are passed the game’s container and the delta of time that has passed since the last tick.
if you need to do some special setup in your Reactors, do it in the initializer like any normal ruby object.
Reacting
Reactors simply orcestrate. They take that delta and tell the entities they care about to do something. Following the above example, here’s a simple Reactor that moves entities around the world.
Class Attribute Summary collapse
-
.concerns ⇒ Object
Returns the value of attribute concerns.
Class Method Summary collapse
Instance Method Summary collapse
Class Attribute Details
.concerns ⇒ Object
Returns the value of attribute concerns.
64 65 66 |
# File 'lib/slickr/reactor.rb', line 64 def concerns @concerns end |
Class Method Details
.concerned_with(*behaviors) ⇒ Object
67 68 69 70 |
# File 'lib/slickr/reactor.rb', line 67 def self.concerned_with(*behaviors) @concerns ||= [] @concerns += behaviors end |
Instance Method Details
#call(*args) ⇒ Object
72 73 74 |
# File 'lib/slickr/reactor.rb', line 72 def call(*args) raise NotImplementedError end |
#entities ⇒ Object
76 77 78 |
# File 'lib/slickr/reactor.rb', line 76 def entities EntityManager.entities_with(*concerns) end |