Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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.

share

migration rejected from stackoverflow.com Jul 15 '14 at 23:47

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as off-topic by Jamal Jul 15 '14 at 23:47

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must involve real code that you own or maintain. Questions seeking an explanation of someone else's code are off-topic. Pseudocode, hypothetical code, or stub code should be replaced by a concrete example." – Jamal
If this question can be reworded to fit the rules in the help center, please edit the question.