Пример #1
0
        void UpdatePosition(SFML.System.Vector2f newPos)
        {
            var oldPos = this.Position;

            /*Check intersection with borders newPos - coordinats of upper left conner of the ship
             * so we add half of the ship size*/
            if (gameInterface.GetTile(newPos.X + (float)SIZE * SIZE_FACTOR / 2,
                                      newPos.Y + (float)SIZE * SIZE_FACTOR / 2) == null)
            {
                Position = newPos;
            }
            else
            {
                isDead = true;
            }
        }
Пример #2
0
        void UpdatePosition()
        {
            if (!isDead)
            {
                var  oldPos      = this.Position;
                var  newPos      = new Vector2f(oldPos.X, oldPos.Y);
                bool isMoveLeft  = Keyboard.IsKeyPressed(Keyboard.Key.Left);
                bool isMoveRight = Keyboard.IsKeyPressed(Keyboard.Key.Right);
                bool isMoveUp    = Keyboard.IsKeyPressed(Keyboard.Key.Up);
                bool isMoveDown  = Keyboard.IsKeyPressed(Keyboard.Key.Down);

                if (isMoveLeft)
                {
                    newPos = new Vector2f(Position.X - shipSpeed, Position.Y);
                }
                if (isMoveRight)
                {
                    newPos = new Vector2f(Position.X + shipSpeed, Position.Y);
                }
                if (isMoveUp)
                {
                    newPos = new Vector2f(Position.X, Position.Y - shipSpeed);
                }
                if (isMoveDown)
                {
                    newPos = new Vector2f(Position.X, Position.Y + shipSpeed);
                }

                /*Check intersection with borders newPos - coordinats of upper left conner of the ship
                 * so we add half of the ship size*/
                if (gameInterface.GetTile(newPos.X + (float)SHIP_SIZE * SIZE_FACTOR / 2,
                                          newPos.Y + (float)SHIP_SIZE * SIZE_FACTOR / 2) == null)
                {
                    Position = newPos;
                }
            }
        }