Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am writing a pong clone with a component based entity system. But I am having trouble with the different kinds of movement in the game.

The problem is the following: My paddles will just move up and down, so I only need a Y-velocity for these. But the ball can move in each direction. So the ball will need an angle and a velocity. Now my question is: Is it usual to put the data for moving a ball in another component than the data for moving a paddle? Because if I would do so, I would need two systems just for movement. Is that a good approach?

A little bit information about my system: My entites are only IDs. I have an entity manager which holds all the entities and the linked components. Components only hold certain data on which systems operate. Basically I am using this approach: Tutorial

share|improve this question

1 Answer 1

up vote 4 down vote accepted

They should use the same movement component for both, if the movement component is velocity. However, the systems that modify the velocity will be different. The ball will use the physics component to bounce off the paddles and walls, where the paddles will use the mouse/keyboard input component to move. So the physics system will be modifying the movement component of the ball, and the input system will be modifying the movement component of the paddles. The paddles won't use the x-axis for movement, but that's OK.

The will both use the movement system. The movement system will take their movement components and update their position components.

share|improve this answer
    
The physics, so the collisions is not the problem. And the problem is as well not, that the paddles would not use the x component. The problem is, that if I give them both the same component for movement, than the movement system will handle them both equal. But: The ball needs movement by an angle, the paddles not. And as my components are just data container and my systems are operating independently from WHAT the entity is, but only on the components, that would not be possible. Or am I thinking too complicated? –  M0rgenstern May 10 '13 at 15:15
    
You're thinking too complicated. I'll edit my answer to be a little more clear. –  Byte56 May 10 '13 at 15:27
    
@Byte56 set you straight, the design trick will be to use systems that key on more than just one component to set up like described. –  Patrick Hughes May 10 '13 at 15:33
1  
The movement system is just taking the velocity and applying it to the position. How the velocity is set will depend on what the physics and input system set them to. –  Byte56 May 10 '13 at 17:34
1  
"system is just taking the velocity and applying it to the position. How the velocity is set will depend on what the physics and input system" Is a very important concept to learn (and very not-OOP) and will keep you from creating many super-specialized and complex systems when simple systems working in concert will both get the job done and increase flexibility instead of locking you in even deeper. –  Patrick Hughes May 10 '13 at 19:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.