Example usage for com.badlogic.gdx.ai.fsm DefaultStateMachine DefaultStateMachine

List of usage examples for com.badlogic.gdx.ai.fsm DefaultStateMachine DefaultStateMachine

Introduction

In this page you can find the example usage for com.badlogic.gdx.ai.fsm DefaultStateMachine DefaultStateMachine.

Prototype

public DefaultStateMachine(E owner) 

Source Link

Document

Creates a DefaultStateMachine for the specified owner.

Usage

From source file:com.mygdx.game.objects.HumanCharacter.java

License:Apache License

public HumanCharacter(Model model, String name, Vector3 location, Vector3 rotation, Vector3 scale,
        btCollisionShape shape, float mass, short belongsToFlag, short collidesWithFlag, boolean callback,
        boolean noDeactivate, Array<BlenderEmpty> ragdollEmpties, String armatureNodeId) {

    super(model, name, location, rotation, scale, shape, mass, belongsToFlag, collidesWithFlag, callback,
            noDeactivate, ragdollEmpties, armatureNodeId, new HumanSteerSettings());

    // Create path follower
    followPathSteerer = new FollowPathSteerer(this);

    // Create the animation controllers
    animations = new AnimationController(modelInstance);
    // Create animation listeners for states that need one
    stateAnimationListeners = new EnumMap<HumanState, AnimationListener>(HumanState.class);
    stateAnimationListeners.put(HumanState.THROW, new AnimationListener());

    // Create the state machine
    stateMachine = new DefaultStateMachine<HumanCharacter, HumanState>(this);
    // Set the steering variables associated with default move state (walking)
    stateMachine.changeState(moveState);
    // Then make the character idle
    stateMachine.changeState(moveState.idleState);
}

From source file:toniarts.openkeeper.world.creature.CreatureControl.java

License:Open Source License

public CreatureControl(Thing.Creature creatureInstance, Creature creature, WorldState worldState,
        short playerId, short level) {
    super(creature);
    stateMachine = new DefaultStateMachine<CreatureControl, CreatureState>(this) {

        @Override//from  w w w.j  a v a2  s .  c om
        public void changeState(CreatureState newState) {
            super.changeState(newState);

            // Notify
            onStateChange(CreatureControl.this, newState, getPreviousState());

        }

    };
    this.worldState = worldState;

    // Attributes
    name = Utils.generateCreatureName();
    bloodType = Utils.generateBloodType();
    this.level = level;
    ownerId = playerId;
    setAttributesByLevel();
    health = maxHealth;
    if (creatureInstance != null) {
        gold = creatureInstance.getGoldHeld();
        if (creatureInstance instanceof KeeperCreature) {
            health = (int) (((KeeperCreature) creatureInstance).getInitialHealth() / 100f * health);
            this.level = ((KeeperCreature) creatureInstance).getLevel();
            ownerId = ((KeeperCreature) creatureInstance).getPlayerId();
        } else if (creatureInstance instanceof GoodCreature) {
            health = (int) (((GoodCreature) creatureInstance).getInitialHealth() / 100f * health);
            this.level = ((GoodCreature) creatureInstance).getLevel();
            ownerId = Player.GOOD_PLAYER_ID;
            objective = ((GoodCreature) creatureInstance).getObjective();
            if (((GoodCreature) creatureInstance).getObjectiveTargetActionPointId() != 0) {
                objectiveTargetActionPoint = worldState.getGameState().getActionPointState()
                        .getActionPoint(((GoodCreature) creatureInstance).getObjectiveTargetActionPointId());
            }
            flags = ((GoodCreature) creatureInstance).getFlags();
        } else if (creatureInstance instanceof NeutralCreature) {
            health = (int) (((NeutralCreature) creatureInstance).getInitialHealth() / 100f * health);
            this.level = ((NeutralCreature) creatureInstance).getLevel();
            ownerId = Player.NEUTRAL_PLAYER_ID;
        } else if (creatureInstance instanceof DeadBody) {
            ownerId = ((DeadBody) creatureInstance).getPlayerId();
        }
    }
}