I'd like some suggestions regarding how to implement the programmer/scripter interface for building entities in my game. I know what the interaction should be, and what the classes are going to be. I just want some suggestions for a clean and pythonic interface to initialize these classes.
My requirements are:
The game has a component-based entity system; each Entity
holds two types of components, Attribute
and Behavior
. An Attribute is some 'dumb' data (like the entity's position, inventory, etc) and a Behavior defines, basically, some processing done on that data (movement, physics, and also how to render the entity on the screen).
Behaviors never directly communicate with each other. They only communicate indirectly through what values the Attribute components hold. What Attributes each Behavior needs is decided upon the Behavior's creation (or soon after).
Here's some example code:
hero = Entity("Hero")
# Attributes
hero[Position] = Position(0.0, 8.0)
hero[Mass] = Mass(75)
# Behaviors
move = Movement(hero[Position])
sprite = Sprite(hero[Position])
physics = Physics(hero[Mass])
hero.add(move)
hero.add(sprite)
hero.add(physics)
This is just an example; it is a simplification of what I have now and I think it's ugly and cumbersome. You can suggest any kind of interface to me. Maybe the Attributes are set in the Entity's constructor, instead of after construction, for example.