Exemple #1
0
 private void Move(object obj)
 {
     if (PolarCoordinateHelper.GetDirection(Coordinates, CoordinatesTo).X *_direction.X <= 0 ||
         PolarCoordinateHelper.GetDirection(Coordinates, CoordinatesTo).Y *_direction.Y <= 0)
     {
         Dispose();
         return;
     }
     Coordinates += _direction * 10;
 }
Exemple #2
0
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend,
                              null, null, null, null,
                              Camera2D.MatrixScreen);

            if (GameplayBackground != null)
            {
                GameplayBackground.Draw(SpriteBatch);
            }

            GraphicsDevice graphicsDevice = ScreenManager.Instance.GraphicsDevice;

            graphicsDevice.Clear(Color.SkyBlue);

            GameController.Instance.DrawWorld(SpriteBatch);

            // Флюгер
            GameController.Instance.ClientWindVane.Draw(SpriteBatch);

            // Корабли
            for (int i = 0; i < GameController.Instance.CurrentShips.Count(); i++)
            {
                if (GameController.Instance.CurrentShips[i] == null)
                {
                    continue;
                }
                GameController.Instance.CurrentShips[i].Draw(SpriteBatch);

                // Если наш корабль - отображаем данные
                if (GameController.Instance.CurrentShips[i].Ship.Player.Name != GameController.Instance.MyLogin)
                {
                    DrawString(GameController.Instance.CurrentShips[i].Ship.Player.Name, 10f, 835f, Color.Red, 0.8f);
                    DrawString(PolarCoordinateHelper.Vector2ToString(GameController.Instance.CurrentShips[i].Ship.Coordinates), 5f, 860f, Color.Red, 0.8f);
                    continue;
                }

                DrawSalsState(GameController.Instance.CurrentShips[i].Ship.ShipSupplies.Sails.SailsState[0],
                              GameController.Instance.CurrentShips[i].Ship.ShipSupplies.Sails.SailsState[1]);
                DrawHealth(GameController.Instance.CurrentShips[i].Ship.Health);
                // Координаты
                DrawString("Coordinates", 10f, 70f, Color.Red, 0.8f);
                DrawString(PolarCoordinateHelper.Vector2ToString(GameController.Instance.CurrentShips[i].Ship.Coordinates), 10f, 100f, Color.Red, 0.8f);
            }

            if (GameController.Instance.Bullets != null)
            {
                foreach (var bullet in GameController.Instance.Bullets)
                {
                    bullet.Draw(SpriteBatch);
                }
            }

            SpriteBatch.End();
        }
Exemple #3
0
        public Bullet(BulletType bulletType, string shooter, Vector2 coordinatesFrom, Vector2 coordinatesTo)
        {
            Shooter         = shooter;
            Type            = bulletType;
            CoordinatesFrom = coordinatesFrom;
            CoordinatesTo   = coordinatesTo;
            Coordinates     = CoordinatesFrom;
            Damage          = 10f;
            _direction      = PolarCoordinateHelper.GetDirection(CoordinatesFrom, CoordinatesTo);
            _direction.Normalize();

            _movingTimer = new Timer(Move, null, 0, 20);
        }
Exemple #4
0
        private void UpdateCurrentShips(int step)
        {
            for (int i = 0; i < 10; i++)
            {
                if (ServerShips[i] == null || CurrentShips[i] == null)
                {
                    return;
                }

                var diffCoords = ServerShips[i].Ship.Coordinates - CurrentShips[i].Ship.Coordinates;
                var diffAngle  = PolarCoordinateHelper.GetAngle(ServerShips[i].Ship.MoveVector, CurrentShips[i].Ship.MoveVector);

                if (Math.Abs(diffAngle) > Math.PI)
                {
                    diffAngle = -(float)(2 * Math.PI - Math.Abs(diffAngle)) * (Math.Sign(diffAngle));
                }

                CurrentShips[i].Ship.Coordinates += diffCoords / (5 - step);
                CurrentShips[i].Ship.MoveVector   = PolarCoordinateHelper.TurnVector2(CurrentShips[i].Ship.MoveVector, diffAngle / (5 - step));
            }
        }
Exemple #5
0
 protected override void TurnToTheRight(object obj)
 {
     MoveVector = PolarCoordinateHelper.TurnVector2(MoveVector, 0.05f);
 }