public void setState(IHobgoblinState state) { if (previousState != null) { previousState = currentState; previousState.Exit(); } else { previousState = state; } state.Enter(); currentState = state; AddDebugText("Current state: " + currentState, 0); AddDebugText("Previous state: " + previousState, 1); }
public Hobgoblin(string name, Vector2D pos, World w, MovingEntity Target) : base(name, pos, w) { // State. hunting = new Hunting(this); retreating = new Retreating(this); guarding = new Guarding(this); wandering = new Wandering(this); command = new Command(this); equip = new Equip(this); setState(guarding); // Starting state. Key = _lastKey + 1; _lastKey++; debugText = new List <string>(); Mass = 100; MaxSpeed = 5; MaxForce = 40; DamagePerAttack = 25; AttackRange = 20; AttackSpeed = 30; // Lower is faster. CurrentCommand = 3; // Default command. CommandRadius = 125; // Size of area where goblins will respond to commanding. SlowingRadius = 100; PanicDistance = 200; // Distance at which hobgoblin starts fleeing. PassiveDistance = 250; // Distance at which hobgoblin goes to guard. _SB = new ArrivalBehaviour(me: this, target: Target, slowingRadius: SlowingRadius); _FleeB = new FleeBehaviour(me: this, target: Target, panicDistance: PanicDistance); _OA = new ObstacleAvoidance(this); _WA = new WallAvoidance(this); _WB = new WanderBehaviour(this, 100, 200); Velocity = new Vector2D(0, 0); SlowingRadius = 100; Scale = 10; VColor = Color.Black; AddDebugText("Current state: " + currentState, 0); AddDebugText("Previous state: " + previousState, 1); }