コード例 #1
0
        private void Initialise()
        {
            _gameOver = new Text("GAME OVER", _font, 60);
            MainMenu.SetTextOriginToMiddle(_gameOver);
            _gameOver.Position = new Vector2D(Program.windowSize.X / 2, 100);

            _pressToRestart        = new Text("PRESS ENTER TO RESTART", _font, 40);
            _pressToRestart.Origin = new Vector2D(_pressToRestart.GetGlobalBounds().Width / 2, _pressToRestart.GetGlobalBounds().Height);
            //SetTextOriginToMiddle(_pressToContinue);
            _pressToRestart.Position = new Vector2D(Program.windowSize.X / 2, Program.windowSize.Y - 100);

            _animationManager.AddAnimation(new Animation(new Vector2D(Program.windowSize.X / 2, Program.windowSize.Y + _pressToRestart.GetGlobalBounds().Height), new Transformable[] { _pressToRestart }, 400, 0, true));
        }
コード例 #2
0
        private void Initialise()
        {
            Vector2D rSize = new Vector2D(Program.windowSize.X / 2, Program.windowSize.Y / 2);

            _rectangleLeft                  = new RectangleShape(rSize);
            _rectangleLeft.Origin           = rSize / 2;
            _rectangleLeft.Position         = new Vector2D(Program.windowSize.X / 4 - 50, Program.windowSize.Y / 2);
            _rectangleLeft.OutlineThickness = 3;
            _rectangleLeft.OutlineColor     = Color.White;
            _rectangleLeft.FillColor        = Color.Black;

            _rectangleRight          = new RectangleShape(_rectangleLeft);
            _rectangleRight.Position = new Vector2D(3 * Program.windowSize.X / 4 + 50, Program.windowSize.Y / 2);



            _title = new Text("SHOOT EM UP", _font, 60);
            SetTextOriginToMiddle(_title);
            _title.Position = new Vector2D(Program.windowSize.X / 2, 100);

            _pressToContinue        = new Text("PRESS ENTER TO CONTINUE", _font, 40);
            _pressToContinue.Origin = new Vector2D(_pressToContinue.GetGlobalBounds().Width / 2, _pressToContinue.GetGlobalBounds().Height);
            //SetTextOriginToMiddle(_pressToContinue);
            _pressToContinue.Position = new Vector2D(Program.windowSize.X / 2, Program.windowSize.Y - 100);

            _restart        = new Text("RESTART", _font, 20);
            _restart.Origin = new Vector2D(0, _restart.GetGlobalBounds().Height);
            //SetTextOriginToMiddle(_restart);
            _restart.Position = new Vector2D(100, Program.windowSize.Y - 100);

            _exit        = new Text("EXIT", _font, 20);
            _exit.Origin = new Vector2D(_exit.GetGlobalBounds().Width, _exit.GetGlobalBounds().Height);
            //SetTextOriginToMiddle(_exit);
            _exit.Position = new Vector2D(Program.windowSize.X - 100, Program.windowSize.Y - 100);


            _settingsGui = new SettingsGui(new Vector2D(Program.windowSize.X / 2 + 300, Program.windowSize.Y / 2 - 150), _font, _window);
            _playerGui   = new PlayerGui(new Vector2D(Program.windowSize.X / 2 - 300, Program.windowSize.Y / 2 - 150), _font);

            _animationManager.AddAnimation(new MoveAnimation(new Vector2D(-_rectangleLeft.Size.X / 2 - _rectangleLeft.OutlineThickness, Program.windowSize.Y / 2), new Transformable[] { _rectangleLeft, _playerGui }, 1000, 0, true));
            _animationManager.AddAnimation(new MoveAnimation(new Vector2D(_rectangleRight.Size.X / 2 + Program.windowSize.X + _rectangleRight.OutlineThickness, Program.windowSize.Y / 2), new Transformable[] { _rectangleRight, _settingsGui }, 1000, 400, true));
            _animationManager.AddAnimation(new MoveAnimation(new Vector2D(Program.windowSize.X / 2, Program.windowSize.Y + _pressToContinue.GetGlobalBounds().Height), new Transformable[] { _pressToContinue }, 400, 1400, true));
        }
コード例 #3
0
        public void Collide()
        {
            List <GameObject> remove       = new List <GameObject>();
            List <GameObject> playerSwords = new List <GameObject>();
            List <GameObject> enemySwords  = new List <GameObject>();


            foreach (GameObject enemy in _dataManager.Enemies)
            {
                if (enemy.GetScripts <Sword>().Count > 0)
                {
                    enemySwords.Add(enemy.GetScripts <CharacterScript>()[0].Weapon);
                }
            }


            foreach (GameObject player in _dataManager.Players)
            {
                foreach (GameObject enemySword in enemySwords)
                {
                    if (!enemySword.Parent.Parent.GetScripts <Sword>()[0].IsActive)
                    {
                        continue;
                    }

                    if (player.GetComponent <RenderComponent>().Shape.GetGlobalBounds().Intersects(enemySword.GetComponent <RenderComponent>().Sprite.GetGlobalBounds()))
                    {
                        GameOver(player);
                    }
                }


                foreach (GameObject powerUp in _dataManager.PowerUps)
                {
                    if (player.GetComponent <RenderComponent>().Shape.GetGlobalBounds().Intersects(powerUp.GetComponent <RenderComponent>().Sprite.GetGlobalBounds()))
                    {
                        powerUp.GetScripts <PowerUpScript>()[0].ExecutePowerUp(player);
                        remove.Add(powerUp);
                    }
                }


                foreach (GameObject bonfire in _dataManager.Bonfires)
                {
                    if ((bonfire.transform.Position - player.transform.Position).GetLength() < 100)
                    {
                        if (!_animationManager.ExistAnimationToTextureComponent(bonfire.GetComponent <RenderComponent>()))
                        {
                            RenderComponent textureComponent = bonfire.GetComponent <RenderComponent>();
                            _animationManager.AddAnimation(new TextureAnimation(textureComponent, new Texture[] { new Texture("Pictures/bonfire2_2.png"), new Texture("Pictures/bonfire3_2.png") }, -1, 0, 500, Vector2D.One(), Vector2D.One() * -1));
                            _animationManager.AddAnimation(new TextureAnimation(textureComponent, null, 200, 0, 0, Vector2D.One() * 4, Vector2D.One() * -1));
                            _animationManager.AddAnimation(new TextureAnimation(textureComponent, null, 200, 200, 0, Vector2D.One(), Vector2D.One() * 4));
                            _dataManager.Score += 1000;
                        }
                    }
                }

                if (player.GetScripts <Sword>().Count > 0)
                {
                    playerSwords.Add(player.GetScripts <CharacterScript>()[0].Weapon);
                }
            }



            foreach (GameObject sword in playerSwords)
            {
                if (!sword.Parent.Parent.GetScripts <Sword>()[0].IsActive)
                {
                    continue;
                }

                foreach (GameObject enemy in _dataManager.Enemies)
                {
                    if (sword.GetComponent <RenderComponent>().Sprite.GetGlobalBounds().Intersects(enemy.GetComponent <RenderComponent>().Shape.GetGlobalBounds()))
                    {
                        remove.Add(enemy);
                        _dataManager.Score += 30;
                    }
                }


                foreach (GameObject chest in _dataManager.Chests)
                {
                    if (sword.GetComponent <RenderComponent>().Sprite.GetGlobalBounds().Intersects(MakeSmaller(chest.GetComponent <RenderComponent>().Sprite.GetGlobalBounds(), 0.5f)))
                    {
                        remove.Add(chest);
                        _map.AddPowerUpRuntime(chest.transform.Position);
                        continue;
                    }
                }
            }



            foreach (GameObject arrow in _dataManager.Arrows)
            {
                foreach (GameObject enemy in _dataManager.Enemies)
                {
                    if (arrow.GetComponent <RenderComponent>().Sprite.GetGlobalBounds().Intersects(enemy.GetComponent <RenderComponent>().Shape.GetGlobalBounds()) && !arrow.GetScripts <ArrowScript>()[0].Friendly.Contains(enemy))
                    {
                        remove.Add(arrow);
                        remove.Add(enemy);
                        _dataManager.Score += 30;
                        continue;
                    }
                }

                foreach (GameObject player in _dataManager.Players)
                {
                    if (arrow.GetComponent <RenderComponent>().Sprite.GetGlobalBounds().Intersects(player.GetComponent <RenderComponent>().Shape.GetGlobalBounds()) && !arrow.GetScripts <ArrowScript>()[0].Friendly.Contains(player))
                    {
                        remove.Add(arrow);
                        GameOver(player);
                        continue;
                    }
                }

                foreach (GameObject chest in _dataManager.Chests)
                {
                    if (arrow.GetComponent <RenderComponent>().Sprite.GetGlobalBounds().Intersects(MakeSmaller(chest.GetComponent <RenderComponent>().Sprite.GetGlobalBounds(), 0.5f)))
                    {
                        remove.Add(arrow);
                        remove.Add(chest);
                        continue;
                    }
                }

                foreach (GameObject secondArrow in _dataManager.Arrows)
                {
                    if (arrow != secondArrow && arrow.GetComponent <RenderComponent>().Sprite.GetGlobalBounds().Intersects(secondArrow.GetComponent <RenderComponent>().Sprite.GetGlobalBounds()))
                    {
                        remove.Add(arrow);
                        remove.Add(secondArrow);
                        continue;
                    }
                }


                if (arrow.GetScripts <ArrowScript>()[0].LifeTime < 0)
                {
                    remove.Add(arrow);
                    continue;
                }
            }



            foreach (GameObject r in remove)
            {
                _dataManager.Environment.GetChilds().Remove(r);
                _dataManager.Enemies.Remove(r);
                _dataManager.PowerUps.Remove(r);
                _dataManager.Chests.Remove(r);
                _dataManager.Arrows.Remove(r);
                _dataManager.Players.Remove(r);
            }
        }
コード例 #4
0
        private void Update(double elapsedTime)
        {
            int lifeImagesCount = _lifeImages.Count;

            for (int i = lifeImagesCount; i < Program.lifes; i++)
            {
                Text lifeImage = new Text("|", _font, (uint)_lifeImagesSize);
                MainMenu.SetTextOriginToMiddle(lifeImage);
                lifeImage.Position = _lifeImagesPosition + (_lifeImagesDistance + Vector2D.Right() * lifeImage.GetGlobalBounds().Width) * i + (Vector2D.Right() * lifeImage.GetGlobalBounds().Width) / 2;
                _lifeImages.Add(lifeImage);
            }

            bool rectangleObject1Collided = false;
            bool rectangleObject2Collided = false;

            if (_player1 != null)
            {
                rectangleObject1Collided = _player1.PongCollision(_circleObject);
            }
            if (_player2 != null)
            {
                rectangleObject2Collided = _player2.PongCollision(_circleObject);
            }

            int numberOfBrickCollisions           = 0;
            List <RectangleObject> collidedBricks = new List <RectangleObject>();

            Vector2D oldCircleDirection = _circleObject.Direction;

            foreach (RectangleObject brick in _bricks)
            {
                if (brick.NewReflectionCollision(_circleObject, _animationManager))
                {
                    brick.Life--;

                    if (brick.Life >= 0)
                    {
                        brick.ChangeToPrefab(RectangleObject.rectangleShapePrefabs[brick.Life]);
                    }

                    numberOfBrickCollisions++;
                    collidedBricks.Add(brick);

                    Vector2D originalPosition = Vector2D.Zero();

                    foreach (RectangleObject brickPrefab in _bricksPrefab)
                    {
                        if (brickPrefab.ID == brick.ID)
                        {
                            originalPosition = brickPrefab.Rectangle.Position;
                        }
                    }

                    _animationManager.RemoveAnimationsToObject(brick.Rectangle);

                    Vector2D animationPosition = brick.Rectangle.Position + oldCircleDirection * 5;
                    _animationManager.AddAnimation(new Animation(brick.Rectangle.Position, new Transformable[] { brick.Rectangle }, 200, 0, animationPosition));
                    _animationManager.AddAnimation(new Animation(animationPosition, new Transformable[] { brick.Rectangle }, 200, 200, originalPosition));
                }
            }

            if (numberOfBrickCollisions > 0)
            {
                if (_player1 != null && _player2 != null)
                {
                    if (_lastHit.Equals(_player1))
                    {
                        _score1 += numberOfBrickCollisions;
                    }

                    if (_lastHit.Equals(_player2))
                    {
                        _score2 += numberOfBrickCollisions;
                    }
                }
                else
                {
                    if (_player1 != null)
                    {
                        _score1++;
                    }

                    if (_player2 != null)
                    {
                        _score2++;
                    }
                }

                foreach (RectangleObject brick in collidedBricks)
                {
                    if (brick.Life < 0)
                    {
                        if (_random.Next(0, _probabilityOfPowerUp) == 0)
                        {
                            PowerUp newPowerUp = _prefabPowerUps[_random.Next(0, _prefabPowerUps.Count)].Clone();


                            double speed = 0.3f;
                            newPowerUp.Spawn(new Vector2D(brick.Rectangle.Position.X, brick.Rectangle.Position.Y), new Vector2D(0, 1), speed);

                            _powerUps.Add(newPowerUp);
                        }

                        _bricks.Remove(brick);
                    }
                }
            }


            if (_bricks.Count == 0 && _loadedLevel == _persistenceManager.LoadLevelList()[_persistenceManager.LoadLevelList().Count - 1])
            {
                Program.windowState = Program.WindowState.GameOver;
            }
            else if (_bricks.Count == 0 && (rectangleObject1Collided || rectangleObject2Collided))
            {
                _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;
                }
            }


            List <PowerUp> usedPowerUps = new List <PowerUp>();

            foreach (PowerUp powerUp in _powerUps)
            {
                powerUp.Update(elapsedTime);

                RectangleObject collidedRectangle = null;
                if (_player1 != null)
                {
                    if (_player1.PowerUpCollision(powerUp))
                    {
                        collidedRectangle = _player1;
                    }
                }

                if (_player2 != null)
                {
                    if (_player2.PowerUpCollision(powerUp))
                    {
                        collidedRectangle = _player2;
                    }
                }

                if (collidedRectangle != null)
                {
                    powerUp.ExecutePowerUp(collidedRectangle);
                    usedPowerUps.Add(powerUp);
                }
                else if (powerUp.Position.X < 0 || powerUp.Position.X > Program.windowSize.X)
                {
                    usedPowerUps.Add(powerUp);
                }
            }

            foreach (PowerUp powerUp in usedPowerUps)
            {
                _powerUps.Remove(powerUp);
            }

            usedPowerUps.Clear();

            _stateManager.Update(elapsedTime);

            _circleObject.Update(elapsedTime);

            bool resetCircleObject = false;

            if (_circleObject.CheckOutOfField((int)Program.windowSize.X, (int)Program.windowSize.Y))
            {
                Program.lifes--;
                _lifeImages.RemoveAt(_lifeImages.Count - 1);
                if (Program.lifes <= 0)
                {
                    Program.windowState = Program.WindowState.GameOver;
                }

                resetCircleObject = true;
                _circleObject.ResetPosition(_circlePosition);
                _circleObject.Direction = new Vector2D(-_circleObject.Direction.X, _circleObject.Direction.Y);
                _circleObject.Update(0);
                _powerUps.Clear();
            }



            if ((rectangleObject1Collided || rectangleObject2Collided) && _player1 != null && _player2 != null)
            {
                /*Vector2D savedPos = _player1.Rectangle.Position;
                 * _player1.Rectangle.Position = _player2.Rectangle.Position;
                 * _player2.Rectangle.Position = savedPos;*/

                _animationManager.AddAnimation(new Animation(_player1.Rectangle.Position, new Transformable[] { _player2.Rectangle }, 100, 0, false));
                _animationManager.AddAnimation(new Animation(_player2.Rectangle.Position, new Transformable[] { _player1.Rectangle }, 100, 0, false));

                if (rectangleObject1Collided)
                {
                    _lastHit = _player1;
                }
                if (rectangleObject2Collided)
                {
                    _lastHit = _player2;
                }
            }



            _aiLeft.Update(elapsedTime, rectangleObject2Collided, rectangleObject1Collided, resetCircleObject);
            _aiRight.Update(elapsedTime, rectangleObject1Collided, rectangleObject2Collided, resetCircleObject);


            if (_score1 < 10)
            {
                _scoreLeftText.DisplayedString = "0" + _score1.ToString();
            }
            else
            {
                _scoreLeftText.DisplayedString = _score1.ToString();
            }

            if (_score2 < 10)
            {
                _scoreRightText.DisplayedString = "0" + _score2.ToString();
            }
            else
            {
                _scoreRightText.DisplayedString = _score2.ToString();
            }


            _animationManager.Update(elapsedTime);
        }