Example #1
0
        public void Update(float secondsElapsed, PlayerTank playerTank)
        {
            var vectorToPlayer = playerTank.Position - this.position;
            var angleToPlayer  = Math.Atan2(vectorToPlayer.Y, vectorToPlayer.X) + Math.PI * 0.5;

            double clockwiseDist, counterDist;

            if (rotation > angleToPlayer)
            {
                clockwiseDist = Pi2 + angleToPlayer - rotation;
                counterDist   = rotation - angleToPlayer;
            }
            else
            {
                clockwiseDist = angleToPlayer - rotation;
                counterDist   = Pi2 + rotation - angleToPlayer;
            }
            if (clockwiseDist < counterDist)
            {
                RotateRight(secondsElapsed);
            }
            else
            {
                RotateLeft(secondsElapsed);
            }
        }
Example #2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent( )
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Bullet.Load(this.Content);
            playerTank         = new PlayerTank( );
            enemyTank          = new EnemyTank( );
            Tank.Texture       = this.Content.Load <Texture2D>("tank");
            _stoneTexture      = this.Content.Load <Texture2D>("Block_tile");
            _woodTexture       = this.Content.Load <Texture2D>("Block_wood");
            _backgroundTexture = this.Content.Load <Texture2D>("sand");
            Explosion.Load(this.Content);

            _terrain = Enumerable.Range(1, 100)
                       .Select(i => RandomTerrain( ))
                       .ToArray( )
                       .Distinct(new BlockLocationComparer( ))
                       .ToArray( );
        }