Example #1
0
    IEnumerator Generate(EnemyData enemy)
    {
        while (active)
        {
            Vector2    position = SetNewEnemyPosition(enemy);
            Quaternion rotation = SetNewEnemyRotation(enemy, position);

            EnemyController newController = Instantiate(enemy.prefab, position, rotation, transform).GetComponent <EnemyController>();
            if (newController)
            {
                newController.SetScreenLimits(leftScreenLimit, rightScreenLimit, upperScreenLimit, lowerScreenLimit);
                newController.SetProyectileContainer(proyectileContainer);
                currentEnemies.Add(newController);

                EnemyModel newModel = newController.gameObject.GetComponent <EnemyModel>();
                newModel.Initialize(collisionDamage, enemy.itemGenerationPercentage);

                EnemyView newView = newController.gameObject.GetComponent <EnemyView>();
                newView.InitializeDamageColor(damageColor, damageColorDuration);
                newView.InitializeExplosion(explosionPrefab, explosionContainer);
            }

            float waitTime = Random.Range(enemy.minWaitTime, enemy.maxWaitTime);
            yield return(new WaitForSeconds(waitTime));
        }
    }
Example #2
0
        private EnemyModel CreateEnemyModel()
        {
            EnemyModel enemyModel = new EnemyModel();
            enemyModel.Front = new Point(0, -1);
            enemyModel.Mass = .2f;
            enemyModel.Scale = Mathematics.Lerp(.4d, .8d, _rnd.NextDouble());

            enemyModel.MaxSpeed = (float)Mathematics.Lerp(_enemyMaxSpeedLowRange, _enemyMaxSpeedHighRange, _rnd.NextDouble());
            enemyModel.MaxForce = (float)Mathematics.Lerp(_enemyMaxForceLowRange, _enemyMaxForceHighRange, _rnd.NextDouble());

            int quadrant = _rnd.Next(1, 5);
            switch (quadrant)
            {
                case 1:
                    enemyModel.Position = new Point(_rnd.NextDouble() * Width, -_enemyCreationBufferWidth);
                    break;
                case 2:
                    enemyModel.Position = new Point(Width + _enemyCreationBufferWidth, _rnd.NextDouble() * Height);
                    break;
                case 3:
                    enemyModel.Position = new Point(_rnd.NextDouble() * Width, Width + _enemyCreationBufferWidth);
                    break;
                default:
                    enemyModel.Position = new Point(-_enemyCreationBufferWidth, _rnd.NextDouble() * Height);
                    break;
            }
            enemyModel.Initialize();
            return enemyModel;
        }