1
\$\begingroup\$

In the below code, there's a FSM for CharacterState that will be handled also in CharacterSystem. The problem was, I don't know what component should hold movements data to process in CharacterState or CharacterSystem

public class CharacterState implements State<Entity> {
    STANDING,
    WALKING,
    RUNNING,
    IN_PAIN,
    DEAD
}

public enum Movements {
    STAND_STILL,
    MOVE_UP,
    MOVE_DOWN,
    MOVE_LEFT,
    MOVE_RIGHT,
    MOVE_UP_RIGHT,
    MOVE_UP_LEFT,
    MOVE_DOWN_RIGHT,
    MOVE_DOWN_LEFT;
}

CharacterComponent implements Component {
    Movements movement
}

MovementComponent implements Component {
    Movements movement
}

AnimationComponent implements Component {
    IntMap<Animation> map = new IntMap<Animation>();
}

animation.map.put(Movements.MOVE_UP.order, ASSET.CHAR_MOVE_UP);
\$\endgroup\$
1
\$\begingroup\$

I would suggest creating a new class just for holding the data if you are sure that the data belongs to multiple classes. Otherwise you can face tight coupling issues.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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