Ejemplo n.º 1
0
    bool IsValidSpawn(IntRect rect, EnemySpawnSettings.EnemySpawn spawn, float time)
    {
        //if(spawn.MinLevel >= _CurrentLevel && spawn.MaxLevel <= _CurrentLevel)
        if ((spawn.HasMinTime && spawn.MinTime > time) || (spawn.HasMaxTime && spawn.MaxTime < time))
        {
            return(false);
        }

        return((spawn.HasMinY == false || spawn.MinY <= rect.MaxY) && (spawn.HasMaxY == false || spawn.MaxY > rect.MinY));
    }
Ejemplo n.º 2
0
    void AttemptSpawn(IntRect rect, EnemySpawnSettings.EnemySpawn spawn)
    {
        if (_coordsList == null)
        {
            _coordsList = new List <SpawnCoords>();
        }
        _coordsList.Clear();
        IntRect windowRect = CloudSpawner.GetCurrentRect(LayerDepth, GridSize, new Vector2(0.6f, 0.6f));

        int minY = rect.MinY;

        if (spawn.HasMinY)
        {
            minY = Mathf.Max(minY, spawn.MinY);
        }
        int maxY = rect.MaxY;

        if (spawn.HasMaxY)
        {
            maxY = Mathf.Min(maxY, spawn.MaxY + 1);
        }
        for (int x = rect.MinX; x < rect.MaxX; x++)
        {
            for (int y = minY; y < maxY; y++)
            {
                if (x > windowRect.MinX &&
                    x < windowRect.MaxX - 1 &&
                    y > windowRect.MinY &&
                    y < windowRect.MaxY - 1)
                {
                    continue;
                }
                if (IsSpawnValid(spawn, x, y) == false)
                {
                    continue;
                }
                _coordsList.Add(new SpawnCoords()
                {
                    X = x,
                    Y = y,
                });
            }
        }

        if (_coordsList.Count > 0)
        {
            var coord = _coordsList[Random.Range(0, _coordsList.Count)];
            SpawnEnemy(spawn, coord);
        }
    }
Ejemplo n.º 3
0
    bool IsSpawnValid(EnemySpawnSettings.EnemySpawn spawn, int x, int y)
    {
        if ((spawn.HasMinY && spawn.MinY > y) || (spawn.HasMaxY && spawn.MaxY < y))
        {
            return(false);
        }

        /*for (int i = 0; i < _SpawnedEnemies.Count; i++) {
         *      var enemy = _SpawnedEnemies [i];
         *      Vector3 pos = enemy.transform.position;
         *      int enemyX = Mathf.RoundToInt (pos.x * GridSize);
         *      int enemyY = Mathf.RoundToInt (pos.x * GridSize);
         *      if (enemyX == x && enemyY == y)
         *              return false;
         * }*/
        return(true);
    }
Ejemplo n.º 4
0
    void SpawnEnemy(EnemySpawnSettings.EnemySpawn spawn, SpawnCoords coord)
    {
        Vector3 position = new Vector3(coord.X / GridSize, coord.Y / GridSize, LayerDepth);

        var prefab = spawn.Variations[Random.Range(0, spawn.Variations.Length)];

        GameObject         obj;
        Queue <GameObject> pool;

        if (_EnemyPool.TryGetValue(prefab, out pool) && pool.Count > 0)
        {
            obj = pool.Dequeue();
        }
        else
        {
            obj = GameObject.Instantiate(prefab) as GameObject;
        }
        var transform = obj.transform;
        var rb        = obj.GetComponent <Rigidbody2D>();

        if (rb != null)
        {
            rb.velocity        = Vector3.zero;
            rb.angularVelocity = 0f;
            rb.position        = position;
            rb.rotation        = 0f;
        }
        if (transform != null)
        {
            transform.position = position;
            transform.rotation = Quaternion.identity;
        }
        var enemy = obj.GetComponent <Enemy>();

        enemy.FromPrefab = prefab;
        var explodable = obj.GetComponent <Explodable>();

        explodable.Spawner = this;
        var foskPos = Blokfosk.Instance.transform.position;

        var dir = (foskPos - position);

        dir.z = 0f;
        dir.y = 0f;

        dir.x           = dir.x < 0f ? -1f : 1f;
        enemy.Direction = dir;

        var scale = enemy.transform.localScale;

        scale = Vector3.one * Random.Range(spawn.ScaleRange.x, spawn.ScaleRange.y);
        if (dir.x > 0)
        {
            scale.x = Mathf.Abs(scale.x);
        }
        else
        {
            scale.x = -Mathf.Abs(scale.x);
        }
        enemy.transform.localScale = scale;

        enemy.MovementSpeed = Random.Range(spawn.MovementSpeedRange.x, spawn.MovementSpeedRange.y);
        enemy.Reset();

        _SpawnedEnemies.Add(enemy);
        _SpawnAccumulator -= spawn.SpawnValue;
    }