Esempio n. 1
0
        public bool Update(short timeStep)
        {
            // todo
            if (timeStep == 0)
            {
                _stance.Normalize();
                _stFrame.Normalize();
                _expression.Normalize();
                _expFrame.Normalize();
            }

            _alerted.Update();
            var aniEnd = false;

            if (Action == null)
            {
                var delay = GetDelay(_stance.Get(), _stFrame.Get());
                var delta = delay - _steLapSed;
                if (timeStep >= delta)
                {
                    _steLapSed = (short)(timeStep - delta);
                    var nextFrame = GetNextFrame(_stance.Get(), _stFrame.Get());
                    var threshold = (float)delta / timeStep;
                    _stFrame.Next(nextFrame, threshold);
                    if (_stFrame.Get() == 0)
                    {
                        aniEnd = true;
                    }
                }
                else
                {
                    _stance.Normalize();
                    _stFrame.Normalize();
                    _steLapSed += timeStep;
                }
            }
            else
            {
                var delay = Action.Delay;
                var delta = (short)(delay - _steLapSed);
                if (timeStep >= delta)
                {
                    _steLapSed = (short)(timeStep - delta);
                    _actFrame  = _drawInfo.NextActionFrame(_actionStr, _actFrame);
                    if (_actFrame > 0)
                    {
                        Action = _drawInfo.GetAction(_actionStr, _actFrame);
                        var threshold = (float)delta / timeStep;
                        _stance.Next(Action.Stance(), threshold);
                        _stFrame.Next(Action.GetFrame(), threshold);
                    }
                    else
                    {
                        aniEnd     = true;
                        Action     = null;
                        _actionStr = "";
                        SetStance(Stance.Id.Stand1);
                    }
                }
                else
                {
                    _stance.Normalize();
                    _stFrame.Normalize();
                    _steLapSed += timeStep;
                }
            }

            var expDelay = Face.GetDelay(_expression.Get(), _expFrame.Get());
            var expDelta = expDelay - _expELapSed;

            if (timeStep >= expDelta)
            {
                _expELapSed = (short)(timeStep - expDelta);
                var nextExpFrame = Face.NextFrame(_expression.Get(), _expFrame.Get());
                var fcThreshold  = (float)expDelta / timeStep;
                _expFrame.Next(nextExpFrame, fcThreshold);
                if (_expFrame.Get() == 0)
                {
                    _expression.Next(
                        _expression.Get() == Expression.Id.Default ? Expression.Id.Blink : Expression.Id.Default,
                        fcThreshold);
                }
            }
            else
            {
                _expression.Normalize();
                _expFrame.Normalize();
                _expELapSed += timeStep;
            }

            return(aniEnd);
        }
Esempio n. 2
0
        public bool Update(short timeStep = GameUtil.TimeStep)
        {
            var frameData = Frame;

            _opacity.Set(_opacity + frameData.OpcStep(timeStep));
            if (_opacity.Last() < 0f)
            {
                _opacity.Set(0f);
            }
            else if (_opacity.Last() > 255f)
            {
                _opacity.Set(255f);
            }
            _xyScale.Set(_xyScale + frameData.ScaleStep(timeStep));
            if (_xyScale.Last() < 0f)
            {
                _opacity.Set(0f);
            }
            if (timeStep >= _delay)
            {
                var   lastFrame = (short)(_frames.Count - 1);
                short nextFrame;
                bool  endEd;
                if (_zigzag && lastFrame > 0)
                {
                    if (_frameStep == 1 && _frame.Get() == lastFrame)
                    {
                        _frameStep = (short)-_frameStep;
                        endEd      = false;
                    }
                    else if (_frameStep == -1 && _frame.Get() == 0)
                    {
                        _frameStep = (short)-_frameStep;
                        endEd      = true;
                    }
                    else
                    {
                        endEd = false;
                    }

                    nextFrame = (short)(_frame.Get() + _frameStep);
                }
                else
                {
                    if (_frame.Get() == lastFrame)
                    {
                        nextFrame = 0;
                        endEd     = true;
                    }
                    else
                    {
                        nextFrame = (short)(_frame.Get() + 1);
                        endEd     = false;
                    }
                }

                var delta     = (short)(timeStep - _delay);
                var threshold = (float)delta / timeStep;
                _frame.Next(nextFrame, threshold);

                _delay = _frames[nextFrame].Delay;
                if (_delay >= delta)
                {
                    _delay -= delta;
                }
                _opacity.Set(_frames[nextFrame].StartOpacity);
                _xyScale.Set(_frames[nextFrame].StartScale);
                return(endEd);
            }
            else
            {
                _frame.Normalize();
                _delay -= timeStep;
                return(false);
            }
        }