//The definitios to each state public void SetState(STATES newState) { if (newState != currentState) //Only change to a different state { switch (newState) { case STATES.WATER: GetComponent <Rigidbody2D>().gravityScale = 1.0f; // To simulate Water density break; case STATES.GAS: particleLifeTime = particleLifeTime / 2.0f; // Gas lives the time the other particles GetComponent <Rigidbody2D>().gravityScale = 0.0f; // To simulate Gas density gameObject.layer = LayerMask.NameToLayer("Gas"); // To have a different collision layer than the other particles (so gas doesnt rises up the lava but still collides with the wolrd) break; case STATES.LAVA: GetComponent <Rigidbody2D>().gravityScale = 0.3f; // To simulate the lava density break; case STATES.NONE: Destroy(gameObject); break; } if (newState != STATES.NONE) { currentState = newState; startTime = Time.time; //Reset the life of the particle on a state change GetComponent <Rigidbody2D>().velocity = new Vector2(); // Reset the particle velocity currentImage.SetActive(false); currentImage = particleImages[(int)currentState]; currentImage.SetActive(true); } } }
// Use this for initialization public override void Start () { base.Start(); agent = (NavMeshAgent) gameObject.GetComponent(typeof(NavMeshAgent)); state = STATES.GO_TO_MINE; }
/// <summary>Updatet den Zellenzustand nach selbst festgelegten Regeln ändert diesen aber nicht</summary> /// <param name="_rules">Struct mit den selber festgelegten Regeln</param> /// <remarks>Holt sich die Anzahl der aktuell Lebenden Nachbarszellen. Je nach Anzahl wird die Zelle geboren, überlebt oder stirbt</remarks> public void CellUpdate(CustomRules _rules) { //Sich die aktuelle Anzahl der 8 möglich Lebenden Nachbarszellen holen int LifingNeighborsCount = LifingNeighbors(); //Sich die aktuelle Anzahl an Lebenden Nachbarszellen holen die den übergebenen Altersgruppen entsprechen int AgeGroupNeighborsCount = AgeGroupNeighbors(_rules.MinAgeReproductions, _rules.MaxAgeReproductions); //Den aktuellen Zustand der Zelle speichern m_NewState = m_CurrentState; //Überprüfen ob das aktuelle Zellenalter älter oder gleich ist als das Alter das in den eigenen Regeln für "Sterben an Altersschwäche" festgelegt wurde if (_rules.AgeWeaknessesOfOld != 0 && m_Age >= (ulong)_rules.AgeWeaknessesOfOld) { m_NewState = STATES.DEAD; //Die Zelle stirbt an Altersschwäche -> Der neue Zustand der Zelle wird "Gestorben" sein } else if (m_CurrentState == STATES.DEAD && AgeGroupNeighborsCount == 3) //Überprüfen ob der aktuelle Zustand "Gestorben" ist und ob es 3 Lebende Nachbarszellen in der festgelegten Altersgruppe gibt { m_NewState = STATES.ALIVE; //Die Zelle wird neugeboren -> Der neue Zustand der Zelle wird "Lebend" sein } else if (m_CurrentState == STATES.ALIVE && LifingNeighborsCount < 2) //Überprüfen der aktuelle Zustand "Lebend" ist und ob es weniger als 2 Lebende Nachbarszellen in der festgelegten Altersgruppe gibt { m_NewState = STATES.DEAD; //Die Zelle stirbt an Vereinsamung -> Der neue Zustand der Zelle wird "Gestorben" sein } else if (m_CurrentState == STATES.ALIVE && (LifingNeighborsCount == 2 || LifingNeighborsCount == 3)) //Überprüfen der aktuelle Zustand "Lebend" ist und ob es genau 2 oder 3 lebende Nachbarszellen in der festgelegten Altersgruppe gibt { return; //Der neue Zustand wird gleich dem aktuellen Zustand der Zelle sein } else if (m_CurrentState == STATES.ALIVE && LifingNeighborsCount > 3) //Überprüfen der aktuelle Zustand "Lebend" ist und ob es mehr wie 3 Lebende Nachbarszellen in der festgelegten Altersgruppe gibt { m_NewState = STATES.DEAD; //Die Zelle stirbt an Überbevölkerung -> Der neue Zustand der Zelle wird "Gestorben" sein } }
// Stemina, Battery의 게이지를 조정하는 코루틴 메서드 private IEnumerator AdjustGauge1() { while (true) { if (!isRunning && stemina < MAX) { stemina += STEMINA_GENERATION; } if (!waitForBattery) { battery -= BATTERY_CONSUME; if (battery <= 0) { state = STATES.DEAD; battery = 0; } playerManager.GetBatterySlider().value = ((float)battery) / MAX; if (battery == 3) { StartCoroutine(WaitForBatteryDead()); } } playerManager.GetPlayerLight().intensity = ((float)battery) / MAX * LIGHT_MAX; playerManager.GetPlayerLight().range = LIGHT_RANGE_MAX + ((float)battery) / MAX * LIGHT_RANGE_MAX; playerManager.GetSteminaSlider().value = ((float)stemina) / MAX; yield return(new WaitForSeconds(0.3f)); } }
// Update is called once per frame public override void Update () { switch (state) { case STATES.GO_TO_MINE: GetComponent<Animation>().wrapMode = WrapMode.Loop; GetComponent<Animation>().CrossFade("NPCwalk"); agent.SetDestination(myMine.transform.position); state = STATES.GOING_TO_MINE; break; case STATES.GO_TO_TC: GetComponent<Animation>().wrapMode = WrapMode.Loop; GetComponent<Animation>().CrossFade("NPCwalk"); agent.SetDestination(myTownCenter.transform.position); state = STATES.GOING_TO_TC; break; case STATES.GOING_TO_MINE: if (agent.remainingDistance <= agent.stoppingDistance) { onReachedMine(); } break; case STATES.GOING_TO_TC: if (agent.remainingDistance <= agent.stoppingDistance) { onReachedTownCenter(); } break; } }
protected void SetState(STATES state) { // Only process state changes. // Once dead, never process state changes again. if (this.currentState == state || this.currentState == STATES.Dead) { return; } switch (state) { case STATES.Dead: // Just here to be explicit. Once Dead, this won't run again. See above. break; case STATES.NotDetected: this.transform.localScale = Vector3.one; this.GetComponent <Renderer>().material.color = this.startingColor; break; case STATES.Detected: this.GetComponent <Renderer>().material.color = Color.yellow; this.transform.localScale = this.activeTargetScale * 0.75f; break; case STATES.ActiveTarget: this.GetComponent <Renderer>().material.color = Color.green; this.transform.localScale = this.activeTargetScale; break; } this.currentState = state; }
public void PauseOrPlay() { if (state == STATES.STOP) { if (playPauseButton != null) { playPauseButton.GetComponentInChildren <Text>().text = "Pause"; } if (controls != null) { controls.enabled = false; } state = STATES.PLAY; } else if (state == STATES.PLAY) { if (playPauseButton != null) { playPauseButton.GetComponentInChildren <Text>().text = "Play"; } if (controls != null) { controls.enabled = true; } state = STATES.STOP; } else if (state == STATES.GAME_OVER) { Application.LoadLevel(Application.loadedLevel); } }
public IEnumerator CouldownAttack() { state = STATES.CantAttack; yield return(new WaitForSeconds(1f / attackSpeed)); state = STATES.Neutral; }
private IEnumerator ChangeState(STATES State, long DurationInMilliseconds) { yield return(new WaitForSecondsRealtime(DurationInMilliseconds / 1000f)); this.stateChanged = false; this.currentState = STATES.IDLE; }
protected void Update() { switch (GameState) { case STATES.WAITINGFORMESSAGE: case STATES.INMINIGAME: MessageEvent = ChatterBox.GetNextMessage(); ChatterBox.ProcessMessage(MessageEvent); break; case STATES.ANSWERMESSAGE: ChatRect.MessageEvent me = new ChatRect.MessageEvent(); me.message = ChatterBox.GetAnswerString(); me.messagetype = ChatRect.messagetype.messageback; ChatterBox.ProcessMessage(me); break; default: break; } GameState = STATES.NONE; }
private void Fall() { if (isGrounded) { myState = STATES.Fall; } }
//The definitios to each state public void SetState(STATES newState){ if(newState!=currentState){ //Only change to a different state currentState=newState; startTime=Time.time;//Reset the life of the particle on a state change rigidbody2D.velocity=new Vector2(); // Reset the particle velocity switch(newState){ case STATES.WATER: //particleImage.color=new Color(1f, 0.92f, 0.016f, 0.5f);// Set the color for the metaball shader to know how to draw each particle particleImage.color=getColorWithScene(Application.loadedLevelName);// Set the color for the metaball shader to know how to draw each particle rigidbody2D.gravityScale=5f; // To simulate Water density rigidbody2D.mass=0.01f; break; case STATES.GAS: particleImage.color=gasColor; particleLifeTime=particleLifeTime/2.0f; // Gas lives the time the other particles rigidbody2D.gravityScale=0.0f;// To simulate Gas density gameObject.layer=LayerMask.NameToLayer("Gas");// To have a different collision layer than the other particles (so gas doesnt rises up the lava but still collides with the wolrd) break; case STATES.LAVA: particleImage.color=lavaColor; rigidbody2D.gravityScale=0.3f; // To simulate the lava density break; case STATES.NONE: Destroy(gameObject); break; } } }
// Use this for initialization void Start() { GameObjectStates[(int)state].SetActive(true); state = STATES.MENU; cameraPos = mainCamera.transform.position; setCamera(); }
public void Fail() { tries++; PlayerPrefs.SetInt("tries", tries); Clear(); state = STATES.FAIL; }
public void fade(STATES state, BackEndManager bm) { // box.clip = anims[1]; box.Play("FadeOut"); BackEndManager.instance.changingState = true; if (state == STATES.GAME) { AudioManager.instance.startFadeO(true); if (GameManager.instance) { GameManager.instance.Clear(); } } // else if(BackEndManager.instance.prvState == (int)STATES.GAME) { // AudioManager.instance.startFadeO(false); // } if (state == STATES.CREDITS || state == STATES.HELP) { Invoke("sfx", 0.5f); Invoke("fadeinAlt", 2.0f); } else { Invoke("sfx", 0.5f); Invoke("fadeIn", 2.0F); } }
// Cargamos el componente CharacterController en la variable player al iniciar el script void Start() { player = GetComponent <CharacterController>(); currentState = STATES.IDLE; anim = GetComponent <Animator>(); Hp = Hpmax; }
public override void Act(int value) { switch (value) { case (int)STATES.IDLE: CurrentState = STATES.IDLE; DoIdle(); break; case (int)STATES.FOLLOW_ORDER: CurrentState = STATES.FOLLOW_ORDER; DoFollowOrder(); break; case (int)STATES.CHASE: CurrentState = STATES.CHASE; DoChase(); break; case (int)STATES.ATTACK: CurrentState = STATES.ATTACK; DoAttack(); break; case (int)STATES.HELP: CurrentState = STATES.HELP; DoHelp(); break; } }
bool MakeJump() { if (nbJumpLeft > 0) { velocity.y = jumpSpeed; if (!isGrounded) { myState = STATES.SecondJump; } else { myState = STATES.Jump; } isGrounded = false; if (isWallSlide) { speed = maxSpeed; velocity.y = jumpSpeed; dir = dir * -1; modifier = 1.0f; isWallSlide = false; } nbJumpLeft--; return(true); } return(false); }
protected void getAttacked() { Player p = targetToKill.GetComponent <Player> (); if (p.time_last_attack == -1 || Time.time - p.time_last_attack >= p.TIME_BETWEEN_ATTACK) { Animation anim = targetToKill.transform.GetChild(1).GetChild(1).GetComponent <Animation> (); anim ["SpearAnimation"].speed = (1.0f / (p.TIME_BETWEEN_ATTACK) + TIME_BETWEEN_ANIMATIONS); anim.Play("SpearAnimation"); // Actual damage float damage = (p.DAMAGE + Random.Range(0, p.RANGE_DAMAGE)); if (health > damage) { health -= damage; // update health bar GameObject bar = this.transform.GetChild(4).gameObject; bar.transform.localScale = new Vector3(health * 0.015f, bar.transform.localScale.y, bar.transform.localScale.z); this.transform.GetChild(0).gameObject.GetComponent <Renderer> ().material = redMat; state = STATES.FIGHTING; p.time_last_attack = Time.time; } else { onDie(); } } }
public void Initialize() { this.animator = this.GetComponent <Animator>(); this.velocity = new Vector3(0, 0, 0); this.groundCollider = null; state = STATES.NEUTRAL; }
void CheckConditions()// Funcion que define la toma de estados { //si se presiona la tecla W S A D if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D)) { //El estado cambia a caminar currentState = STATES.Walkin; } else { //Si no el estado es reposo currentState = STATES.IDLE; } if (Input.GetKey(KeyCode.H)) { currentState = STATES.SHOOTING; //estado caminar } if (Input.GetKeyDown(KeyCode.Z) && onFloor) { currentState = STATES.CRAWL;//estado caminar rb.AddForce(new Vector3(0, playerJump, 0), ForceMode.Impulse); onFloor = false; } }
void CheckConditions()// Funcion que define la toma de estados { //si se presiona la tecla W S A D if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D)) { //El estado cambia a caminar currentState = STATES.Walkin; } else { //Si no el estado es reposo currentState = STATES.IDLE; } if (Input.GetKey(KeyCode.H)) { currentState = STATES.SHOOTING; //estado caminar } if (Input.GetKey(KeyCode.W) && (Input.GetKey(KeyCode.C)) || Input.GetKey(KeyCode.S) && (Input.GetKey(KeyCode.C)) || Input.GetKey(KeyCode.A) && (Input.GetKey(KeyCode.C)) || Input.GetKey(KeyCode.D) && (Input.GetKey(KeyCode.C))) { currentState = STATES.CRAWL; } if (life == 0) { currentState = STATES.MUERTO; //estado de muerte } }
public void ClearConversation() { scrollingBackground.transform.position = Vector3.zero; cursor.transform.position = cursorStart.transform.position; state = STATES.NORMAL; textUtility.RecycleAll(); }
void state_corridor_0() { if (isHandSafe) { text.text = "You escaped the Prison Cell... \n\n" + "\nbut......... for how long?\n\n\nPress S to check stairs, Press F to check floor and Press C to examine Closet"; } else { text.text = "You get excited seeing the key turn and cut you hand in the process....\n\n" + "\"I still haven't learnt the lesson...\" - You say to yourself\n" + "\n\n\"But I am free.....\n.....at least...for....now.\"\n\n\n" + "Press S to check stairs, Press F to examine floor and Press C to examine closet"; } if (Input.GetKeyDown(KeyCode.S)) { myState = STATES.stairs_0; } else if (Input.GetKeyDown(KeyCode.F)) { myState = STATES.floor; } else if (Input.GetKeyDown(KeyCode.C)) { myState = STATES.closet_door; } }
void InstantiateTurret(GameObject turret) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, walkable)) { if (!Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), Mathf.Infinity, nonConstructable)) { Vector3 position = hit.collider.gameObject.transform.position; position.y = 0; hit.collider.gameObject.layer = nonWalkableLayerIndex; GameObject instance = Instantiate(turret, position, Quaternion.identity) as GameObject; Collider collider = instance.GetComponent <Collider>(); if (collider != null) { instance.transform.position = instance.transform.position + instance.transform.up * collider.bounds.size.y / 2; } state = STATES.RECREATING_GRID; pathfindingGrid.UpdateGrid(position); GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); for (int i = 0; i < enemies.Length; i++) { enemies[i].GetComponent <Enemy>().ReEvaluatePath(); } state = STATES.PLAY; } } }
private void initCipherInput() { long inputLength; using (CStreamReader reader = CipherInput.CreateReader()) { inputLength = reader.Length; reader.Read(prelBlock); reader.Read(cipherBlock); reader.Close(); } for (int byteCounter = 0; byteCounter < blockSize; byteCounter++) { corruptedBlock[byteCounter] = prelBlock[byteCounter]; } if (inputLength < 2 * blockSize) { curState = STATES.ERROR; GuiLogMessage("Input Message too short. Please check if the Block Size is correct (in the Plugin Settings).", NotificationLevel.Error); } else if (inputLength > 2 * blockSize) { GuiLogMessage("The input message is longer than the expected length. Please check if the Block Size is correct (in the Plugin Settings).", NotificationLevel.Warning); } }
// Update is called once per frame public void Update() { if (m_currentState) { m_targetStateName = m_currentState.Update(); if (m_targetStateName != m_currentState.m_ID) { m_currentState.onExist(); Destroy(m_currentState); if (m_targetStateName == STATES.S_IDLE) { m_currentState = gameObject.AddComponent(typeof(IdleState)) as IdleState; m_currentState.onEntry(); } else if (m_targetStateName == STATES.S_WALK) { m_currentState = gameObject.AddComponent(typeof(WalkState)) as WalkState; m_currentState.onEntry(); } else if (m_targetStateName == STATES.S_RUN) { m_currentState = gameObject.AddComponent(typeof(RunState)) as RunState; m_currentState.onEntry(); } else if (m_targetStateName == STATES.S_JUMP) { m_currentState = gameObject.AddComponent(typeof(JumpState)) as JumpState; m_currentState.onEntry(); } else if (m_targetStateName == STATES.S_CHARGE) { m_currentState = gameObject.AddComponent(typeof(ChargeState)) as ChargeState; m_currentState.onEntry(); } else if (m_targetStateName == STATES.S_DELIVER) { m_currentState = gameObject.AddComponent(typeof(DeliverState)) as DeliverState; m_currentState.onEntry(); } else if (m_targetStateName == STATES.S_DIE) { m_currentState = gameObject.AddComponent(typeof(DieState)) as DieState; m_currentState.onEntry(); } else if (m_targetStateName == STATES.S_PATROL) { m_currentState = gameObject.AddComponent(typeof(PatrolState)) as PatrolState; m_currentState.onEntry(); } else { m_currentState = null; } } } // Update steering forces updateSteering(); }
//The definitios to each state public void SetState(STATES newState) { if (newState != currentState) { //Only change to a different state currentState = newState; startTime = Time.time; //Reset the life of the particle on a state change GetComponent <Rigidbody2D>().velocity = new Vector2(); // Reset the particle velocity switch (newState) { case STATES.WATER: particleImage.color = waterColor; // Set the color for the metaball shader to know how to draw each particle GetComponent <Rigidbody2D>().gravityScale = 1.0f; // To simulate Water density break; case STATES.GAS: particleImage.color = gasColor; particleLifeTime = particleLifeTime / 2.0f; // Gas lives the time the other particles GetComponent <Rigidbody2D>().gravityScale = 0.0f; // To simulate Gas density gameObject.layer = LayerMask.NameToLayer("Gas"); // To have a different collision layer than the other particles (so gas doesnt rises up the lava but still collides with the wolrd) break; case STATES.LAVA: particleImage.color = lavaColor; GetComponent <Rigidbody2D>().gravityScale = 0.3f; // To simulate the lava density break; case STATES.NONE: Destroy(gameObject); break; } } }
private void Move() { float moveV = Input.GetAxisRaw("Vertical"); float moveH = Input.GetAxisRaw("Horizontal"); // 플레이어가 달리지 않는 경우와 달리는 경우 if (!isRunning) { rb.transform.Translate(moveH * playerSpeed * Time.deltaTime, moveV * playerSpeed * Time.deltaTime, 0f); } else if (state != STATES.IDLE) { rb.transform.Translate(moveH * playerRunningSpeed * Time.deltaTime, moveV * playerRunningSpeed * Time.deltaTime, 0f); } // 플레이어 상태 설정 if (moveH < -0.1f) { state = STATES.WALK_LEFT; } else if (moveH > 0.1f || moveV != 0f) { state = STATES.WALK_RIGHT; } else { state = STATES.IDLE; } }
protected void findPath() { // Select a random room MazeRoom r = maze.rooms [Random.Range(0, maze.rooms.Count)]; float randomNumber = Random.Range(0.0f, 1.0f); // Number of total steps int nbSteps = 0; foreach (MazeCell c in r.cells) { nbSteps += c.playerStepsCounter + 1; } // Look for the cell to go to float cpt = 0.0f; foreach (MazeCell c in r.cells) { if (randomNumber >= cpt && randomNumber <= cpt + ((c.playerStepsCounter + 1) * 1.0f / nbSteps)) { walkingTarget = c; break; } cpt += (c.playerStepsCounter + 1) * 1.0f / nbSteps; } //walkingTarget = c; state = STATES.WALKING; }
// Start is called before the first frame update void Start() { RestartText.text = ""; GameOverText.text = ""; if (controler == null) { controler = this; } else if (controler != this) { Destroy(gameObject); } HighestScore savedScore = SaveGame.LoadScore(); if (savedScore != null) { highestScore = savedScore.highestScore; } nextTimeIncrease = Time.unscaledTime; state = STATES.INTRO; soundController.PlayIntro(); }
protected void detectPlayer() { Collider[] hitColliders = Physics.OverlapSphere(this.transform.position, DETECTING_DISTANCE * agressivity); int i = 0; // Objects at right distance while (i < hitColliders.Length) { if (hitColliders[i].gameObject == targetToKill) { // Objects in line of sight RaycastHit hit; Vector3 rayOrigin = this.transform.position + Vector3.up; Vector3 targetDirection = hitColliders[i].transform.position - this.transform.position; if (Physics.Raycast(rayOrigin, targetDirection, out hit)) { // Angle of sight float angle = Vector3.Angle(targetDirection, this.transform.forward); if (Mathf.Abs(angle) < VIEW_ANGLE * agressivity) { this.transform.GetChild(0).gameObject.GetComponent <Renderer> ().material = redMat; state = STATES.FIGHTING; return; } } } i++; } }
//The definitios to each state public void SetState(STATES newState) { if(newState!=currentState){ //Only change to a different state switch(newState){ case STATES.WATER: GetComponent<Rigidbody2D>().gravityScale=1.0f; // To simulate Water density break; case STATES.GAS: particleLifeTime=particleLifeTime/2.0f; // Gas lives the time the other particles GetComponent<Rigidbody2D>().gravityScale=0.0f;// To simulate Gas density gameObject.layer=LayerMask.NameToLayer("Gas");// To have a different collision layer than the other particles (so gas doesnt rises up the lava but still collides with the wolrd) break; case STATES.LAVA: GetComponent<Rigidbody2D>().gravityScale=0.3f; // To simulate the lava density break; case STATES.NONE: Destroy(gameObject); break; } if(newState!=STATES.NONE){ currentState=newState; startTime=Time.time;//Reset the life of the particle on a state change GetComponent<Rigidbody2D>().velocity=new Vector2(); // Reset the particle velocity currentImage.SetActive(false); currentImage=particleImages[(int)currentState]; currentImage.SetActive(true); } } }
/// <summary>Updatet den Zellenzustand nach den gängigen Regeln von Game of Life ändert diesen aber noch nicht</summary> /// <remarks>Holt sich die Anzahl der aktuell Lebenden Nachbarszellen. Je nach Anzahl wird die Zelle geboren, überlebt oder stirbt</remarks> public void CellUpdate() { //Sich die aktuelle Anzahl der 8 möglich Lebenden Nachbarszellen holen int LifingNeighborsCount = LifingNeighbors(); //Den aktuellen Zustand der Zelle speichern m_NewState = m_CurrentState; //Nach den gängigen Regeln von Game of Life den neuen Zustand der Zelle speichern if (m_CurrentState == STATES.DEAD && LifingNeighborsCount == 3) //Überprüfen der aktuelle Zustand "Gestorben" ist und ob es 3 Lebende Nachbarszellen gibt { m_NewState = STATES.ALIVE; //Die Zelle wird neugeboren -> Der neue Zustand der Zelle wird "Lebend" sein } else if (m_CurrentState == STATES.ALIVE && LifingNeighborsCount < 2) //Überprüfen der aktuelle Zustand "Lebend" ist und ob es weniger als 2 Lebende Nachbarszellen gibt { m_NewState = STATES.DEAD; //Die Zelle stirbt an Vereinsamung -> Der neue Zustand der Zelle wird "Gestorben" sein } else if (m_CurrentState == STATES.ALIVE && (LifingNeighborsCount == 2 || LifingNeighborsCount == 3)) //Überprüfen der aktuelle Zustand "Lebend" ist und ob es genau 2 oder 3 lebende Nachbarszellen gibt { return; //Der neue Zustand wird gleich dem aktuellen Zustand der Zelle sein } else if (m_CurrentState == STATES.ALIVE && LifingNeighborsCount > 3) //Überprüfen der aktuelle Zustand "Lebend" ist und ob es mehr wie 3 Lebende Nachbarszellen gibt { m_NewState = STATES.DEAD; //Die Zelle stirbt an Überbevölkerung -> Der neue Zustand der Zelle wird "Gestorben" sein } }
private void onReachedMine() { GoldMine mineComp = (GoldMine) myMine.GetComponent(typeof(GoldMine)); if (mineComp != null) { mineComp.transferResources(this); } //nav.SetDestination(myTownCenter.transform.position); //reachedMine = false; state = STATES.GO_TO_TC; }
void OnGUI() { /*GUI.matrix = GUIGlobals.GetGUIScaleMatrix(); string stateString = ""; switch(state) { case STATES.DEFAULT: stateString= "DEFAULT"; break; case STATES.CONFIRM: stateString= "CONFIRM"; break; case STATES.ACK: stateString= "ACK"; break; case STATES.CAPTURING: stateString= "CAPTURING"; break; } GUI.Label(new Rect(0, 0, 100, 50), stateString); */ if(state == STATES.CONFIRM || state == STATES.ACK) { //GUI.skin=gSkin; GUI.matrix = GUIGlobals.GetGUIScaleMatrix(); GUILayout.BeginArea(new Rect(GUIGlobals.GetCenterX()-300, GUIGlobals.GetCenterY()-200, 600, 400)); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label(message); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if(GUILayout.Button("OK")) { if(state == STATES.CONFIRM) { state = STATES.CAPTURING; StartCapture(); } else { state = STATES.DEFAULT; } } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndArea(); } }
// Update is called once per frame void FixedUpdate() { switch (this.currentState) { case STATES.IDLE: animator.Play ("enemy-idle"); if (Mathf.Abs (PlayerTransform.position.x - this.GetComponent<Transform> ().position.x) < playerDetector) { animator.SetTrigger ("attack"); currentState = STATES.ATTACK; } else if (Mathf.Abs (speed) > 0) { this.currentState = STATES.WALKING; } if (PlayerTransform.position.x > this.GetComponent<Transform> ().position.x && speed <= 0) { speed = maxSpeed; } else if (PlayerTransform.position.x < this.GetComponent<Transform> ().position.x && speed >= 0){ speed = -maxSpeed; } break; case STATES.WALKING: animator.Play ("enemy-walking"); if (Mathf.Abs (PlayerTransform.position.x - this.GetComponent<Transform> ().position.x) < playerDetector) { animator.SetTrigger ("attack"); currentState = STATES.ATTACK; } else if (Mathf.Abs (speed) == 0) { this.currentState = STATES.IDLE; } if (PlayerTransform.position.x > this.GetComponent<Transform> ().position.x && speed <= 0) { speed = maxSpeed; } else if (PlayerTransform.position.x < this.GetComponent<Transform> ().position.x && speed >= 0){ speed = -maxSpeed; } break; case STATES.ATTACK: speed = 0; this.ApplyDamage (0.3f, 0.7f); if (this.animator.GetCurrentAnimatorStateInfo (0).normalizedTime >= 0.9) { this.currentState = STATES.IDLE; } break; } this.FixEnemyScaleX (); this.GetComponent<Rigidbody2D>().velocity = new Vector2 (speed, this.GetComponent<Rigidbody2D>().velocity.y); }
public PauzeEvent(string pauzeState) { switch (pauzeState) { case "pauze": state = STATES.pauze; break; case "resume": state = STATES.resume; break; default: break; } }
public Client(int numServiceItems, Store s) { this.id = CUSTOMERID; CUSTOMERID++; this.inQueue = false; this.timeEnteredStore = Timer.getTick(); this.timeEnteredQueue = -1; this.state = STATES.WAIT_TO_QUEUE; this.serviceItems = new List<ServiceItem>(); this.GenerateServiceItems(numServiceItems); this.strategies = new List<ClientStrategy>(); this.strategies.Add(new SmallestQueueStrategy(s, this)); this.strategies.Add(new FewestItemsStrategy(s, this)); this.currentStrategy = 0; patience = Configs.CLIENT_CHANGE_QUEUE_INTERVAL + (new Random()).Next(180); this.store = s; }
public Wand(Scene theScene, GraphicsDevice gDevice, Catalog cat, Room rm) { scene = theScene; graphicsDevice = gDevice; catalog = cat; room = rm; actionState = STATES.SELECTING; spriteBatch = new SpriteBatch(graphicsDevice); screenCenter = new Vector2(graphicsDevice.Viewport.Width / 2.0f, graphicsDevice.Viewport.Height / 2.0f); nearSource = new Vector3(screenCenter, 0); farSource = new Vector3(screenCenter, 1); // Add a mouse click callback function to perform ray picking when mouse is clicked MouseInput.Instance.MouseClickEvent += new HandleMouseClick(MouseClickHandler); MouseInput.Instance.MouseWheelMoveEvent += new HandleMouseWheelMove(MouseWheelHandler); // Add a keyboard press handler for user input KeyboardInput.Instance.KeyPressEvent += new HandleKeyPress(KeyPressHandler); }
void Search() { //Debug.Log("Searching"); //check if player is close or not if (_currentSearchTime >= SearchTime) { _distanceToPlayer = (_playerTransform.position - _transform.position).sqrMagnitude; _currentSearchTime = 0; if ( (_distanceToPlayer < SearchRadius * SearchRadius) ) { _directionToPlayer = (_playerTransform.position - _transform.position).normalized; _currentAttackTime += Time.deltaTime; if (_distanceToPlayer > AttackDistance * AttackDistance) { _moveDirection = _directionToPlayer; _currentSpeed = HostileSpeed; _renderer.material = HostileMaterial; State = STATES.HOSTILE; } else { //attack player if (_currentAttackTime > AttackTime) { _currentAttackTime = 0; _playerScript.TakeDamage(Damage); } else { //do nothing, still cooling } } } else { _renderer.material = NeutralMaterial; State = STATES.HOSTILE; _moveDirection = _wanderDirection; _currentSpeed = WanderSpeed; } } else { _currentSearchTime += (Time.realtimeSinceStartup - _myTimeSinceStartup); _myTimeSinceStartup = Time.realtimeSinceStartup; } }
public void targetTakesDamage() { StartCoroutine(healthScript.TakeDamage(damage, mySoliderScript, "hsl")); if (state != STATES.GotBlocked && state != STATES.GotHit) { debug = "ATTACK - transition to attack "; state = STATES.Attack; } }
protected IEnumerator Help(Transform attacker) { state = STATES.Help; yield return null; }
protected IEnumerator ProtectTown(Transform attacker) { //ChangeState (STATES.Chasing); GetComponent<Animation>().wrapMode = WrapMode.Loop; state = STATES.ProtectingTown; GetComponent<Animation>().CrossFade(chargeAnimation); agent.stoppingDistance = attackRange; agent.SetDestination(myTownCenter.transform.position); while (Vector3.Distance(myTownCenter.transform.position, transform.position) > attackRange) { debug = "going to my town to protect it"; if (!GetComponent<Animation>().IsPlaying(chargeAnimation)) { GetComponent<Animation>().wrapMode = WrapMode.Loop; state = STATES.ProtectingTown; GetComponent<Animation>().CrossFade(chargeAnimation); } if (isImmobalized()) { Debug.Log (gameObject.name + " - break from chase "); yield break; } yield return null; } debug = ""; //ChangeState (STATES.Attack); state = STATES.Idle; }
public void ForceIdleState() { this.nextState = STATES.IDLE; }
protected void SetState(STATES state) { // Only process state changes. // Once dead, never process state changes again. if (this.currentState == state || this.currentState == STATES.Dead) return; switch (state) { case STATES.Dead: // Just here to be explicit. Once Dead, this won't run again. See above. break; case STATES.NotDetected: this.transform.localScale = Vector3.one; this.GetComponent<Renderer>().material.color = this.startingColor; break; case STATES.Detected: this.GetComponent<Renderer>().material.color = Color.yellow; this.transform.localScale = this.activeTargetScale * 0.75f; break; case STATES.ActiveTarget: this.GetComponent<Renderer>().material.color = Color.green; this.transform.localScale = this.activeTargetScale; break; } this.currentState = state; }
/* void OnTriggerExit2D (Collider2D other) { switch (this.currentState) { case STATES.STRANGLE: if (other.gameObject.CompareTag ("Player")) { other.gameObject.SendMessage ("GetStrangled"); } this.currentState = STATES.IDLE; //Debug.Log ("Strangle damage"); break; } } */ /*---------------------------------------------------------------------------------------------------------------------- * OTHER FUNCTIONS ----------------------------------------------------------------------------------------------------------------------*/ public void GetDamage(int dir) { this.currentState = STATES.DAMAGE; this.GetComponent<Rigidbody2D> ().AddForce (new Vector2 (dir * this.damageRecoil, 100)); }
public void RevertState() { state = previousState; }
private void SetTarget(GameObject target) { //if this NPC is not in a fight then start fighting the attacker if (state != STATES.Chase && state != STATES.Chasing && state != STATES.Attack && state != STATES.Attacking ) { //ChangeState (STATES.Chase); state = Soldier.STATES.Chase; _Target = target.transform; healthScript = target.GetComponent<Health>(); //Debug.Log ("Target set to " + target + " for " + gameObject.name); } }
protected IEnumerator ChaseTargetNew() { //ChangeState (STATES.Chasing); debug = "STATES.Chasing"; state = STATES.Chasing; debug = "look at"; //look at //--lookat coroutine was causing problems -- 2/1/15 // yield return StartCoroutine(Lookat(Target.position, 2.5f, true)); transform.LookAt (Target.position); agent.stoppingDistance = attackRange; float t = Time.time; while (Vector3.Distance(Target.position, transform.position) > attackRange) { debug = "Time.time - t " + (Time.time - t).ToString() ; if (Time.time - t > 1.0f) { state = STATES.Chase; yield break; } debug = "chasing"; /*if (!GetComponent<Animation>().IsPlaying(chargeAnimation)) { GetComponent<Animation>().wrapMode = WrapMode.Loop; state = STATES.Chasing; GetComponent<Animation>().CrossFade(chargeAnimation); }*/ if (anim != null) { anim.SetFloat("speed", 1f); } if (isImmobalized()) { Debug.Log (gameObject.name + " - break from chase "); yield break; } debug = " Target.position " + Target.position; agent.SetDestination(Target.position); if (Target.position != targetCachedPos) { //Debug.Log("-- set dest ---"); debug = " targetCachedPos changed get new path"; //agent.ResetPath(); bool complete = agent.SetDestination(Target.position); debug = " set destination complete = " + complete.ToString(); debug = " set new targetCachedPos"; targetCachedPos = Target.position; yield return new WaitForFixedUpdate(); } yield return null; } debug = "STATES.Attack"; //ChangeState (STATES.Attack); //animation.CrossFade(idleAnimation); state = STATES.Attack; }
// Update is called once per frame public virtual void Update() { base.Update(); if (healthScript != null && (healthScript.isDead || healthScript.isDying)) { state = STATES.Idle; } }
// Use this for initialization public virtual void Start() { base.Start(); anim = gameObject.GetComponent<Animator> (); //ChangeState (STATES.Idle); state = STATES.Idle; }
// Update is called once per frame void Update() { if(state == STATES.CAPTURING) { if(Input.GetKeyDown("m")) { showMessage = true; state = STATES.ACK; message = "Capturing finished. Screenshots stored in " + realFolder; } else { string name = string.Format("{0}/{1:D04}_shot.png", realFolder, Time.frameCount ); Application.CaptureScreenshot (name); } } else { if(Input.GetKeyDown("m")) { state = STATES.CONFIRM; message = "Press OK to start capture movie. Quit with 'm'"; } } }
// Use this for initialization void Start() { state = STATES.DEFAULT; realFolder = ""; message = ""; }
public void GetStrangled() { this.currentState = STATES.STRANGLED; this.nextState = STATES.STRANGLED; }
public void UnRooted(GameObject attacker) { state = STATES.Unrooted; //Debug.Log(gameObject.name + " got unrooted"); }
//the different case scenarios when we move further in the game from main menu to new game, etc. public void changeState(STATES state) { UIElementCollection child = mainWindow.container.Children; child.Clear(); switch (state) { case STATES.Menu: child.Add(new GameMenu(this)); break; //case STATES.Mode: child.Add(new GameMode(this)); // break; // case STATES.Level: child.Add(new GameLevel(this)); // break; //case STATES.Login: child.Add(new UserLogin(this, db)); // break; case STATES.Game: child.Add(new GameGridView(this, Player1, Player2)); break; case STATES.Ranking: child.Add(new PlayerRankings(this)); break; case STATES.Settings: child.Add(new GameSettings(this)); break; case STATES.Tutorial: child.Add(new GameTutorial(this)); break; case STATES.Profile: child.Add(new GamePlayerProfile(this, db)); break; } }
protected IEnumerator GoToTownToAttack() { //ChangeState (STATES.Chasing); GetComponent<Animation>().wrapMode = WrapMode.Loop; state = STATES.GoingToTownToAttack; GetComponent<Animation>().CrossFade(chargeAnimation); //look at //yield return StartCoroutine(Lookat(Target.position, 2.5f, true)); agent.SetDestination(TargetTown.position); agent.stoppingDistance = attackRange; while (Vector3.Distance(TargetTown.position, transform.position) > attackRange) { debug = "going to town to attack"; if (!GetComponent<Animation>().IsPlaying(chargeAnimation)) { GetComponent<Animation>().wrapMode = WrapMode.Loop; state = STATES.GoingToTownToAttack; GetComponent<Animation>().CrossFade(chargeAnimation); } if (isImmobalized()) { yield break; } yield return null; } debug = ""; //ChangeState (STATES.Attack); state = STATES.AttackTown; }
public void Rooted(GameObject attacker) { //Debug.Log(gameObject.name + " got rooted"); Target = attacker.transform; state = STATES.Rooted; }
void FixedUpdate() { this.UpdateInputAxis (); this.UpdateGrounded (); switch (currentState) { case STATES.IDLE: this.animator.Play ("player-idle"); if (this.GetAttack ()) { // Is it attacking? this.nextState = STATES.ATTACK; } else if (this.GetJump ()) { // Is it trying to jump? this.Jump (); this.nextState = STATES.ON_AIR; } else if (!this.grounded) { // Is it falling? this.nextState = STATES.ON_AIR; } else if (this.inputAxis != 0) { // Is it trying to move? this.nextState = STATES.WALKING; } else { this.nextState = STATES.IDLE; } break; case STATES.WALKING: this.animator.Play ("player-walking"); this.GetComponent<Rigidbody2D>().velocity = new Vector2 (inputAxis, this.GetComponent<Rigidbody2D>().velocity.y); if (this.GetAttack ()) { // Is it attacking? this.nextState = STATES.ATTACK; } else if (this.GetJump ()) { // Is it trying to jump? this.Jump (); this.nextState = STATES.ON_AIR; } else if (!this.grounded) { // Is it falling? this.nextState = STATES.ON_AIR; } else if (this.inputAxis == 0) { // Did it stop moving? this.nextState = STATES.IDLE; } else { this.nextState = STATES.WALKING; } break; case STATES.ATTACK: this.GetComponent<Rigidbody2D>().velocity = new Vector2 (0, this.GetComponent<Rigidbody2D>().velocity.y); this.attackCollider.SetActive (true); if (this.comboCount == 0) { this.comboCount = 1; this.animator.Play("player-attack-1"); } this.comboTime += Time.deltaTime; if (this.comboTime < this.comboMinTime) { attackCollider.GetComponent<Renderer>().material.color = Color.white; } else if (this.comboTime > this.comboMinTime && this.comboTime < this.comboMaxTime) { attackCollider.GetComponent<Renderer>().material.color = Color.blue; if (this.GetAttack ()) { if (Input.GetButton("Fire2-"+playerNumber) && this.comboCount < 3) { this.attackCollider.SetActive (false); this.comboTime = 0f; this.comboCount = 0; this.animator.Play("player-strangle-begin"); this.nextState = STATES.STRANGLE; } else if (Input.GetButton("Fire2-"+playerNumber) && this.comboCount >= 3 && this.comboCount < 5) { this.attackCollider.SetActive (false); this.comboCount = 10; this.comboTime = 0f; this.animator.Play("player-knee-in-the-face"); } else if (this.comboCount < 4){ this.attackCollider.SetActive (false); this.comboCount++; this.comboTime = 0f; this.animator.Play("player-attack-" + this.comboCount); } } } else if (this.comboTime > this.comboMaxTime) { this.comboTime = 0f; this.nextState = STATES.IDLE; this.attackCollider.SetActive (false); this.comboCount = 0; } else { this.nextState = STATES.ATTACK; } break; case STATES.STRANGLE: this.attackCollider.SetActive (true); this.strangleTime += Time.deltaTime; this.UpdateStrangle (); if (this.strangle) { if (this.strangleTime < this.strangleMinTime) { } else if (this.strangleTime > this.strangleMinTime && this.strangleTime < this.strangleMaxTime) { if (this.GetAttack () && Input.GetButton("Fire2-"+playerNumber)) { this.strangleTime = 0f; this.attackCollider.SetActive (true); this.animator.Play ("player-strangle-attack"); this.strangledEnemy.SendMessage ("GetStrangleDamage"); } } else if (this.strangleTime > this.strangleMaxTime) { this.strangleTime = 0f; this.nextState = STATES.IDLE; this.attackCollider.SetActive (false); this.strangledEnemy.SendMessage ("ForceIdleState"); } } else { this.strangleTime = 0f; this.nextState = STATES.IDLE; this.strangledEnemy.SendMessage ("ForceIdleState"); } break; case STATES.ON_AIR: this.animator.Play("player-jump"); this.GetComponent<Rigidbody2D>().velocity = new Vector2 (inputAxis, this.GetComponent<Rigidbody2D>().velocity.y); if (this.grounded) { nextState = STATES.IDLE; } break; case STATES.DAMAGE: this.nextState = STATES.IDLE; this.animator.Play ("player-damage"); break; case STATES.STRANGLED: this.animator.Play ("player-strangled"); break; default: break; } this.FixScaleX (); currentState = nextState; }