2
\$\begingroup\$

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

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

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.

\$\endgroup\$
15
  • \$\begingroup\$ 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? \$\endgroup\$ May 10, 2013 at 15:15
  • \$\begingroup\$ You're thinking too complicated. I'll edit my answer to be a little more clear. \$\endgroup\$
    – House
    May 10, 2013 at 15:27
  • \$\begingroup\$ @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. \$\endgroup\$ May 10, 2013 at 15:33
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – House
    May 10, 2013 at 17:34
  • 1
    \$\begingroup\$ "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. \$\endgroup\$ May 10, 2013 at 19:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .