title: Move enemy sprite depending on which side it spawns. c# monogame
body: <p>So I have a code where the sprite spawn outside the window and I want it to move on a specific straight line depending on where it spawn say if the sprite spawn at the top it goes at the bottom and vise versa if the sprite then spawn to the left it will go right and vise versa.</p>
  
  <p>Game1.cs code:</p>
  
  <pre><code>public class Game1 : Game
  {
      GraphicsDeviceManager graphics;
      SpriteBatch spriteBatch;
      Player player;
      List&lt;Enemy&gt; enemies = new List&lt;Enemy&gt;();
  
  
      public Vector2 ecords
      {
          get { return ecords; }
          set { ecords = value; }
      }
  
  
  
      public Game1()
      {
          graphics = new GraphicsDeviceManager(this);
          Content.RootDirectory = "Content";
      }
  
  
      protected override void Initialize()
      {
  
  
          base.Initialize();
      }
  
  
      protected override void LoadContent()
      {
          spriteBatch = new SpriteBatch(GraphicsDevice);
          //player
          Texture2D playertexture = Content.Load&lt;Texture2D&gt;("Player");
          player = new Player(new Vector2(350, 175), playertexture);
  
          //enemy
          Texture2D enemytexture = Content.Load&lt;Texture2D&gt;("Enemy");
          Random random = new Random();
          var width = GraphicsDevice.Viewport.Width;
          var height = GraphicsDevice.Viewport.Height;
  
          for (int i = 0; i &lt; 20; i++)
          {
              enemies.Add(new Enemy(new Vector2(random.Next(width, width + 100), random.Next(0, height)), enemytexture));
              enemies.Add(new Enemy(new Vector2(random.Next(0 - 100, 0), random.Next(0, height)), enemytexture));
              enemies.Add(new Enemy(new Vector2(random.Next(0, width), random.Next(-100, 0)), enemytexture));
              enemies.Add(new Enemy(new Vector2(random.Next(0, width), random.Next(height, height + 100)), enemytexture));
          }
  
  
  
  
  
      }
  
      protected override void UnloadContent()
      {
  
      }
  
      protected override void Update(GameTime gameTime)
      {
          if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
              Exit();
          foreach (Enemy enemy in enemies)
          {
              enemy.Update(gameTime);
          }
          player.Update(gameTime);
  
  
  
          base.Update(gameTime);
      }
  
      protected override void Draw(GameTime gameTime)
      {
          GraphicsDevice.Clear(Color.CornflowerBlue);
  
          spriteBatch.Begin();
          foreach (Enemy enemy in enemies)
          {
              enemy.Draw(spriteBatch);
          }
          player.Draw(spriteBatch);
  
          spriteBatch.End();
  
          base.Draw(gameTime);
      }
  }
  </code></pre>
  
  <p>Enemy.cs</p>
  
  <pre><code>class Enemy
  {
      Texture2D enemytexture;
      Vector2 enemyposition;
  
  
      public Enemy(Vector2 enemyposition, Texture2D enemytexture)
      {
          this.enemyposition = enemyposition;
          this.enemytexture = enemytexture;
      }
      public void Update(GameTime gameTime)
      {
  
      }
  
      public void Draw(SpriteBatch spriteBatch)
      {
          spriteBatch.Draw(enemytexture, enemyposition, Color.White);
      }
  }
  </code></pre>