title: XNA: Need help spawning enemies on any side, on a timer tick, then maving them move randomly
body: <p>Ok so I am making a 2d shooting game in XNA and have hit a bit of a snag. I am trying to make an enemy class that will allow me to spawn an enemy just off screen every 10 seconds, then have it move randomly in either up, right left or down. After spending the better part of 4 hours scouring the internet all I have found is examples making the enemy move one direction, spawn from one point and so on.</p>
  
  <p>Any help would be much appreciated, my enemy class is a bit of a mess at the minute from dragging together so much code to try and make it work. Here it is as it stands:</p>
  
  <pre><code>using Microsoft.Xna.Framework;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace Shark_Wars_2
  {
      class Enemy
      {
          List&lt;Vector2&gt; sharkPosition = new List&lt;Vector2&gt;(); //is there a better way for having more than one of the same enemy?
          public Vector2 sharkDirection;
  
          public int sharkWidth;
          public int sharkHeight;
  
          public int sharkSpeed;
  
          float sharkSpawnProbability;
  
          public Random randomSharkPosition;
          public Random direction;
  
          double timer = 0;
          float interval = 1000;
          int speed = 1;
  
          public Enemy()
          {
              sharkPosition = new Vector2(0, 0); //brings up error - see above
  
              sharkWidth = 64;
              sharkHeight = 44;
  
              sharkSpeed = 3;
  
              sharkSpawnProbability = 1 / 10000f;
  
              randomSharkPosition = new Random(3); //left, right, up, down
              direction = new Random(3);
  
          }
  
          public void update(GameTime gameTime)
          {
              //enemy movement
              for (int i = 0; i &lt; sharkPosition.Count; i++)
              {
                  //enemy position increases by speed
                  sharkPosition[i] = new Vector2(sharkPosition[i].X + sharkDirection.X, sharkPosition[i].Y + sharkDirection.Y);
              }
  
              timer += gameTime.ElapsedGameTime.TotalMilliseconds;
  
              //aniamtion
              if (timer &gt;= interval / speed)
              {
                  timer = 0;
              }
  
              //spawn new enemy
              if (randomSharkPosition.NextDouble() &lt; sharkSpawnProbability)
              {
                  float spawn = (float)randomSharkPosition.NextDouble() * (1280 - sharkHeight); sharkPosition.Add(new Vector2(sharkDirection.X, sharkDirection.Y));
              }
          }
  
          // ill worry about drawing after spawning and movement, should be no problem
          public void draw()//(SpriteBatch spritebatch, Texture2D wave)
          {
              for (int i = 0; i &lt; sharkPosition.Count; i++)
              {
                  //spritebatch.Draw(shark, new Rectangle((int)sharkPosition[i].X, (int)sharkPosition[i].Y, sharkWidth, sharkHeight);
              }
          }
      }
  }
  </code></pre>
  
  <p>my head is really blocked, I spent a lot of time working out how to make moving background objects and a list of bullets.</p>
  
  <p>I would really like to simplify this down too so if you know of an easier way of doing things I am all ears!</p>
  
  <p>Thanks in advance!</p>