New actors may be created from scratch, using energy from the world, or may be created from existing actors, using a aprt of their energy.
For the first method to work we have to set-up factories as in the previous example. We ammend the ActorFactory to create a more interesting actor. This is the new constructor:
We're initialising the DNA our factory holds arround with a kind (IdKind), a running cost (1), an average life span (100) and the energy required at birth (10). As previously stated, this energy must come from the world or from the parents.
Once we have a valid DNA instance we add the brain, actuator, reflex and sensor to the DNA sequence. Any actor created by this factory will have these components (if they can be created).
Now, after we have a valid world we can create a new actor from scratch like so:
This is what happens inside:
Do not forget to release the reference that is passed to the caller by World::createActor().
Example 6 - Factories | april-core library | Example 8 - Events and event lines |