Exemple #1
0
 public Ai(RectangleObject rectangleObject, CircleObject circleObject, Vector2f windowSize, Difficulty difficulty)
 {
     _rectangleObject = rectangleObject;
     _circleObject    = circleObject;
     _windowSize      = windowSize;
     _nextPosition    = windowSize.Y / 2;
     _difficulty      = difficulty;
 }
        private void Initialise(Ai.Difficulty difficultyLeft, Ai.Difficulty difficultyRight)
        {
            _window = new RenderWindow(new VideoMode((uint)_windowSize.X, (uint)_windowSize.Y), "PONG");
            _window.SetActive();

            _circlePosition = new Vector2f(_windowSize.X / 2, _windowSize.Y / 2);


            _rectangleObject1           = new RectangleObject(new Vector2f(_rectangleSizeX, _rectangleSizeY));
            _rectangleObject1.FillColor = Color.White;
            _rectangleObject1.Attach(new SoundObserver(_soundManager));
            _rectangleObject2           = new RectangleObject(new Vector2f(_rectangleSizeX, _rectangleSizeY));
            _rectangleObject2.FillColor = Color.White;
            _rectangleObject2.Attach(new SoundObserver(_soundManager));

            _circleObject = new CircleObject(_circleSize);
            _circleObject.Attach(new SoundObserver(_soundManager));
            _circleObject.FillColor = Color.White;


            _prefabPowerUps.Add(new SpeedDown(_circleObject));
            _prefabPowerUps.Add(new BiggerRectangleObject(_circleObject));
            _prefabPowerUps.Add(new BiggerRectangleObject(_circleObject));
            _prefabPowerUps.Add(new Disco(_circleObject));
            _prefabPowerUps.Add(new Disco(_circleObject));



            _circleObject.Position = _circlePosition;
            _circleObject.Update(0);


            _rectangleObject1.Position = new Vector2f(_rectanglePositionX, _windowSize.Y / 2);
            _rectangleObject2.Position = new Vector2f(_windowSize.X - _rectanglePositionX, _windowSize.Y / 2);

            _scoreLeftText          = new Text(_scoreLeft.ToString(), _font, _characterSizeScore);
            _scoreLeftText.Position = new Vector2f(_windowSize.X / 2 - _scoreLeftText.GetGlobalBounds().Width - 100, 100);

            _scoreRightText          = new Text(_scoreRight.ToString(), _font, _characterSizeScore);
            _scoreRightText.Position = new Vector2f(_windowSize.X / 2 + 100, 100);

            _middleLine          = new Text("I", _font);
            _middleLine.Position = new Vector2f(_windowSize.X / 2 - _middleLine.GetGlobalBounds().Width / 2, 0);
            while (_middleLine.GetGlobalBounds().Height < _windowSize.Y)
            {
                _middleLine.DisplayedString += "\n\nI";
            }

            _aiLeft  = new Ai(_rectangleObject1, _circleObject, _windowSize, difficultyLeft);
            _aiRight = new Ai(_rectangleObject2, _circleObject, _windowSize, difficultyRight);

            _nextPowerUps.Add(Random(0, _prefabPowerUps.Count));
        }
        public bool Collision(CircleObject circleObject, double elapsedTime)
        {
            if (this.GetGlobalBounds().Intersects(circleObject.GetRectangleBoundary().GetGlobalBounds()))
            {
                float heightDifference = this.Position.Y - circleObject.Position.Y;

                if (heightDifference > this.Size.Y / 2)
                {
                    heightDifference = this.Size.Y / 2;
                }
                else if (heightDifference < -this.Size.Y / 2)
                {
                    heightDifference = -this.Size.Y / 2;
                }

                Vector2f newDirection;

                float percent = -((heightDifference * 50) / (this.Size.Y / 2)) / 100;
                if (Program.windowSize.X / 2 > circleObject.Position.X)
                {
                    newDirection          = new Vector2f((float)Math.Cos(percent * (float)Math.PI / 2), percent * (float)Math.PI);
                    circleObject.Position = new Vector2f(this.Position.X + this.Size.X / 2 + circleObject.Radius * 1.5f, circleObject.Position.Y);
                    circleObject.Update(0);
                }
                else
                {
                    newDirection          = new Vector2f(-(float)Math.Cos(percent * (float)Math.PI / 2), percent * (float)Math.PI);
                    circleObject.Position = new Vector2f(this.Position.X - this.Size.X / 2 - circleObject.Radius * 1.5f, circleObject.Position.Y);
                    circleObject.Update(0);
                }

                float scalar = (float)Math.Sqrt(newDirection.X * newDirection.X + newDirection.Y * newDirection.Y);
                newDirection = new Vector2f(newDirection.X / scalar, newDirection.Y / scalar);

                circleObject.Direction = newDirection;
                circleObject.CollisionHappened();


                Notify(SoundManager.SoundNumbers.HitPlayer);
                return(true);
            }
            else
            {
                return(false);
            }
        }
 public SpeedDown(CircleObject circleObject)
 {
     this._circleObject = circleObject;
     this.Texture       = new Texture("SpeedDown.png");
 }
Exemple #5
0
 public Disco(CircleObject circleObject)
 {
     _circleObject  = circleObject;
     this.Texture   = new Texture("Disco.png");
     this._duration = 5000;
 }
        private void Initialise()
        {
            _brickPosition = new Vector2D(Program.windowSize.X / 2, Program.windowSize.Y / 4);

            _circlePosition = new Vector2D(Program.windowSize.X / 2, Program.windowSize.Y / 2);

            _lag = 0.0;

            _circleObject = new CircleObject(_circleSize);
            _circleObject.Circle.FillColor = Color.White;

            _levelID      = 0;
            _loadedLevel  = _persistenceManager.LoadLevelList()[_levelID++];
            _bricks       = _persistenceManager.LoadLevel(_loadedLevel);
            _bricksPrefab = _persistenceManager.LoadLevel(_loadedLevel);

            for (int i = 0; i < _bricks.Count; i++)
            {
                _bricks[i].Rectangle.Position       += _brickPosition;
                _bricksPrefab[i].Rectangle.Position += _brickPosition;
            }


            /*for (int i = 0; i < _brickCount.X; i++)
             * {
             *  for (int j = 0; j < _brickCount.Y; j++)
             *  {
             *      RectangleObject newBrick = new RectangleObject(new Vector2D(_brickSizeX, _brickSizeY));
             *      newBrick.Rectangle.FillColor = Color.White;
             *
             *      //double positionX = _brickPosition.X + i * (_brickSizeX + _brickDistance.X);
             *      double positionX = i * (_brickSizeX + _brickDistance.X);
             *      positionX -= (_brickCount.X / 2) * (_brickSizeX + _brickDistance.X) ;
             *      //double positionY = _brickPosition.Y + j * (_brickSizeY + _brickDistance.Y);
             *      double positionY = j * (_brickSizeY + _brickDistance.Y);
             *      positionY -= (_brickCount.Y / 2) * (_brickSizeY + _brickDistance.Y);
             *
             *      newBrick.Rectangle.Position = new Vector2D(positionX, positionY);
             *
             *      if (j % 2 == 0)
             *      {
             *          newBrick.Life = 0;
             *      }
             *
             *      newBrick.ChangeToPrefab(RectangleObject.rectangleShapePrefabs[newBrick.Life]);
             *
             *      _bricks.Add(newBrick);
             *  }
             * }
             * _persistenceManager.SaveLevel("level1",_bricks);
             * foreach (RectangleObject brick in _bricks)
             * {
             *  brick.Rectangle.Position += _brickPosition;
             * }*/


            List <State> states = new List <State>();

            states.Add(new Disco(_circleObject));
            states.Add(new Disco(_circleObject));
            states.Add(new SpeedDown(_circleObject));
            states.Add(new BiggerRectangleObject(_circleObject));
            states.Add(new BiggerRectangleObject(_circleObject));
            //_prefabPowerUps.Add(new SpeedDown(_circleObject));
            //_prefabPowerUps.Add(new BiggerRectangleObject(_circleObject));
            //_prefabPowerUps.Add(new BiggerRectangleObject(_circleObject));
            //_prefabPowerUps.Add(new Disco(_circleObject));
            //_prefabPowerUps.Add(new Disco(_circleObject));


            _players.Add(_player1);
            _players.Add(_player2);

            _stateManager = new StateManager(states, _players);


            /*PowerUp powerUp1 = new PowerUp(states[0]);
             * powerUp1.StateManager = _stateManager;
             *
             * _prefabPowerUps.Add(powerUp1);*/

            for (int i = 0; i < states.Count; i++)
            {
                states[i].ID = i;

                PowerUp powerUp = new PowerUp(states[i]);
                powerUp.StateManager = _stateManager;

                _prefabPowerUps.Add(powerUp);
            }


            _circleObject.Circle.Position = _circlePosition;
            _circleObject.Update(0);



            _scoreLeftText                  = new Text(_score1.ToString(), _font, _characterSizeScore);
            _scoreLeftText.Position         = new Vector2D(100, Program.windowSize.Y - _scoreLeftText.GetGlobalBounds().Height - 100);
            _scoreLeftText.OutlineThickness = 2;
            _scoreLeftText.OutlineColor     = Color.White;
            _scoreLeftText.FillColor        = Color.Black;

            _scoreRightText          = new Text(_score2.ToString(), _font, _characterSizeScore);
            _scoreRightText.Position = new Vector2D(Program.windowSize.X - _scoreRightText.GetGlobalBounds().Width - 100, Program.windowSize.Y - _scoreRightText.GetGlobalBounds().Height - 100);
        }
Exemple #7
0
 public Disco(CircleObject circleObject)
 {
     _circleObject = circleObject;
     this.Texture  = new Texture("Disco.png");
 }
 public BiggerRectangleObject(CircleObject circleObject)
 {
     _circleObject  = circleObject;
     this.Texture   = new Texture("BiggerRectangleObject.png");
     this._duration = 10000;
 }