Enums
Enum Houd een state bij 'Uitgebreide boolean'; ipv 2 states (True, false) meerdere states Enum UnitState { IDLE, DEFENSIVE, AGRESSIVE} Public UnitState currentEnemyState = UnitState.IDLE;
StateMachine
State machine Functionaliteit afspelen aan de hand van de gekozen state Enum UnitState { IDLE, DEFENSIVE, AGRESSIVE} private UnitState currentEnemyState = UnitState.IDLE; if(currentEnemyState == UnitState.IDLE){ //in idle state MoveAtRandom(); }else if(currentEnemyState == UnitState.DEFENSIVE){ //in defensiveState ActivatedShieldBarrier(); }else if(currentEnemyState == UnitState.AGRESSIVE){ //aggressiveState RunTowardPlayer(); }
StateMachine Class Enemy{ Enum UnitState { IDLE, DEFENSIVE, AGRESSIVE} Public UnitState currentEnemyState = UnitState.IDLE; const float SPEED_AGGRESSIVE = 10; const float SPEED_IDLE = 3; float movementSpeed = 5; public void Update(){ //heeft een bepaald gedrag gebaseerd op unitState; //zie vorige slide } public void SetEnemyState(UnitState newState){ currentEnemyState = newState; //set initial settings if(currentEnemyState == UnitState.IDLE){ movementSpeed = SPEED_IDLE; }else if(currentEnemyState == UnitState.AGRESSIVE){ movementSpeed = SPEED_AGGRESSIVE; } }