Ejemplo n.º 1
0
        private void Reset()
        {
            MoverManager.movers.Clear();

            _mainPartIsDead = false;
            _ready          = true;
            _timer          = Config.BossInitialTimer;

            if (_previousBossPart == null)
            {
                _mainPart = new BossPart(
                    _gameRef, this, player, MoverManager, _completeBulletPatterns, new Color(0f, 0.75f, 0f, 0.65f),
                    4242f, null, _iteration, _step, null, null, true
                    );

                _mainPart.Initialize();
            }
            else
            {
                _mainPart = _previousBossPart;
                _mainPart.IterateStructure(_iteration);
            }

            _previousBossPart = (BossPart)_mainPart.Clone();

            _parts.Add(_mainPart);

            _core = new BossCore(_gameRef, _mainPart, () => player.Ship.Position, MoverManager, _completeBulletPatterns);
            _core.Initialize();
        }
Ejemplo n.º 2
0
        public Boss(GameRunner gameRef, Player player, int iteration = 50, float step = 25)
        {
            _gameRef                   = gameRef;
            _defeatCounter             = 0;
            MoverManager               = new MoverManager(gameRef);
            GameManager.GameDifficulty = Config.GameDifficultyDelegate;
            this.player                = player;
            _iteration                 = iteration;
            _step             = step;
            _previousBossPart = null;

            _parts            = new List <BossPart>();
            _currentPartIndex = 0;

            //MoverManager.Initialize(player.Position);
        }
Ejemplo n.º 3
0
        private void Split(CollisionConvexPolygon box)
        {
            var newPolygonShape = _structure.Split(box);
            var center          = box.GetCenterInWorldSpace();

            // TODO: Part is dead?
            // A boss part is dead when its center is dead?
            // or when the number of sub-parts is less than a number?
            if (center.X > (Size.X / 2f - 2 * _step) + Position.X - Origin.X &&
                center.X < (Size.X / 2f + 2 * _step) + Position.X - Origin.X)
            {
                TakeDamage(99999);
            }
            else
            {
                var boxLocalPosition = box.GetLocalPosition();

                // Left (1) or right (-1) part?
                var factor = (boxLocalPosition.X > Origin.X) ? 1 : -1;

                // If the break out part is not large enough => we don't create another part
                if (newPolygonShape.Vertices != null && newPolygonShape.GetArea() > Config.MinBossPartArea)
                {
                    var bossPart = new BossPart(
                        GameRef, _bossRef, player, _moverManager, null, _color,
                        _health, null, 0, 25f, null, newPolygonShape
                        );

                    bossPart.Initialize();

                    var bossPartSize     = newPolygonShape.GetSize();
                    var boxWorldPosition = box.GetWorldPosition();

                    // Compute new boss part's world position
                    var worldPosition = Vector2.Zero;
                    worldPosition.Y = boxWorldPosition.Y - boxLocalPosition.Y;

                    // Left part
                    if (factor == 1)
                    {
                        worldPosition.X = boxWorldPosition.X - bossPartSize.X;
                    }
                    // Right part
                    else if (factor == -1)
                    {
                        worldPosition.X = boxWorldPosition.X + _step;
                    }

                    // Update world position according to parent rotation
                    bossPart.Scale    = Scale;
                    bossPart.Rotation = Rotation;

                    var newLocalPosition = Vector2.Zero;
                    newLocalPosition.X = (Position.X - Origin.X) + (boxLocalPosition.X);
                    newLocalPosition.Y = (Position.Y - Origin.Y);

                    if (factor == -1)
                    {
                        newLocalPosition.X -= bossPartSize.X;
                    }
                    else
                    {
                        newLocalPosition.X += _step;
                    }

                    var newOrigin = newPolygonShape.GetCenter();
                    newLocalPosition += newOrigin;

                    var rotationOrigin = Position;
                    newLocalPosition = Vector2.Transform(newLocalPosition - rotationOrigin, Matrix.CreateRotationZ(Rotation)) + rotationOrigin;

                    bossPart.Origin   = newOrigin;
                    bossPart.Position = newLocalPosition;
                    _bossRef.Parts.Add(bossPart);

                    // Give to this new BossPart an impulsion to (pseudo) random direction due to explosion
                    var rnd = (float)(random.NextDouble() * (1f - 0.75f)) + 0.75f;
                    bossPart.ApplyImpulse(new Vector2(factor, rnd * factor), new Vector2(rnd / 5f));
                    ApplyImpulse(new Vector2(-factor, rnd * -factor), new Vector2(rnd / 5f));
                }

                // Remove destroyed bounding boxes
                if (factor == -1)
                {
                    CollisionBoxes.RemoveAll(bb => bb.GetCenter().X < boxLocalPosition.X);
                }
                else
                {
                    CollisionBoxes.RemoveAll(bb => bb.GetCenter().X > boxLocalPosition.X);
                }

                // This is the bounding that the player has destroyed, so we remove it from the list
                CollisionBoxes.Remove(box);
            }
        }