Package game.actors

Source Code of game.actors.SoldierActor

package game.actors;

import engine.geometry.Rectangle;
import engine.geometry.Vector;
import engine.hierarchy.DefaultActor;
import game.habits.AnimationHabit;
import game.habits.DynamicHabit;
import game.habits.GravityHabit;
import game.habits.HurtHabit;
import game.habits.MetalHabit;
import game.habits.PatrolHabit;
import game.habits.PlatformCharacterAnimationHabit;
import game.habits.PlatformCharacterMovementHabit;
import game.habits.PlatformCharacterStateHabit;

public class SoldierActor extends DefaultActor implements HurtHabit.Listener {
    private Vector startPosition;
    private PlatformCharacterStateHabit state;

    public SoldierActor(Vector startPosition) {
        this.startPosition = startPosition;
    }

    @Override
    protected void onAdd() {
        AnimationHabit animation = addHabit(new AnimationHabit());
        DynamicHabit dynamic =
                addHabit(new DynamicHabit(new Rectangle(startPosition, new Vector(24, 48)).toPolygon(), 60));
        addHabit(new GravityHabit(dynamic));
        state = addHabit(new PlatformCharacterStateHabit(dynamic));
        addHabit(new PatrolHabit(state));
        addHabit(new PlatformCharacterAnimationHabit("soldier", 52, animation, state));
        addHabit(new PlatformCharacterMovementHabit(state, dynamic, animation));
        addHabit(new HurtHabit(this, dynamic.getPolygon()));
        addHabit(new MetalHabit(dynamic));
    }

    @Override
    public void onHurt(HurtHabit hurt) {
        state.attack();
    }
}
TOP

Related Classes of game.actors.SoldierActor

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.