Package com.teamjmonkey.ai.aggro

Source Code of com.teamjmonkey.ai.aggro.AggroBehaviorStare

package com.teamjmonkey.ai.aggro;

import com.jme3.scene.Spatial;
import com.teamjmonkey.controls.MoveRandomControl;

public class AggroBehaviorStare extends AggroBehaviorBase {

    private float speed;

    public AggroBehaviorStare(float speed) {
        this.speed = speed;
    }

    public void onAggro(Spatial target) {
        interruptOtherActions();
        entity.lookAt(target.getLocalTranslation(), speed, false);
    }

    private void interruptOtherActions() {
        MoveRandomControl mrc = spatial.getControl(MoveRandomControl.class);
        if (mrc != null) {
            mrc.pause();
        }
    }

    private void resumeOtherActions() {
        MoveRandomControl mrc = spatial.getControl(MoveRandomControl.class);
        if (mrc != null) {
            mrc.resume();
        }
    }

    public void onAggroLoss() {
        resumeOtherActions();
    }

    public void update(float tpf, Spatial target, boolean hasOtherAggroType) {
        if (!hasOtherAggroType) {
            entity.lookAt(target.getLocalTranslation(), speed, false);
        }
    }
}
TOP

Related Classes of com.teamjmonkey.ai.aggro.AggroBehaviorStare

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.