Esempio n. 1
0
        void Update()
        {
            if (source != null && !source.isPlaying)
            {
                if (_timer == null)
                {
                    StartNewTimer();
                }
                else
                {
                    _timer.Update();
                }

                if (_timer.hasEnded)
                {
                    _timer = null;
                    source.Play();
                }
            }
        }
Esempio n. 2
0
        protected virtual void Update()
        {
            if (state == GameState.Loading)
            {
                if (_loadingTimer != null)
                {
                    _loadingTimer.Update();
                }

                if (loadingOperation != null)
                {
                    if (loadingOperation.isDone)
                    {
                        loadingOperation = null;
                    }
                }

                if (loadingOperation == null)
                {
                    loadingOperation = null;

                    if (_loadingTimer != null)
                    {
                        if (_loadingTimer.hasEnded)
                        {
                            _loadingTimer = null;
                        }
                    }
                    else
                    {
                        InitLevel();
                    }
                }
            }
            else
            {
                timers.Update();
            }
        }
Esempio n. 3
0
        // ================================================================================
        //  private methods
        // --------------------------------------------------------------------------------

        private void UpdateTimers(List <Timer> timers)
        {
            _timersToDelete.Clear();

            for (int i = 0; i < timers.Count; i++)
            {
                Timer timer = timers[i];

                timer.Update();

                if (timer.hasEnded)
                {
                    callbacks[timer]();
                    callbacks.Remove(timer);

                    _timersToDelete.Add(timer);
                }
            }

            for (int i = 0; i < _timersToDelete.Count; i++)
            {
                timers.Remove(_timersToDelete[i]);
            }
        }
Esempio n. 4
0
 public void Update()
 {
     _timer.Update();
 }
Esempio n. 5
0
        void FixedUpdate()
        {
            // do nothing when game is not running
            if (BaseGameController.Instance.state != GameState.Running && BaseGameController.Instance.state != GameState.Sequence)
            {
                return;
            }

            // slow movement
            if (_rigidbody2D != null)
            {
                if (_rigidbody2D.velocity.magnitude < 0.005f)
                {
                    _rigidbody2D.velocity = Vector2.zero;
                    lookDirection         = Vector2.zero;
                }
                else
                {
                    _rigidbody2D.velocity = Vector2.Lerp(_rigidbody2D.velocity, Vector2.zero, Time.fixedDeltaTime * 5.0f);
                }
            }

            // do nothing when dead
            if (state == ActorState.Disabled || state == ActorState.Dead)
            {
                return;
            }

            // timer for hit visuals
            if (_hitTimer != null && isAlive)
            {
                _hitTimer.Update();

                if (_hitTimer.hasEnded)
                {
                    HideDamageDisplay();
                }
            }

            // update target
            target.Update();

            // update movement
            if (state == ActorState.Moving)
            {
                if (!target.hasTarget)
                {
                    isMoving = false;
                    state    = ActorState.Idle;
                    return;
                }
                else
                {
                    MoveTowardsTarget();
                }
            }

            // resume actions when idle
            if (state == ActorState.Idle && target.hasTarget &&
                !(weapon.type == Weapon.WeaponType.Healing && target.otherActor != null && target.otherActor.health >= target.otherActor.maxHealth))
            {
                state = ActorState.Moving;
                return;
            }

            // update action
            if (_actionTimer != null)
            {
                _actionTimer.Update();
                if (_actionTimer.hasEnded)
                {
                    state        = ActorState.Idle;
                    _actionTimer = null;
                }
            }
        }