private IEnumerator LockingCrossHairOnEnemy() { _state = HunterState.LOCKING_CROSSHAIR_ON_ENEMY; _crossHair.visible = true; SpriteTweener.TweenAlpha(_hunterFollowRangeCone, 0, 0.4f, 500); //Seeking target do { var crossHairWorldPos = TransformPoint(_crossHair.Pos.x, _crossHair.Pos.y); var distance = _enemy.Pos - crossHairWorldPos; var distanceNorm = distance.Normalized; var nextPos = distanceNorm * _sightSpeed * Time.delta; _crossHair.Translate(nextPos.x, nextPos.y); if (!IsEnemyInRange()) { _lostLockOnEnemyOutOfRangeRoutine = _lostLockOnEnemyOutOfRangeRoutine = CoroutineManager.StartCoroutine(LostLockOnEnemyOutOfRangeRoutine(_enemy), this); } yield return(null); } while (_state == HunterState.LOCKING_CROSSHAIR_ON_ENEMY); }
private IEnumerator ShootAtEnemyRoutine(GameObject enemy) { _state = HunterState.SHOOT; SoundManager.Instance.PlayFx(3); Console.WriteLine($"{this}: SHOOT!!!"); for (int i = 0; i < _hunterBehaviorListeners.Length; i++) { _hunterBehaviorListeners[i].OnShootAtEnemy(this, _aimDistance, enemy); } //Cooldown _state = HunterState.RECOVER_FROM_SHOOT; yield return(new WaitForMilliSeconds(1500)); if (IsEnemyInRange()) { _scanningForEnemyRoutine = CoroutineManager.StartCoroutine(ScanningForEnemy(HunterState.SCANNING, false), this); } else { _lostLockOnEnemyOutOfRangeRoutine = CoroutineManager.StartCoroutine(LostLockOnEnemyOutOfRangeRoutine(enemy), this); } }
public void EndLevel() { _state = HunterState.END_LEVEL; HunterBehaviorListeners = null; CoroutineManager.StopAllCoroutines(this); CoroutineManager.StartCoroutine(EndLevelRoutine(), this); }
private float m_downSpeed = 5.0f; // 速度減少 //---------------------------------------------------------------------- //! @brief 初期化処理 //! //! @param[in] なし //! //! @return なし //---------------------------------------------------------------------- void Start() { m_state = new HunterChaseState(); m_nextState = m_state; m_player = GameObject.Find("Player"); m_navMeshAgent = GetComponent <NavMeshAgent>(); m_defaultSpeed = m_navMeshAgent.speed; }
private void ToPursue() { _state = HunterState.Pursue; _steering._settings = _pursueSettings; List <IBehaviour> behaviours = new List <IBehaviour>(); behaviours.Add(new Pursue()); _steering.SetBehaviours(behaviours, "pursue"); }
private void ToApproach() { _state = HunterState.Approach; _steering._settings = _approachSettings; List <IBehaviour> behaviours = new List <IBehaviour>(); behaviours.Add(new Pursue()); _steering.SetBehaviours(behaviours, "Approach"); }
private void ToIdle() { _state = HunterState.Idle; _steering._settings = _idleSettings; List <IBehaviour> behaviours = new List <IBehaviour>(); behaviours.Add(new Idle()); _steering.SetBehaviours(behaviours, "Idle"); }
public override void Update(GameTime gameTime) { if (Keyboard.GetState().IsKeyDown(Keys.Right)) { frameTimer += gameTime.ElapsedGameTime.TotalSeconds; flip = false; if (frameTimer >= FRAME_DURATION) { frameTimer = 0; if (TILE_COUNT_WALK <= ++currentFrame) { currentFrame = 0; } sourceRect.X = TILE_SIZE * currentFrame; } hunterPosition += Speed; hunterState = HunterState.WalkRight; } else if (Keyboard.GetState().IsKeyDown(Keys.Left)) { frameTimer += gameTime.ElapsedGameTime.TotalSeconds; flip = true; if (frameTimer >= FRAME_DURATION) { frameTimer = 0; if (TILE_COUNT_WALK <= ++currentFrame) { currentFrame = 0; } sourceRect.X = TILE_SIZE * currentFrame; } hunterPosition -= Speed; hunterState = HunterState.WalkLeft; } if (Keyboard.GetState().IsKeyDown(Keys.Up) && hasJumped == false) { hunterPosition.Y -= 45f; hasJumped = true; } if (hasJumped == true) { jumpTimer += gameTime.ElapsedGameTime.TotalSeconds; if (jumpTimer > 0.2) { hunterPosition.Y += 45f; jumpTimer = 0.0; hasJumped = false; } } hunterPosition.X = MathHelper.Clamp(hunterPosition.X, 0, GraphicsDevice.Viewport.Width - sourceRect.Width); base.Update(gameTime); }
private IEnumerator SnapCrossHairToEnemy(GameObject enemy) { _state = HunterState.CROSSHAIR_LOCKED_ON_ENEMY; int time = 0; int duration = 300; var crossStartPos = TransformPoint(_crossHair.Pos.x, _crossHair.Pos.y); Vector2 localPos; while (time < duration) { float pointX = Easing.Ease(Easing.Equation.QuadEaseOut, time, crossStartPos.x, enemy.x - crossStartPos.x, duration); float pointY = Easing.Ease(Easing.Equation.QuadEaseOut, time, crossStartPos.y, enemy.y - crossStartPos.y, duration); localPos = InverseTransformPoint(pointX, pointY); _crossHair.SetXY(localPos.x, localPos.y); time += Time.deltaTime; yield return(null); } SpriteTweener.TweenColor(_crossHair, _crossHair.StartColor, ColorTools.ColorToUInt(Color.Red), 300); //After Snap, follow target while distance less than range //Countdown to Shoot _countDownToShootRoutine = CoroutineManager.StartCoroutine(CountDownToShootRoutine(enemy), this); do { _distanceToTarget = enemy.Pos - _pos; float distanceMag = _distanceToTarget.Magnitude; localPos = InverseTransformPoint(enemy.x, enemy.y); _crossHair.SetXY(localPos.x, localPos.y); //Lost lock on enemy, out of range if (distanceMag > _scanEnemyRange) { CoroutineManager.StopCoroutine(_countDownToShootRoutine); _lostLockOnEnemyOutOfRangeRoutine = CoroutineManager.StartCoroutine(LostLockOnEnemyOutOfRangeRoutine(enemy), this); } yield return(null); } while (_state == HunterState.CROSSHAIR_LOCKED_ON_ENEMY); }
private IEnumerator EnemyDetectedRoutine() { _state = HunterState.ENEMY_DETECTED; SpriteTweener.TweenAlpha(_crossHair, 0, 1, 400); SoundManager.Instance.SetFxVolume(4, 0.5f); yield return(new WaitForMilliSeconds(500)); //Start Lock enemy _lockingCrossHairOnEnemy = CoroutineManager.StartCoroutine(LockingCrossHairOnEnemy(), this); }
IEnumerator ScanningForEnemy(HunterState pState, bool resetCrossHairPosition) { _state = pState; _crossHair.Reset(resetCrossHairPosition); float distanceMag = float.MaxValue; do { _distanceToTarget = _enemy.Pos - _pos; distanceMag = _distanceToTarget.Magnitude; if (distanceMag < _scanEnemyRange) { //Change State to Enemy Detected _enemyDetectedRoutine = CoroutineManager.StartCoroutine(EnemyDetectedRoutine(), this); } yield return(null); } while (_state == HunterState.SCANNING); }
private IEnumerator LostLockOnEnemyOutOfRangeRoutine(GameObject enemy) { _state = HunterState.LOST_LOCK_ON_ENEMY; SpriteTweener.TweenAlpha(_hunterFollowRangeCone, 0.4f, 0, 500); SpriteTweener.TweenAlpha(_crossHair, 1, 0, 400); //Only get points when evading the first time if (_lostLockOnEnemyCounter == 0) { LocalEvents.Instance.Raise(new LevelLocalEvent(_enemy, (GameObject)this, null, LevelLocalEvent.EventType.STORK_GET_POINTS_EVADE_HUNTER)); } _lostLockOnEnemyCounter++; yield return(new WaitForMilliSeconds(1000)); //Return to scanning state _scanningForEnemyRoutine = CoroutineManager.StartCoroutine(ScanningForEnemy(HunterState.SCANNING, true), this); }
//---------------------------------------------------------------------- //! @brief 更新処理 //! //! @param[in] なし //! //! @return なし //---------------------------------------------------------------------- void Update() { // 状態変更 if (m_nextState != m_state) { m_state = m_nextState; m_state.Enter(this); } float speed = m_defaultSpeed; // 拘束されていたら速度を落とす if (m_zombieNum >= m_restraintNum) { speed /= m_downSpeed; } // 速度代入 m_navMeshAgent.speed = speed; m_zombieNum = 0; m_state.Update(this); }
//---------------------------------------------------------------------- //! @brief 状態変更 //! //! @param[in] 次の状態クラス //! //! @return なし //---------------------------------------------------------------------- public void ChangeState(HunterState state) { this.m_nextState = state; }