void sheets_0() {
		text.text = "You can't believe you sleep in these things. Surely it's " +
					"time somebody changed them. The pleasures of prison life " +
					"I guess!\n\n" +
					"Press R to Return to roaming your cell" ;
		if (Input.GetKeyDown(KeyCode.R)) {myState = States.cell;}
	}
 void OnStateChange(States before, States after) {
   if ((before & States.Ladder) == States.Ladder &&
       (after & States.OnGround) == States.OnGround) {
     aiInput.SetY(0);
     aiInput.SetX((float)facing);
   }
 }
 void coat_room_0()
 {
     text.text = "An apathetic hipster asks you for your ticket. " +
                 "You realize you gave your tickets to your date to hold. \n\n" +
                 "Press P to Return to return to the Party.";
     if (Input.GetKeyDown(KeyCode.P)) {myState = States.party_0;}
 }
	void lock_0() {
		text.text = "This is one of those button locks. You have no idea what the " +
					"combination is. You wish you could somehow see where the dirty " +
					"fingerprints were, maybe that would help.\n\n" +
					"Press R to Return to roaming your cell" ;
		if (Input.GetKeyDown(KeyCode.R)) {myState = States.cell;}
	}
Beispiel #5
0
 protected override void move()
 {
     if (Camera.main.gameObject.transform.position.y + 5f <= transform.position.y)
         transform.Translate (new Vector3 (0f, Time.deltaTime * 5f, 0f));
     else
         state = States.Phase1;
 }
    void bar_1()
    {
        text.text = "Still don't have your wallet. That whiskey must be kicking in. \n\n" +
                    "Press B to go back.";

        if (Input.GetKeyDown(KeyCode.B)) {myState = States.party_1;}
    }
    void bar_2()
    {
        text.text = "The bar is really crowded now. It takes a while, but you finally settle your tab. \n\n" +
                    "Press B to go back to your date";

        if (Input.GetKeyDown(KeyCode.B)) {myState = States.date_2;}
    }
Beispiel #8
0
 void cell()
 {
     text.text = "Press S to Sheet -- M to Mirror -- L to Lock \n";
     if (Input.GetKeyDown(KeyCode.S))      {myState = States.sheet_0;}
     else if (Input.GetKeyDown(KeyCode.M)) {myState = States.mirror;}
     else if (Input.GetKeyDown(KeyCode.L)) {myState = States.lock_0;}
 }
Beispiel #9
0
		// --- constructors ---
		
		/// <summary>Creates a new instance of this system with default parameters.</summary>
		/// <param name="train">The train.</param>
		internal AtsSx(Train train) {
			this.Train = train;
			this.State = States.Disabled;
			this.AlarmCountdown = 0.0;
			this.SpeedCheckCountdown = 0.0;
			this.RedSignalLocation = 0.0;
		}
 public BankFish(PurchaseList P)
 {
     State = States.WriteP;
     Pu = P;
     InitializeComponent();
     Btn_Edit.Enabled = Btn_Delete.Enabled = false;
 }
 public BankFish(Project P)
 {
     State = States.WritePro;
     Pro = P;
     InitializeComponent();
     Btn_Edit.Enabled = Btn_Delete.Enabled = false;
 }
 public BankFish(Credit C)
 {
     State = States.WriteC;
     Cr = C;
     InitializeComponent();
     Btn_Edit.Enabled = Btn_Delete.Enabled = false;
 }
 public BankFish(Factor F)
 {
     State = States.WriteF;
     Fa = F;
     InitializeComponent();
     Btn_Edit.Enabled = Btn_Delete.Enabled = false;
 }
Beispiel #14
0
        public virtual bool Apply(States.ZombieState state)
        {
            this.Timer.Start();

            if (!(state is States.Death) && GetZombieColds(state.Zombie) == 0)
            {
                state.Image.Color = GMath.GammaBlend(state.Image.Color, Color.Blue, 0.5f);
                state.Image.Delay = (long)(state.Image.Delay / ColdAffect);

                States.Walk walk = state as States.Walk;
                if (walk != null)
                {
                    walk.Velocity *= ColdAffect;
                }

                States.Attack att = state as States.Attack;
                if (att != null)
                {
                    att.AttackTimer.Interval = TimeSpan.FromMilliseconds(att.AttackTimer.Interval.TotalMilliseconds / ColdAffect);
                }

                return true;
            }

            return false;
        }
        public decimal Calculate(decimal price, States state, string zip)
        {
            decimal taxPrice = default(decimal);
            // Call Real Web Service to determine the Sales Tax.
            switch (state)
            {
                case States.Arizona:
                    taxPrice = CalculateTaxPriceInternal(price, 7.125, zip);
                    break;
                case States.Illinois:
                    taxPrice = CalculateTaxPriceInternal(price, 3.75, zip);
                    break;
                case States.Massachusetts:
                    taxPrice = CalculateTaxPriceInternal(price, 6.25, zip);
                    break;
                case States.California:
                    taxPrice = CalculateTaxPriceInternal(price, 2.50, zip);
                    break;
                case States.Washington:
                    taxPrice = CalculateTaxPriceInternal(price, 3.10, zip);
                    break;
                case States.NewJersey:
                    taxPrice = CalculateTaxPriceInternal(price, 7.00, zip);
                    break;
                case States.Texas:
                    taxPrice = CalculateTaxPriceInternal(price, 8.15, zip);
                    break;
                default:
                    taxPrice = 0;
                    break;
            }

            return taxPrice;
        }
Beispiel #16
0
 void corridor_2()
 {
     text.text = "Back in the corridor, having declined to dress-up as a cleaner.\n\n" +
         "Press C to revisit the Closet, and S to climb the stairs";
     if (Input.GetKeyDown(KeyCode.C)) {myState = States.in_closet;}
     else if (Input.GetKeyDown(KeyCode.S)) {myState = States.stairs_2;}
 }
Beispiel #17
0
 public static void QuitLobby()
 {
     MultiPlayer.Shutdown("Game", string.Empty);
     Players = null;
     Timers.Remove("Positions");
     State = States.MainMenu;
 }
Beispiel #18
0
 public Egg(SpriteManager cm,int id, int x, int y)
 {
     pos = new Point(x, y);
     this.id = id;
     this.egg = cm.GetSprite("Players/Egg");
     this.st = States.IDLE;
 }
Beispiel #19
0
 void closet_door()
 {
     text.text = "You are looking at a closet door, unfortunately it's locked. " +
         "Maybe you could find something around to help enourage it open?\n\n" +
             "Press R to Return to the corridor";
     if (Input.GetKeyDown(KeyCode.R)) {myState = States.corridor_0;}
 }
	void courtyard () {
		text.text = "You walk through the courtyard dressed as a cleaner. " +
					"The guard tips his hat at you as you waltz past, claiming " +
					"your freedom. You heart races as you walk into the sunset.\n\n" +
					"Press P to Play again." ;
		if 		(Input.GetKeyDown(KeyCode.P)) 	{myState = States.cell;}
	}
 void OnGUI()
 {
     if(GUILayout.Button("NEXT STATE"))
     {
         if(currentState == States.START)
         {
             currentState = States.PLAYERCHOICE;
         }
         else if (currentState == States.PLAYERCHOICE)
         {
             currentState = States.ENEMYCHOICE;
         }
         else if (currentState == States.ENEMYCHOICE)
         {
             currentState = States.LOSE;
         }
         else if (currentState == States.LOSE)
         {
             currentState = States.WIN;
         }
         else if (currentState == States.WIN)
         {
             currentState = States.START;
         }
     }
 }
	void in_closet() {
		text.text = "Inside the closet you see a cleaner's uniform that looks about your size! " +
					"Seems like your day is looking-up.\n\n" +
					"Press D to Dress up, or R to Return to the corridor";
		if 		(Input.GetKeyDown(KeyCode.R)) 	{myState = States.corridor_2;}
		else if (Input.GetKeyDown(KeyCode.D)) 	{myState = States.corridor_3;}
	}
 public Check(Factor F)
 {
     State = States.WriteF;
     F1 = F;
     InitializeComponent();
     Btn_Edit.Enabled = Btn_Delete.Enabled = false;
 }
Beispiel #24
0
 public Cutscene(States a_backState, String a_sceneToLoad)
 {
     m_backState = a_backState;
     m_comDone = 0;
     m_filePath = a_sceneToLoad;
     m_waitingForKey = false;
 }
 public Check(Credit Cr)
 {
     State = States.WriteC;
     Cr1 = Cr;
     InitializeComponent();
     Btn_Edit.Enabled = Btn_Delete.Enabled = false;
 }
Beispiel #26
0
	void Wait() {
		waitTimer += Time.deltaTime;
		if(waitTimer > waitTime) {
			waitTimer = 0.0f;
			currentState = States.Moving;
		}
	}
Beispiel #27
0
        public virtual void ChangeState(States.ZombieState currentState, States.ZombieState lastState)
        {
            lastState.Image.Color = GMath.DeGammaBlend(lastState.Image.Color, Color.Red, 0.5f);

            if (!(currentState is States.Death))
                currentState.Image.Color = GMath.GammaBlend(currentState.Image.Color, Color.Red, 0.5f);
        }
        public bool AcceptChar(char c)
        {
            switch (_state)
            {

                case States.STATE0:

                    if (-1 == ("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.@_-~#").IndexOf(c))
                    {
                        _state = States.STATE1;
                        return true;
                    }
                    //throw new Exception("Invalid input character");
                    return false;

                case States.STATE1:

                    if (-1 == ("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.@_-~#").IndexOf(c))
                    {
                        _state = States.STATE1;
                        return true;
                    }
                    return false;

                default:
                    //throw new Exception("Invalid state value");
                    return false;
            }
        }
Beispiel #29
0
	void Start() {
		waitTimer = 0.0f;
		circleCenter = transform.position + new Vector3(0, 0, offset);
		currentTargetPosition = transform.position;
		//currentTargetPosition = FindNewTargetPosition();
		currentState = States.Moving;
	}
	void corridor_3() {
		text.text = "You're standing back in the corridor, now convincingly dressed as a cleaner. " +
					"You strongly consider the run for freedom.\n\n" +
					"Press S to take the Stairs, or U to Undress";
		if 		(Input.GetKeyDown(KeyCode.S)) 	{myState = States.courtyard;}
		else if (Input.GetKeyDown(KeyCode.U)) 	{myState = States.in_closet;}
	}
Beispiel #31
0
 // Use this for initialization
 void Start()
 {
     myState = States.cell;
 }
Beispiel #32
0
 void OnExitToMenu(States oldState, States newState)
 {
     currentInput = menuInput;
     OnPrintListOfCommands();
 }
Beispiel #33
0
 void OnNewGame(States oldState, States newState)
 {
     currentInput = gameInput;
     Engine.CreateNewGame();
     Console.WriteLine("Welcome to the GameOfHomes! Type 'list' for a list of commands");
 }
Beispiel #34
0
        public bool AcceptChar(char c)
        {
            switch (_state)
            {
            case States.STATE0:
                if (-1 != ("w").IndexOf(c))
                {
                    _state = States.STATE10;
                    return(true);
                }
                return(false);

            case States.STATE1:
                if (-1 != ("t").IndexOf(c))
                {
                    _state = States.STATE2;
                    return(true);
                }
                //throw new Exception("Invalid input character");
                return(false);

            case States.STATE2:
                if (-1 != ("t").IndexOf(c))
                {
                    _state = States.STATE3;
                    return(true);
                }
                //throw new Exception("Invalid input character");
                return(false);

            case States.STATE3:
                if (-1 != ("p").IndexOf(c))
                {
                    _state = States.STATE4;
                    return(true);
                }
                //throw new Exception("Invalid input character");
                return(false);

            case States.STATE4:
                if (-1 != ("s").IndexOf(c))
                {
                    _state = States.STATE5;
                    return(true);
                }

                if (-1 != (":").IndexOf(c))
                {
                    _state = States.STATE7;
                    return(true);
                }
                //throw new Exception("Invalid input character");
                return(false);

            case States.STATE5:
                if (-1 != (":").IndexOf(c))
                {
                    _state = States.STATE7;
                    return(true);
                }
                //throw new Exception("Invalid input character");
                return(false);

            case States.STATE6:

                //throw new Exception("Invalid input character");
                return(false);

            case States.STATE7:
                if (-1 != ("/").IndexOf(c))
                {
                    _state = States.STATE8;
                    return(true);
                }
                //throw new Exception("Invalid input character");
                return(false);

            case States.STATE8:

                if (-1 != ("/").IndexOf(c))
                {
                    _state = States.STATE0;
                    return(true);
                }
                //throw new Exception("Invalid input character");
                return(false);

            case States.STATE9:

                if (-1 != ("h").IndexOf(c))
                {
                    _state = States.STATE1;
                    return(true);
                }

                if (-1 != ("f").IndexOf(c))
                {
                    _state = States.STATE2;
                    return(true);
                }

                if (-1 != ("w").IndexOf(c))
                {
                    _state = States.STATE10;
                    return(true);
                }

                if (-1 != ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789").IndexOf(c))
                {
                    _state = States.STATE12;
                    return(true);
                }

                //throw new Exception("Invalid input character");
                return(false);

            case States.STATE10:
                if (-1 != ("w").IndexOf(c))
                {
                    _state = States.STATE11;
                    return(true);
                }
                return(false);

            case States.STATE11:
                if (-1 != ("w").IndexOf(c))
                {
                    _state = States.STATE12;
                    return(true);
                }
                return(false);

            case States.STATE12:
                if (-1 != (".").IndexOf(c))
                {
                    _state = States.STATE13;
                    return(true);
                }
                return(false);

            case States.STATE13:
                if (-1 != ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.").IndexOf(c))
                {
                    _state = States.STATE14;
                    return(true);
                }
                return(false);

            case States.STATE14:
                if (-1 != ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.").IndexOf(c))
                {
                    _state = States.STATE14;
                    return(true);
                }
                if (-1 != (".").IndexOf(c))
                {
                    _state = States.STATE15;
                    return(true);
                }
                return(false);

            case States.STATE15:
                if (-1 != ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").IndexOf(c))
                {
                    _state = States.STATE16;
                    return(true);
                }
                return(false);

            case States.STATE16:
                if (-1 != ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").IndexOf(c))
                {
                    _state = States.STATE17;
                    return(true);
                }
                return(false);

            case States.STATE17:
                if (-1 != ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").IndexOf(c))
                {
                    _state = States.STATE18;
                    return(true);
                }

                if (-1 != (":").IndexOf(c))
                {
                    _state = States.STATE21;
                    return(true);
                }
                if (-1 != ("/").IndexOf(c))
                {
                    _state = States.STATE23;
                    return(true);
                }
                return(false);

            case States.STATE18:
                if (-1 != ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").IndexOf(c))
                {
                    _state = States.STATE19;
                    return(true);
                }
                return(false);

            case States.STATE19:
                if (-1 != ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").IndexOf(c))
                {
                    _state = States.STATE20;
                    return(true);
                }
                return(false);

            case States.STATE20:
                if (-1 != ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").IndexOf(c))
                {
                    _state = States.STATE17;
                    return(true);
                }
                return(false);

            case States.STATE21:
                if (-1 != ("0123456789").IndexOf(c))
                {
                    _state = States.STATE21;
                    return(true);
                }
                if (-1 != (":").IndexOf(c))
                {
                    _state = States.STATE17;
                    return(true);
                }
                return(false);

            case States.STATE23:
                if (-1 != ("$").IndexOf(c))
                {
                    _state = States.STATE24;
                    return(true);
                }
                if (-1 != ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,;?'\\+&%$#").IndexOf(c))
                {
                    _state = States.STATE17;
                    return(true);
                }

                return(false);

            case States.STATE24:
                if (-1 != ("$").IndexOf(c))
                {
                    _state = States.STATE24;
                    return(true);
                }
                return(false);

            case States.STATE25:
                if (-1 != ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,;?'\\+&%$#").IndexOf(c))
                {
                    _state = States.STATE25;
                    return(true);
                }
                return(false);

            default:
                //throw new Exception("Invalid state value");
                return(false);
            }
        }
Beispiel #35
0
 public void Reset()
 {
     _state = States.STATE9;
 }
Beispiel #36
0
        public override void Activate()
        {
            if (state != States.Active)
            {
                pendingState             = States.Active;
                BokuGame.objectListDirty = true;

                Editor editor = InGame.inGame.Editor;
                if (editor.Active)
                {
                    HelpOverlay.Push(@"PieSelectorProgrammingNoSelection");
                }
                else
                {
                    HelpOverlay.Push(@"PieSelectorAddItemNoSelection");
                }

                if (SelectWater || SetWater)
                {
                    WaterPicker waterPicker = InGame.inGame.shared.ToolBox.WaterPicker;

                    holdOnGet  = waterPicker.OnGetType;
                    holdOnSet  = waterPicker.OnSetType;
                    holdOnPick = waterPicker.OnPickType;

                    waterPicker.OnGetType  = OnGetWater;
                    waterPicker.OnSetType  = OnSetWater;
                    waterPicker.OnPickType = OnPickWater;

                    typePicker = waterPicker;
                    if (SetWater)
                    {
                        lastWaterIndex = RootData.SetWaterTypeIndex;
                    }
                    else
                    {
                        lastWaterIndex = RootData.WaterType;
                    }

                    if (lastWaterIndex < 0)
                    {
                        lastWaterIndex = Water.CurrentType;
                    }
                }
                else
                {
                    MaterialPicker matPicker = InGame.inGame.shared.ToolBox.MaterialPicker;

                    holdOnGet  = matPicker.OnGetType;
                    holdOnSet  = matPicker.OnSetType;
                    holdOnPick = matPicker.OnPickType;

                    matPicker.OnGetType     = OnGetTerrain;
                    matPicker.OnSetType     = OnSetTerrain;
                    matPicker.OnPickType    = OnPickTerrain;
                    matPicker.UseAltOverlay = true;

                    typePicker = matPicker;

                    ushort rootDataMatIdx = (ushort)RootData.MaterialType;
                    if (TerrainMaterial.IsValid(rootDataMatIdx, false, false))
                    {
                        lastTerrainIndex = rootDataMatIdx;
                    }
                    else if (!TerrainMaterial.IsValid(lastTerrainIndex, false, false))
                    {
                        lastTerrainIndex = Terrain.CurrentMaterialIndex;
                    }
                }
                typePicker.Active = true;
                typePicker.Hidden = false;
            }
        }
Beispiel #37
0
 // Use this for initialization
 void Start()
 {
     initializeVariables();
     myState = States.level_start;
 }
        void Perception()
        {
            RaycastHit hit;

            enemyInSight = false;
            enemysInRange.RemoveAll(e => e.entity == null || e.entity.transform == null);
            // por cada enemigo en la escena
            foreach (var item in enemysInRange)
            {
                // verifica si el enemigo no existe
                if (item == null || item.entity == null || item.entity.transform == null)
                {
                    break;
                }

                Vector3 itemDir = (item.entity.transform.position - gameObject.transform.position);
                // verifica el angulo del enemigo con respecto al actor
                float angle = Vector3.Angle(gameObject.transform.forward, itemDir);

                if (CalculatePathLength(item.entity.transform.position) <= perceptionRadius)
                {
                    //Debug.Log(item.entity.name + " PERCIBIDO!");
                }

                // si esta dentro del campo visual
                if (angle < (FOV * 0.5f))
                {
                    // busca el centro de masa asignado o sino el punto de posicion
                    Vector3 itemFollowingPos = Vector3.zero;
                    Vector3 aimHelperPos     = Vector3.zero;

                    Vehicle vehicleEnemy    = item.entity.GetComponent <Vehicle>();
                    Vehicle vehiclePersonal = GetComponent <Vehicle>();
                    if (vehicleEnemy != null)
                    {
                        itemFollowingPos = vehicleEnemy.centerOfMass.position;
                        aimHelperPos     = vehiclePersonal.aimHelper.position;
                    }
                    else
                    {
                        itemFollowingPos = item.entity.transform.position;
                        aimHelperPos     = transform.position;
                    }

                    Vector3 enemyDir = (itemFollowingPos - aimHelperPos);

                    // verifica que el enemigo se encuentre visible y en el rango de distancia
                    if (Physics.Raycast(aimHelperPos, enemyDir, out hit, perceptionRadius))
                    {
                        if (ShowLinesPerceptions)
                        {
                            Debug.DrawRay(aimHelperPos, enemyDir, new Color(Color.red.r, Color.red.g, Color.red.b, 0.15f), 0.1f);
                        }
                        if (item.entity.gameObject == hit.transform.gameObject)
                        {
                            if (ShowLinesPerceptions)
                            {
                                Debug.DrawRay(aimHelperPos, enemyDir, new Color(Color.green.r, Color.green.g, Color.green.b, 0.3f), 0.1f);
                            }
                            if (enemiesInFOV.Any(e => e.entity.Equals(item.entity)))
                            {
                                enemiesInFOV.Find(e => e.entity.Equals(item.entity)).Update(e => { e.entity = item.entity; e.distance = hit.distance; });
                            }
                            else
                            {
                                enemiesInFOV.Add(new Enemies()
                                {
                                    entity   = item.entity,
                                    distance = hit.distance
                                });
                            }
                        }
                    }
                }
            }

            if (enemiesInFOV.Count > 0)
            {
                // quita de la lista los que esten muertos
                enemiesInFOV.RemoveAll(e => e.entity == null || e.entity.transform == null);
                if (enemiesInFOV.Count > 0)
                {
                    // ordena los enemigos por distancia
                    enemiesInFOV = enemiesInFOV.OrderBy(e => e.distance).ToList();

                    // ajusta el estado y guarda la entidad del enemigo
                    if (state != States.Critical)
                    {
                        state = States.Chase;
                    }

                    entityFollowing      = enemiesInFOV.First().entity;
                    lastEnemySightingPos = entityFollowing.transform.position;

                    if (CalculatePathLength(entityFollowing.transform.position) <= perceptionRadius)
                    {
                        //Debug.Log(entityFollowing.name + " PERCIBIDO!");
                        personalLastSighting = entityFollowing.transform.position;
                    }
                }
            }
        }
            /************************************************************************************************************************/
            #region Enumeration
            /************************************************************************************************************************/
            // IEnumerable for 'foreach' statements.
            /************************************************************************************************************************/

            /// <summary>
            /// Returns an enumerator that will iterate through all states in each layer (not states inside mixers).
            /// </summary>
            public IEnumerator <KeyValuePair <object, AnimancerState> > GetEnumerator() => States.GetEnumerator();
        void Chasing(bool noChangeState = false)
        {
            // si el enemigo no esta muerto
            if (entityFollowing && entityFollowing.transform != null)
            {
                // si esta siguiendo a un enemigo
                if (state == States.Chase)
                {
                    if ((entityFollowing.transform.position - transform.position).sqrMagnitude > 4f)
                    {
                        navAgent.destination = entityFollowing.transform.position;
                    }

                    navAgent.speed = chaseSpeed;
                }

                // si pasa mucho tiempo sin contacto visual resetea el comportamiento
                if (timeLost > maxTimeLost)
                {
                    if (!noChangeState)
                    {
                        state = States.StandBy;
                    }
                    entityFollowing = null;
                    timeLost        = 0;
                }
                else
                {
                    // rota a la posicion del enemigo que esta siguiendo
                    Vector3 relativePos = entityFollowing.transform.position - gameObject.transform.position;
                    relativePos.y = 0;
                    if (state != States.Critical)
                    {
                        gameObject.transform.rotation = Quaternion.Slerp(gameObject.transform.rotation, Quaternion.LookRotation(relativePos), Time.deltaTime * turnSpeedOnChase);
                    }

                    // verifica el angulo del enemigo con respecto al actor
                    float angle = Vector3.Angle(gameObject.transform.forward, (entityFollowing.transform.position - gameObject.transform.position));

                    // si el enemigo esta dentro del rango de tiro
                    if (angle < (FOVForFire * 0.5f))
                    {
                        timeLost     = 0;
                        enemyInSight = true;
                    }
                    else
                    {
                        timeLost    += Time.deltaTime;
                        enemyInSight = false;
                    }
                }
            }
            else
            {
                if (!noChangeState)
                {
                    state = States.StandBy;
                }
                entityFollowing = null;
                timeLost        = 0;
            }

            if (allowFire)
            {
                foreach (LaserWeapon lw in shipControlComponent.laserWeapons)
                {
                    lw.firing = enemyInSight;
                    firing    = enemyInSight;
                }
            }
        }
 public StateMachine(GameObject entity, States currentState) : base(entity)
 {
     setCurrentState(currentState);
 }
        public virtual void Update()
        {
            if (ShowDebugMsgs && gameObject && navAgent && shipControlComponent)
            {
                Debug.Log("[" + gameObject.name + "]\nState=" + state + "\nEvade=" + evade + "\nSpeed=" + navAgent.speed + "\nMovement=" + shipControlComponent.emInput.movement);
            }

            if (lastEnemySightingPos != enemyPreviousSighting)
            {
                personalLastSighting = lastEnemySightingPos;
            }

            enemyPreviousSighting = lastEnemySightingPos;

            GoToRecharge();

            if (navAgent)
            {
                navAgent.baseOffset = Mathf.Lerp(navAgent.baseOffset, gameObject.GetComponent <Rigidbody>().velocity.y, Time.deltaTime);
                navAgent.height     = navAgent.baseOffset;
            }

            if (behavior == Behavior.Patrol && state == States.StandBy)
            {
                state = States.Patrol;
            }

            Perception();

            Evade(currentImpactHit);

            if (state == States.StandBy || state == States.Patrol)
            {
                switch (behavior)
                {
                case Behavior.Defender:
                    Defender();
                    break;

                case Behavior.Explorer:
                    Explorer();
                    break;

                case Behavior.Patrol:
                    Patrol();
                    break;
                }
            }
            else
            {
                if (state == States.Alert)
                {
                    OnAlert();
                }
                else if (state == States.Chase)
                {
                    Chasing();
                }
            }

            if (ShowNavPoints)
            {
                navAgent.destination.DebugCreateCircle(debugColor);
                Debug.DrawRay(gameObject.transform.position, (navAgent.destination - gameObject.transform.position), debugColor, 0.1f);
            }
        }
Beispiel #43
0
    public void ApplyBehaviourAttack(TypeEnemy whatType)
    {
        switch (whatType)
        {
        case TypeEnemy.Ghost:

            if (lookedThePlayer)
            {
                if (transform.position == posToChaseAndAttack)
                {
                    if (Vector3.Distance(transform.position, playerPos.transform.position) >= minimumDistanceToChase)
                    {
                        lookedThePlayer = false;
                        myCurrentState  = States.Idle;
                    }
                    else
                    {
                        alreadyPlaceTheTarget = false;
                    }
                }

                if (!alreadyPlaceTheTarget)
                {
                    float posX = playerPos.gameObject.transform.position.x - playerPos.gameObject.transform.localScale.x;
                    float posZ = playerPos.gameObject.transform.position.z - playerPos.gameObject.transform.localScale.z;

                    posToChaseAndAttack   = new Vector3(posX, 0, posZ);
                    posToChaseAndAttack.y = gameObject.transform.localScale.y + theTerrain.SampleHeight(posToChaseAndAttack);

                    alreadyPlaceTheTarget = true;
                }

                transform.position = Vector3.MoveTowards(transform.position, posToChaseAndAttack, speedEnemy * Time.deltaTime);
                transform.LookAt(posToChaseAndAttack, Vector3.up);

                Debug.Log("Distancia enemigo player = " + Vector3.Distance(transform.position, playerPos.transform.position));

                if (Vector3.Distance(transform.position, playerPos.transform.position) <= 1.5f)
                {
                    alreadyPlaceTheTarget = false;
                    lookedThePlayer       = false;
                    myCurrentState        = States.GoBack;
                }
            }
            else
            {
                randomPosCreated = false;
            }

            break;

        case TypeEnemy.Bomb:
            if (Physics.CheckSphere(transform.position, radiusDetectPlayer, player))
            {
                timeToExplode = true;
                playerEscapes = false;
            }
            else
            {
                playerEscapes = true;
            }
            if (timeToExplode)
            {
                if (timerToExplode <= timeUntilExplode)
                {
                    timerToExplode += Time.deltaTime;
                }
                else
                {
                    CreateExplosion();
                    if (!playerEscapes)
                    {
                        AttackPlayer();
                    }
                }
            }
            break;
        }
    }
 /// <summary>
 /// If a state is registered with the `key`, this method outputs it as the `state` and returns true. Otherwise
 /// `state` is set to null and this method returns false.
 /// </summary>
 public bool TryGet(object key, out AnimancerState state) => States.TryGetValue(key, out state);
 // Use this for initialization
 void Start()
 {
     myState = States.bedroom_0;
 }
 public void setCurrentState(States currentState)
 {
     p_myFirstTime    = false;
     p_myCurrentState = currentState;
 }
Beispiel #47
0
    private void FixedUpdate()
    {
        switch (state)
        {
        case States.PATROLLING:
            if (aggroScript.aggro == true && playerScript.isHidden == false)
            {
                state = States.FOLLOWING;
                break;
            }
            if (this.GetComponentInChildren <ObstacleDetection>().obstacle == true)
            {
                movingRight = !movingRight;
            }
            if (movingRight == true)
            {
                transform.eulerAngles = new Vector3(0, -180, 0);
            }
            else
            {
                transform.eulerAngles = new Vector3(0, 0, 0);
            }
            anima.SetBool("Idle", false);
            anima.SetBool("Running", true);
            transform.Translate(Vector2.left * speed * Time.deltaTime);
            break;

        case States.FOLLOWING:
            if (!aggroScript.aggro)
            {
                state = States.PATROLLING;
                return;
            }
            if (player.transform.position.x > transform.position.x - 2.5f && player.transform.position.x < transform.position.x + 2.5f)
            {
                if (player.transform.position.x > transform.position.x)
                {
                    movingRight           = true;
                    transform.eulerAngles = new Vector3(0, -180, 0);
                }
                else if (player.transform.position.x < transform.position.x)
                {
                    movingRight           = false;
                    transform.eulerAngles = new Vector3(0, 0, 0);
                }
                state = States.ATTACKING;
                return;
            }
            if (player.transform.position.x > transform.position.x + 2)
            {
                movingRight           = true;
                transform.eulerAngles = new Vector3(0, -180, 0);
            }
            if (player.transform.position.x < transform.position.x - 2)
            {
                movingRight           = false;
                transform.eulerAngles = new Vector3(0, 0, 0);
            }
            if (obstacle.obstacle == false)
            {
                anima.SetBool("Idle", false);
                anima.SetBool("Running", true);
                transform.Translate(Vector2.left * (speed * 3) * Time.deltaTime);
            }
            else
            {
                anima.SetBool("Idle", true);
                anima.SetBool("Running", false);
            }
            break;

        case States.ATTACKING:
            anima.SetBool("Idle", false);
            anima.SetBool("Running", false);
            anima.SetBool("Attack", true);
            break;
        }
    }
Beispiel #48
0
 public void Reset()
 {
     State = States.None;
 }
Beispiel #49
0
 /// <summary>Is called every frame.</summary>
 /// <param name="data">The data.</param>
 /// <param name="blocking">Whether the device is blocked or will block subsequent devices.</param>
 internal override void Elapse(ElapseData data, ref bool blocking)
 {
     // --- behavior ---
     if (this.State == States.Suppressed)
     {
         if (data.Handles.BrakeNotch <= this.Train.Specs.BrakeNotches)
         {
             this.AlarmCountdown = DurationOfInitialization;
             this.State          = States.Initializing;
         }
     }
     if (this.State == States.Initializing)
     {
         this.AlarmCountdown -= data.ElapsedTime.Seconds;
         if (this.AlarmCountdown <= 0.0)
         {
             this.State = States.Chime;
         }
         else
         {
             data.Handles.BrakeNotch = this.Train.Specs.BrakeNotches + 1;
             this.Train.Sounds.AtsBell.Play();
         }
     }
     if (blocking)
     {
         if (this.State != States.Disabled & this.State != States.Suppressed)
         {
             this.State = States.Normal;
         }
     }
     else
     {
         if (this.State == States.Chime)
         {
             this.Train.Sounds.AtsChime.Play();
         }
         else if (this.State == States.Alarm)
         {
             this.Train.Sounds.AtsBell.Play();
             this.AlarmCountdown -= data.ElapsedTime.Seconds;
             if (this.AlarmCountdown <= 0.0)
             {
                 this.State = States.Emergency;
             }
         }
         else if (this.State == States.Emergency)
         {
             this.Train.Sounds.AtsBell.Play();
             data.Handles.BrakeNotch = this.Train.Specs.BrakeNotches + 1;
         }
         if (this.SpeedCheckCountdown > 0.0 & data.ElapsedTime.Seconds > 0.0)
         {
             this.SpeedCheckCountdown -= data.ElapsedTime.Seconds;
         }
         if (this.CompatibilityDistanceAccumulator != 0.0)
         {
             this.CompatibilityDistanceAccumulator += data.Vehicle.Speed.MetersPerSecond * data.ElapsedTime.Seconds;
             if (this.CompatibilityDistanceAccumulator > 27.7)
             {
                 this.CompatibilityDistanceAccumulator = 0.0;
             }
         }
         if (this.State != States.Disabled & (this.Train.Doors != DoorStates.None | data.Handles.BrakeNotch > 0))
         {
             data.Handles.PowerNotch = 0;
         }
     }
     // --- panel ---
     if ((this.State == States.Chime | this.State == States.Normal) & !blocking)
     {
         this.Train.Panel[256] = 1;
     }
     if (this.State == States.Initializing | this.State == States.Alarm)
     {
         this.Train.Panel[257] = 1;
         this.Train.Panel[258] = 1;
     }
     else if (this.State == States.Emergency)
     {
         int value = (int)data.TotalTime.Milliseconds % 1000 < 500 ? 1 : 0;
         this.Train.Panel[257] = 2;
         this.Train.Panel[258] = value;
     }
 }
 public GpsAutoDiscoveryEventArgs(States state, string gpsport, OpenNETCF.IO.Serial.BaudRates gpsbauds)
 {
     this.state    = state;
     this.gpsport  = gpsport;
     this.gpsbauds = gpsbauds;
 }
Beispiel #51
0
 /// <summary>
 /// Reset the timer to its beginning state
 /// </summary>
 public void Reset()
 {
     _CurrentState = States.eStopped;
     _CurrentTime  = 0;
 }
Beispiel #52
0
 private void Attacked()
 {
     anima.SetBool("Attack", false);
     state = States.FOLLOWING;
 }
Beispiel #53
0
 /// <summary>
 /// Start the timer
 /// IMPORTANT(mtn5): it will start the timer from the current time
 /// if you want to start the timer from 0, see Restart or Reset
 /// </summary>
 public void Start()
 {
     _CurrentState = States.eRunning;
 }
Beispiel #54
0
        // --- inherited functions ---

        /// <summary>Is called when the system should initialize.</summary>
        /// <param name="mode">The initialization mode.</param>
        internal override void Initialize(InitializationModes mode)
        {
            this.State = mode == InitializationModes.OffEmergency ? States.Suppressed : States.Normal;
        }
Beispiel #55
0
		int HomingInnerTick(int predClfDist, int diffClfMslHgt, int relTarHorDist, int lastHtChg, int lastHt,
			int nxtRelTarHorDist, int relTarHgt, int vFacing, bool targetPassedBy)
		{
			int desiredVFacing = vFacing;

			// Incline coming up -> attempt to reach the incline so that after predClfDist
			// the height above the terrain is positive but as close to 0 as possible
			// Also, never change horizontal facing and never travel backwards
			// Possible techniques to avoid close cliffs are deceleration, turning
			// as sharply as possible to travel directly upwards and then returning
			// to zero vertical facing as low as possible while still not hitting the
			// high terrain. A last technique (and the preferred one, normally used when
			// the missile hasn't been fired near a cliff) is simply finding the smallest
			// vertical facing that allows for a smooth climb to the new terrain's height
			// and coming in at predClfDist at exactly zero vertical facing
			if (info.TerrainHeightAware && diffClfMslHgt >= 0 && !allowPassBy)
				desiredVFacing = IncreaseAltitude(predClfDist, diffClfMslHgt, relTarHorDist, vFacing);
			else if (relTarHorDist <= 3 * loopRadius || state == States.Hitting)
			{
				// No longer travel at cruise altitude
				state = States.Hitting;

				if (lastHt >= targetPosition.Z)
					allowPassBy = true;

				if (!allowPassBy && (lastHt < targetPosition.Z || targetPassedBy))
				{
					// Aim for the target
					var vDist = new WVec(-relTarHgt, -relTarHorDist, 0);
					desiredVFacing = (sbyte)vDist.HorizontalLengthSquared != 0 ? vDist.Yaw.Facing : vFacing;

					// Do not accept -1  as valid vertical facing since it is usually a numerical error
					// and will lead to premature descent and crashing into the ground
					if (desiredVFacing == -1)
						desiredVFacing = 0;

					// If the target has been passed by, limit the absolute value of
					// vertical facing by the maximum vertical rate of turn
					// Do this because the missile will be looping horizontally
					// and thus needs smaller vertical facings so as not
					// to hit the ground prematurely
					if (targetPassedBy)
						desiredVFacing = desiredVFacing.Clamp(-info.VerticalRateOfTurn.Facing, info.VerticalRateOfTurn.Facing);
					else if (lastHt == 0)
					{ // Before the target is passed by, missile speed should be changed
						// Target's height above loop's center
						var tarHgt = (loopRadius * WAngle.FromFacing(vFacing).Cos() / 1024 - System.Math.Abs(relTarHgt)).Clamp(0, loopRadius);

						// Target's horizontal distance from loop's center
						var tarDist = Exts.ISqrt(loopRadius * loopRadius - tarHgt * tarHgt);

						// Missile's horizontal distance from loop's center
						var missDist = loopRadius * WAngle.FromFacing(vFacing).Sin() / 1024;

						// If the current height does not permit the missile
						// to hit the target before passing it by, lower speed
						// Otherwise, increase speed
						if (relTarHorDist <= tarDist - System.Math.Sign(relTarHgt) * missDist)
							ChangeSpeed(-1);
						else
							ChangeSpeed();
					}
				}
				else if (allowPassBy || (lastHt != 0 && relTarHorDist - lastHtChg < loopRadius))
				{
					// Only activate this part if target too close to cliff
					allowPassBy = true;

					// Vector from missile's current position pointing to the loop's center
					var radius = new WVec(loopRadius, 0, 0)
						.Rotate(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(64 - vFacing)));

					// Vector from loop's center to incline top hardcoded in height buffer zone
					var edgeVector = new WVec(lastHtChg, lastHt - pos.Z, 0) - radius;

					if (!targetPassedBy)
					{
						// Climb to critical height
						if (relTarHorDist > 2 * loopRadius)
						{
							// Target's distance from cliff
							var d1 = relTarHorDist - lastHtChg;
							if (d1 < 0)
								d1 = 0;
							if (d1 > 2 * loopRadius)
								return 0;

							// Find critical height at which the missile must be once it is at one loopRadius
							// away from the target
							var h1 = loopRadius - Exts.ISqrt(d1 * (2 * loopRadius - d1)) - (pos.Z - lastHt);

							if (h1 > loopRadius * (1024 - WAngle.FromFacing(vFacing).Cos()) / 1024)
								desiredVFacing = WAngle.ArcTan(Exts.ISqrt(h1 * (2 * loopRadius - h1)), loopRadius - h1).Angle >> 2;
							else
								desiredVFacing = 0;

							// TODO: deceleration checks!!!
						}
						else
						{
							// Avoid the cliff edge
							if (info.TerrainHeightAware && edgeVector.Length > loopRadius && lastHt > targetPosition.Z)
							{
								int vFac;
								for (vFac = vFacing + 1; vFac <= vFacing + info.VerticalRateOfTurn.Facing - 1; vFac++)
								{
									// Vector from missile's current position pointing to the loop's center
									radius = new WVec(loopRadius, 0, 0)
										.Rotate(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(64 - vFac)));

									// Vector from loop's center to incline top + 64 hardcoded in height buffer zone
									edgeVector = new WVec(lastHtChg, lastHt - pos.Z, 0) - radius;
									if (edgeVector.Length <= loopRadius)
										break;
								}

								desiredVFacing = vFac;
							}
							else
							{
								// Aim for the target
								var vDist = new WVec(-relTarHgt, -relTarHorDist, 0);
								desiredVFacing = (sbyte)vDist.HorizontalLengthSquared != 0 ? vDist.Yaw.Facing : vFacing;
								if (desiredVFacing < 0 && info.VerticalRateOfTurn.Facing < (sbyte)vFacing)
									desiredVFacing = 0;
							}
						}
					}
					else
					{
						// Aim for the target
						var vDist = new WVec(-relTarHgt, relTarHorDist, 0);
						desiredVFacing = (sbyte)vDist.HorizontalLengthSquared != 0 ? vDist.Yaw.Facing : vFacing;
						if (desiredVFacing < 0 && info.VerticalRateOfTurn.Facing < (sbyte)vFacing)
							desiredVFacing = 0;
					}
				}
				else
				{
					// Aim to attain cruise altitude as soon as possible while having the absolute value
					// of vertical facing bound by the maximum vertical rate of turn
					var vDist = new WVec(-diffClfMslHgt - info.CruiseAltitude.Length, -speed, 0);
					desiredVFacing = (sbyte)vDist.HorizontalLengthSquared != 0 ? vDist.Yaw.Facing : vFacing;

					// If the missile is launched above CruiseAltitude, it has to descend instead of climbing
					if (-diffClfMslHgt > info.CruiseAltitude.Length)
						desiredVFacing = -desiredVFacing;

					desiredVFacing = desiredVFacing.Clamp(-info.VerticalRateOfTurn.Facing, info.VerticalRateOfTurn.Facing);

					ChangeSpeed();
				}
			}
			else
			{
				// Aim to attain cruise altitude as soon as possible while having the absolute value
				// of vertical facing bound by the maximum vertical rate of turn
				var vDist = new WVec(-diffClfMslHgt - info.CruiseAltitude.Length, -speed, 0);
				desiredVFacing = (sbyte)vDist.HorizontalLengthSquared != 0 ? vDist.Yaw.Facing : vFacing;

				// If the missile is launched above CruiseAltitude, it has to descend instead of climbing
				if (-diffClfMslHgt > info.CruiseAltitude.Length)
					desiredVFacing = -desiredVFacing;

				desiredVFacing = desiredVFacing.Clamp(-info.VerticalRateOfTurn.Facing, info.VerticalRateOfTurn.Facing);

				ChangeSpeed();
			}

			return desiredVFacing;
		}
Beispiel #56
0
 /// <summary>
 /// Pause the timer, will not update its time
 /// </summary>
 public void Pause()
 {
     _CurrentState = States.ePaused;
 }
 public void Stop()
 {
     state = States.Paused;
 }
Beispiel #58
0
		public void Tick(World world)
		{
			ticks++;
			if (anim != null)
				anim.Tick();

			// Switch from freefall mode to homing mode
			if (ticks == info.HomingActivationDelay + 1)
			{
				state = States.Homing;
				speed = velocity.Length;

				// Compute the vertical loop radius
				loopRadius = LoopRadius(speed, info.VerticalRateOfTurn.Facing);
			}

			// Switch from homing mode to freefall mode
			if (rangeLimit >= WDist.Zero && distanceCovered > rangeLimit)
			{
				state = States.Freefall;
				velocity = new WVec(0, -speed, 0)
					.Rotate(new WRot(WAngle.FromFacing(vFacing), WAngle.Zero, WAngle.Zero))
					.Rotate(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(hFacing)));
			}

			// Check if target position should be updated (actor visible & locked on)
			var newTarPos = targetPosition;
			if (args.GuidedTarget.IsValidFor(args.SourceActor) && lockOn)
				newTarPos = (args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.PositionClosestTo(args.Source))
					+ new WVec(WDist.Zero, WDist.Zero, info.AirburstAltitude);

			// Compute target's predicted velocity vector (assuming uniform circular motion)
			var yaw1 = tarVel.HorizontalLengthSquared != 0 ? tarVel.Yaw : WAngle.FromFacing(hFacing);
			tarVel = newTarPos - targetPosition;
			var yaw2 = tarVel.HorizontalLengthSquared != 0 ? tarVel.Yaw : WAngle.FromFacing(hFacing);
			predVel = tarVel.Rotate(WRot.FromYaw(yaw2 - yaw1));
			targetPosition = newTarPos;

			// Compute current distance from target position
			var tarDistVec = targetPosition + offset - pos;
			var relTarDist = tarDistVec.Length;
			var relTarHorDist = tarDistVec.HorizontalLength;

			WVec move;
			if (state == States.Freefall)
				move = FreefallTick();
			else
				move = HomingTick(world, tarDistVec, relTarHorDist);

			renderFacing = new WVec(move.X, move.Y - move.Z, 0).Yaw;

			// Move the missile
			var lastPos = pos;
			if (info.AllowSnapping && state != States.Freefall && relTarDist < move.Length)
				pos = targetPosition + offset;
			else
				pos += move;

			// Check for walls or other blocking obstacles
			var shouldExplode = false;
			WPos blockedPos;
			if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width,
				out blockedPos))
			{
				pos = blockedPos;
				shouldExplode = true;
			}

			// Create the sprite trail effect
			if (!string.IsNullOrEmpty(info.TrailImage) && --ticksToNextSmoke < 0 && (state != States.Freefall || info.TrailWhenDeactivated))
			{
				world.AddFrameEndTask(w => w.Add(new SpriteEffect(pos - 3 * move / 2, renderFacing, w,
					info.TrailImage, info.TrailSequences.Random(world.SharedRandom), trailPalette)));

				ticksToNextSmoke = info.TrailInterval;
			}

			if (info.ContrailLength > 0)
				contrail.Update(pos);

			distanceCovered += new WDist(speed);
			var cell = world.Map.CellContaining(pos);
			var height = world.Map.DistanceAboveTerrain(pos);
			shouldExplode |= height.Length < 0 // Hit the ground
				|| relTarDist < info.CloseEnough.Length // Within range
				|| (info.ExplodeWhenEmpty && rangeLimit >= WDist.Zero && distanceCovered > rangeLimit) // Ran out of fuel
				|| !world.Map.Contains(cell) // This also avoids an IndexOutOfRangeException in GetTerrainInfo below.
				|| (!string.IsNullOrEmpty(info.BoundToTerrainType) && world.Map.GetTerrainInfo(cell).Type != info.BoundToTerrainType) // Hit incompatible terrain
				|| (height.Length < info.AirburstAltitude.Length && relTarHorDist < info.CloseEnough.Length); // Airburst

			if (shouldExplode)
				Explode(world);
		}
 public void Start()
 {
     lastCall = (long)DateTime.Now.Ticks;
     state    = States.Started;
     World.timers[(int)priority].Enqueue(this);
 }
 void Start()
 {
     myState = States.cart_0;
 }