示例#1
0
        public virtual void Update(GameTime gameTime)
        {
            float tanRot = (float)Math.Tan(_parent.RotationInRadians);
            float cosRot = (float)Math.Cos(_parent.RotationInRadians);
            float sinRot = (float)Math.Sin(_parent.RotationInRadians);

            _parent.Position += _parent.Speed;

            if (GameManager.GameManager.InfiniteWorld)
            {
                if (_parent.Position.X < 0)
                {
                    _parent._position.X = GameManager.GameManager._WidthGame;
                }
                else if (_parent.Position.X > GameManager.GameManager._WidthGame)
                {
                    _parent._position.X = 0;
                }

                if (_parent.Position.Y < 0)
                {
                    _parent._position.Y = GameManager.GameManager._HeightGame;
                }
                else if (_parent.Position.Y > GameManager.GameManager._HeightGame)
                {
                    _parent._position.Y = 0;
                }
            }
            if (_parent.FadeTime > 0)
            {
                _parent.FadeTime -= gameTime.ElapsedGameTime.Milliseconds;
            }

            /////////////inputs
            _accel      = _accelFactor * _inputs.Y * _inputsLength;
            _accelVec.X = cosRot * _accel;
            _accelVec.Y = sinRot * _accel;

            if (_accel >= 0)
            {
                _parent.Speed += _accelVec;
            }
            else
            {
                _parent.Speed *= (float)(1 - _friction * ((0.2f - _accel) / 0.2f));
            }
            _parent.RotationInDegrees += ROTATION_SPEED * _inputs.X;

            if (_accel == 0)
            {
                _parent.Speed *= 1 - _friction;
            }

            if (Utilitaire.DiffVec2(_parent.Speed) > _parent.getMaxSpeed())
            {
                _parent.Speed *= _parent.getMaxSpeed() / Utilitaire.DiffVec2(_parent.Speed);
            }
        }
示例#2
0
        /// <summary>
        /// Gère l'affichage du radar
        /// </summary>
        /// <param name="spriteBatch"></param>
        public void Draw(SpriteBatch spriteBatch)
        {
            Vector2        tmpVec;
            List <Vector2> tmpClonePosition = new List <Vector2>();

            XnaDebugDrawer.DebugDrawer.DrawCircle(spriteBatch, _position, _size, _bgRadar, 3, 100);
            XnaDebugDrawer.DebugDrawer.DrawCircle(spriteBatch, _position, 3, _bgRadar, 3, 4);

            foreach (MovingObject enemi in _enemies)
            {
                tmpClonePosition.Clear();
                if (Utilitaire.DiffVec2(enemi.Position - _ship.Position) < this._range)
                {
                    tmpClonePosition.Add(enemi.Position);
                }
                if (GameManager.GameManager.InfiniteWorld)
                {
                    tmpVec = new Vector2(enemi.Position.X - GameManager.GameManager._WidthGame, enemi.Position.Y);
                    if (Utilitaire.DiffVec2(tmpVec - _ship.Position) < this._range)
                    {
                        tmpClonePosition.Add(tmpVec);
                    }
                    tmpVec = new Vector2(enemi.Position.X + GameManager.GameManager._WidthGame, enemi.Position.Y);
                    if (Utilitaire.DiffVec2(tmpVec - _ship.Position) < this._range)
                    {
                        tmpClonePosition.Add(tmpVec);
                    }
                    tmpVec = new Vector2(enemi.Position.X, enemi.Position.Y - GameManager.GameManager._HeightGame);
                    if (Utilitaire.DiffVec2(tmpVec - _ship.Position) < this._range)
                    {
                        tmpClonePosition.Add(tmpVec);
                    }
                    tmpVec = new Vector2(enemi.Position.X, enemi.Position.Y + GameManager.GameManager._HeightGame);
                    if (Utilitaire.DiffVec2(tmpVec - _ship.Position) < this._range)
                    {
                        tmpClonePosition.Add(tmpVec);
                    }
                }

                if (tmpClonePosition.Count > 0)
                {
                    foreach (Vector2 point in tmpClonePosition)
                    {
                        tmpVec = _position + new Vector2(((point.X - _ship.Position.X) / _range) * _size, (((point.Y - _ship.Position.Y) / _range) * _size));
                        XnaDebugDrawer.DebugDrawer.DrawCircle(spriteBatch, tmpVec, 3, _colorEnemies, 3, 4);
                    }
                }
            }
        }
        public override void Update(GameTime gameTime)
        {
            float tanRot = (float)Math.Tan(_parent.RotationInRadians);
            float cosRot = (float)Math.Cos(_parent.RotationInRadians);
            float sinRot = (float)Math.Sin(_parent.RotationInRadians);

            _parent.Position += new Vector2(_parent.MAX_SPEED / 2 + _parent.SpeedX, _parent.Speed.Y);

            _inputs = new Vector2(_inputs.X, -_inputs.Y);
            if (GameManager.GameManager.InfiniteWorld)
            {
                if (_parent.Position.X < 0)
                {
                    _parent._position.X = GameManager.GameManager._WidthGame;
                }
                else if (_parent.Position.X > GameManager.GameManager._WidthGame)
                {
                    _parent._position.X = 0;
                }

                if (_parent.Position.Y < 0)
                {
                    _parent._position.Y = GameManager.GameManager._HeightGame;
                }
                else if (_parent.Position.Y > GameManager.GameManager._HeightGame)
                {
                    _parent._position.Y = 0;
                }
            }
            if (_parent.FadeTime > 0)
            {
                _parent.FadeTime -= gameTime.ElapsedGameTime.Milliseconds;
            }

            /////////////inputs
            _accel    = _accelFactor;
            _accelVec = _inputs * _accelFactor;


            _parent.Speed += _accelVec;

            _parent.Speed *= (float)(1 - _friction);



            /* if (_parent.RotationInDegrees - rotationTarget < ROTATION_SPEED * 5)
             * {*/
            _parent.RotationInDegrees = 0;

            /*}
             * else if (rotationTarget - _parent.RotationInDegrees < 180)
             * {
             *  _parent.RotationInDegrees += ROTATION_SPEED * 4;
             * }
             * else
             * {
             *  _parent.RotationInDegrees -= ROTATION_SPEED * 4;
             * }*/
            // _parent.RotationInRadians = (rotationTarget+_parent.RotationInRadians)/2;

            /*
             * if (_accel == 0)
             * {
             *  _parent.Speed *= 1- _friction;
             * }*/

            if (Utilitaire.DiffVec2(_parent.Speed) > _parent.getMaxSpeed() * 4)
            {
                _parent.Speed *= _parent.getMaxSpeed() * 4 / Utilitaire.DiffVec2(_parent.Speed);
            }
        }