Beispiel #1
0
        /// <summary>
        /// Renders model.
        /// </summary>
        /// <param name="spriteBatch">Object for performing drawing actions.</param>
        public void Render(SpriteBatch spriteBatch)
        {
            var bodyTexture        = _textureStorage.TankBodyTexture;
            var turretTexture      = _textureStorage.TankTurretTexture;
            var bodyTextureCenter  = new Vector2(bodyTexture.Width / 2, bodyTexture.Height / 2);
            var turretTexturePivot = new Vector2(22, 20);             // TODO: Get it from model config.

            var bodyPosition        = _tank.Position;
            var turretPivotPosition = bodyPosition.MovedByVector(VectorD.Polar(-10.0, _tank.Heading));

            spriteBatch.Draw(bodyTexture, (Vector2)bodyPosition, null, Color.White,
                             (float)_tank.Heading, bodyTextureCenter, 1f, SpriteEffects.None, 0f);
            spriteBatch.Draw(turretTexture, (Vector2)turretPivotPosition, null, Color.White,
                             (float)_tank.TurretHeading, turretTexturePivot, 1f, SpriteEffects.None, 0f);
        }
Beispiel #2
0
        public void UpdatePosition(TimeSpan timeDelta)
        {
            double time = timeDelta.TotalSeconds;

            Position = Position.MovedByVector(VectorD.Polar(Speed * time, Heading));
            Speed   += Acceleration * time;

            double turn = TurnSpeed * time;

            Heading       += turn;
            TurretHeading += turn;

            // Calculate turret heading:
            double targetTurretHeading = VectorD.Cartesian(_target.X - Position.X, _target.Y - Position.Y).Heading;
            double turretHeadingDelta  = targetTurretHeading - TurretHeading;
            double turretHeadingChange = Math.Sign(turretHeadingDelta) *
                                         Math.Min(Math.Abs(turretHeadingDelta), TurretTurnSpeedConstant);

            TurretHeading += turretHeadingChange;
        }