In the below code is the way I create a character in Entity System. But I think this is the decouple, I'm having hard time decoupling this class.
1st approach
public enum CharacterType {
PLAYER_CHARACTER, // PC or a character controlled by a player
NON_PLAYER_CHARACTER // NPC or a character controlled by a computer it self (artificial intelligence), but notice that it is a friendly character
}
public class Character {
// Player-Character can be controlled by the player it self
// None-Player-Character is a autonomous and cannot be controlled
// Player-Enemy target a player-character
// Player-Allied target a player-enemy and friendly to a player-character
// All character is moving
CharacterType type
CharacterMovement movement
}
// or
public class PlayerCharacter extends Character {
}
public class NonPlayerCharacter extends Character {
}
public class Merchant extends NonPlayerCharacter {
}
public class Enemy extends Character {
}
public class CharacterComponent implements Component {
public Character character;
}
2nd approach
public class PlayerComponent implements Component {
public static final int IDLE = 0;
public static final int MOVE_UP = 1;
...
}
public class NonePlayerComponent implements Component {
public static final int IDLE = 0;
public static final int MOVE_UP = 1;
...
}
public class EnemyPlayerComponent implements Component {
public static final int IDLE = 0;
public static final int MOVE_UP = 1;
...
}
public class AlliedPlayerComponent implements Component {
public static final int IDLE = 0;
public static final int MOVE_UP = 1;
...
}
Noticed in the 2nd approach that it has a redundant data.