title: How to enable shooting using angles?
body: <p>Sitting and making a 2d shooting game where my player needs to be able to shoot up left and up right using angles. The problem I have is I can't find a way to make this work.</p>
  
  <p>So how do I calculate the angle to shoot the bullet a specific angle?</p>
  
  <p>My code in player class</p>
  
  <pre><code>class Player
  {
      //Player 
      public Rectangle playercollisionbox;
      public Texture2D Playertexture;
      public Vector2 Position = new Vector2(470, 850);
  
  
  
      //Bullet
      public Texture2D bulletTexture;
      //How fast you shoot
      public float bulletDelay = 1;
      public List&lt;Bullet&gt; bulletList;
  
      //Angle bullet
      public float spriterotation = 0;
      public float speed = 1;
      public Vector2 bulletposition;
  
  
      //Health
      public int Health;
      public Vector2 healthbarposition = new Vector2(20, 40);
      public Texture2D healthbartexture;
      public Rectangle healthrectangle;
  
  
      //Contructor
      public Player()
      {
          bulletList = new List&lt;Bullet&gt;();
          Health = 200;
      }
  
      public void LoadContent(ContentManager Content)
      {
  
          bulletTexture = Content.Load&lt;Texture2D&gt;(@"images/projectile2");
          healthbartexture = Content.Load&lt;Texture2D&gt;(@"images/HealthBar");
  
  
  
  
      }
  
      public void Update(GameTime gameTime)
      {
  
  
          KeyboardState keyboardState = Keyboard.GetState();
  
          playercollisionbox = new Rectangle((int)Position.X, (int)Position.Y, Playertexture.Width, Playertexture.Height); 
          //Player movement
          if (keyboardState.IsKeyDown(Keys.Up))
          {
              Position.Y -= 7;
          }
  
          if (keyboardState.IsKeyDown(Keys.Left))
          {
              Position.X -= 7;
          }
          if (keyboardState.IsKeyDown(Keys.Down))
          {
              Position.Y += 7;
          }
          if (keyboardState.IsKeyDown(Keys.Right))
          {
              Position.X += 7;
          }
          //Player movement
  
          healthrectangle = new Rectangle((int)healthbarposition.X, (int)healthbarposition.Y, Health, 25);
  
          //Off-screen block
          if (Position.X &lt; 0)
          {
              Position.X = 0;
          }
          if (Position.Y &lt; 0)
          {
              Position.Y = 0;
          }
          if (Position.X &gt; 943)
          {
              Position.X = 943;
          }
          if (Position.Y &gt; 904)
          {
              Position.Y = 904;
          }
  
          //Bullet
          if (keyboardState.IsKeyDown(Keys.Space))
          {
              Shoot();
          }
          UpdateBullet();
  
      }
  
      public virtual void Draw(SpriteBatch spriteBatch)
      {
  
          spriteBatch.Draw(Playertexture, Position, Color.White);
          foreach (Bullet b in bulletList)
          {
              b.Draw(spriteBatch);
          }
          spriteBatch.Draw(healthbartexture, healthrectangle, Color.White);
      }
      //Shooting method 
      public void Shoot()
      {
          if (bulletDelay &gt;= 0)
          {
              bulletDelay--;
          }
          if (bulletDelay &lt;= 0)
          {
              //First Bullet
              Bullet newBullet = new Bullet(bulletTexture);
              newBullet.position = new Vector2(Position.X + 40 - newBullet.texture.Width / 2, Position.Y - 40);
              newBullet.isVisible = true;
              //Second Bullet
  
  
  
  
  
              if (bulletDelay == 0)
              {
                  bulletDelay = 20;
              }
  
              if (bulletList.Count() &lt; 20)
              {
                  bulletList.Add(newBullet); 
              }
  
  
          }
      }
      //Updating bullet after shooting
      public void UpdateBullet()
      {
          //speed on nullet
          foreach (Bullet b in bulletList)
          {
  
              b.position.Y = b.position.Y - b.speed;
              b.bulletcollisionbox = new Rectangle((int)b.position.X, (int)b.position.Y, b.texture.Width, b.texture.Height);
  
              //outside screen removes it
              if (b.position.Y &lt;= 0)
              {
                  b.isVisible = false;
              }
          }
  
          for (int i = 0; i &lt; bulletList.Count; i++)
            {
                if (!bulletList[i].isVisible)
                {
                    bulletList.RemoveAt(i);
                    i--;
                }
            }
  
      }
  
   }
  </code></pre>
  
  <p>My Bullet Class</p>
  
  <pre><code> public class Bullet
  {
      public Texture2D texture;
      public Vector2 origin;
  
      public Vector2 position;
      public bool isVisible;
      public float speed;
      public Rectangle bulletcollisionbox;
  
  
  
  
      public Bullet(Texture2D newTexture)
      {
          speed = 10;
          texture = newTexture;
          isVisible = false;
      }
  
      public void Draw(SpriteBatch spriteBatch)
      {
  
          spriteBatch.Draw(texture, position, Color.White);
      }
  }
  </code></pre>