Пример #1
0
        public BagelEnemy(BagelType bagelType,
                          ISizeProvider sizeProvider = null,
                          IEntityAdder entityAdder   = null,
                          float x         = 0,
                          float y         = 0,
                          float velX      = 0,
                          float velY      = 0,
                          int health      = 1,
                          float direction = 0) :
            base(x, y, velX, velY, health, direction)
        {
            BagelType = bagelType;

            this.sizeProvider = sizeProvider;
            if (sizeProvider == null && bagelType == BagelType.Bouncing)
            {
                throw new ArgumentException("How I can bounce when there're no walls?");
            }

            this.entityAdder = entityAdder;
            if (entityAdder == null &&
                (bagelType == BagelType.Shooting ||
                 bagelType == BagelType.Clone ||
                 bagelType == BagelType.InvincibleClone))
            {
                throw new ArgumentException("I must add \"bullets\" somewhere!");
            }
            if (bagelType == BagelType.Clone ||
                bagelType == BagelType.InvincibleClone)
            {
                rand = new Random();
            }

            UpdateCollisionBox();
        }
Пример #2
0
        private void AddFourDirectionalBagels(BagelType bagelType)
        {
            var angle = rand.NextDouble() * Math.PI * 2;

            entityAdder.AddEntity(
                new BagelEnemy(bagelType,
                               sizeProvider,
                               entityAdder,
                               X, Y,
                               (float)(ShotSpeed * Math.Cos(angle)),
                               (float)(ShotSpeed * Math.Sin(angle)),
                               1)
                );
            entityAdder.AddEntity(
                new BagelEnemy(bagelType,
                               sizeProvider,
                               entityAdder,
                               X, Y,
                               -(float)(ShotSpeed * Math.Cos(angle)),
                               -(float)(ShotSpeed * Math.Sin(angle)),
                               1)
                );
            entityAdder.AddEntity(
                new BagelEnemy(bagelType,
                               sizeProvider,
                               entityAdder,
                               X, Y,
                               (float)(ShotSpeed * Math.Sin(angle)),
                               -(float)(ShotSpeed * Math.Cos(angle)),
                               1)
                );
            entityAdder.AddEntity(
                new BagelEnemy(bagelType,
                               sizeProvider,
                               entityAdder,
                               X, Y,
                               -(float)(ShotSpeed * Math.Sin(angle)),
                               (float)(ShotSpeed * Math.Cos(angle)),
                               1)
                );
        }