コード例 #1
0
ファイル: BaseSerpent.cs プロジェクト: danbystrom/Serpent
        public virtual void Update(GameTime gameTime)
        {
            var lengthSpeed = (11 - _serpentLength) / 10f;
            var speed       = (float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.0045f * lengthSpeed * modifySpeed();

            if (_whereabouts.Direction != Direction.None)
            {
                _fractionAngle += speed;
                if (_fractionAngle >= 1)
                {
                    _fractionAngle        = 0;
                    _whereabouts.Location = _whereabouts.NextLocation;
                    takeDirection();
                }
                _whereabouts.Fraction = (float)Math.Sin(_fractionAngle * MathHelper.PiOver2);
            }
            else
            {
                takeDirection();
            }

            if (_tail != null)
            {
                _tail.Update(gameTime, GetPosition(), speed);
            }

            if (_whereabouts.Direction != Direction.None)
            {
                _headDirection = _whereabouts.Direction;
            }
        }
コード例 #2
0
        public void Update(GameTime gameTime, Vector3 prevPos, float speed)
        {
            var pos = GetPosition();

            if (PathToWalk.Count != 1)
            {
                var distance = Vector3.DistanceSquared(pos, prevPos);
                var w        = PathToWalk[0];
                w.Fraction += speed; // *distance;
                if (w.Fraction >= 1)
                {
                    PathToWalk.RemoveAt(0);
                }
                else
                {
                    PathToWalk[0] = w;
                }
            }
            if (Next != null)
            {
                Next.Update(gameTime, pos, speed);
            }
        }