public Projectile(ContentManager manager, Ship ship)
 {
     this.ship = ship;
     this.texture = manager.Load<Texture2D>("Projectile");
     this.rectangle = new Rectangle(ship.Rectangle.X + 15,ship.Rectangle.Y + 1,45,45);
     this.Hit = false;
 }
 public Upgrade(ContentManager content, string font, string text, Ship ship)
 {
     this.font = content.Load<SpriteFont>(font);
     this.position.X = ship.Rectangle.X;
     this.position.Y = ship.Rectangle.Y-10;
     this.text = text;
     this.ship = ship;
 }
 public void Update(Ship target, Ship attacker)
 {
     if (this.rectangle.Intersects(target.Rectangle))
     {
         this.Hit = true;
     }
     if (attacker.Rectangle.Y > target.Rectangle.Y)
     {
         this.rectangle.Y -= 2;
     }
     else
     {
         this.rectangle.Y += 2;
     }
 }
 public override void Update(Ship playerShip, ref GameState gameState, GameTime gameTime)
 {
     if (gameState == GameState.FreeRoam)
     {
         if (this.Rectangle.Intersects(playerShip.Rectangle))
         {
             gameState = GameState.Combat;
             this.IsInCombat = true;
         }
         if(destination.X!=0 && destination.Y!=0)
         {
             if(this.rectangle.X!=destination.X && this.rectangle.Y!=destination.Y && reached==false)
             {
                 Vector2 trajectory = destination - this.initialCoordinates;
                 trajectory.Normalize();
                 this.rectangle.X += (int)(trajectory.X * speed);
                 this.rectangle.Y += (int)(trajectory.Y * speed);
             }
             else
             {
                 reached = true;
                 if(reached)
                 {
                     Vector2 trajectory = this.initialCoordinates - destination;
                     trajectory.Normalize();
                     this.rectangle.X += (int)(trajectory.X * speed);
                     this.rectangle.Y += (int)(trajectory.Y * speed);
                     if(this.rectangle.X==this.initialCoordinates.X && this.rectangle.Y==this.initialCoordinates.Y)
                     {
                         reached = false;
                     }
                 }
             }
             
         }
         
     }
     if (gameState == GameState.Combat)
     {
         this.RandomMovement(gameTime, playerShip);
     }
     base.Update(playerShip, ref gameState, gameTime);
 }
 public virtual void Update(Ship target, ref GameState gameState, GameTime gameTime)
 {
     if (gameState==GameState.Combat)
     {
         for (int i = this.Bullets.Count - 1; i >= 0; i--)
         {
             if (this.Bullets[i].Hit)
             {
                 target.TakeDamage(this.Damage);
                 if (target.IsDestroyed)
                 {
                     this.rectangle.X = (int)target.initialCoordinates.X;
                     this.rectangle.Y = (int)target.initialCoordinates.Y;
                     this.Bullets.Clear();
                     gameState = GameState.FreeRoam;
                     return;
                 }
                 this.Bullets.RemoveAt(i);
             }
         }
         foreach (var item in this.Bullets)
         {
             item.Update(target, this);
         }
     }
 }
 private void RandomMovement(GameTime gameTime, Ship playership)
 {
     List<IDrawableCustom> ships = new List<IDrawableCustom> { playership };
     rnd = new Random();
     int direction = rnd.Next(1, 5);
     int fireDelay = rnd.Next(1, 3);
     if (Math.Abs(gameTime.TotalGameTime.TotalSeconds - this.time) > fireDelay)
     {
         this.Fire(gameTime);
     }
     if (Math.Abs(gameTime.TotalGameTime.TotalSeconds - this.time) > 1)
     {
         switch (direction)
         {
             case 1:
                 this.handler = new MoveAction(this.MoveUp);
                 this.time = gameTime.TotalGameTime.TotalSeconds;
                 break;
             case 2:
                 if(this.Rectangle.Bottom>=GlobalConstants.WINDOW_HEIGHT || playership.Rectangle.Top-this.Rectangle.Bottom<=50)
                 {
                     this.handler = new MoveAction(this.MoveUp);
                 }
                 else
                 {
                     this.handler = new MoveAction(this.MoveDown);
                 } 
                 this.time = gameTime.TotalGameTime.TotalSeconds;
                 break;
             case 3:
                 this.handler = new MoveAction(this.MoveRight);
                 this.time = gameTime.TotalGameTime.TotalSeconds;
                 break;
             case 4:
                 this.handler = new MoveAction(this.MoveLeft);
                 this.time = gameTime.TotalGameTime.TotalSeconds;
                 break;
         }
     }
     this.handler(ships);
 }
 public HullUpgrade(ContentManager content, string font, string text, Ship ship) : base(content, font, text,ship)
 {
 }