Ejemplo n.º 1
0
    public Enemy spawnEnemy(SpawnDirection spawnDirection, Enemy enemyPrefab)
    {
        float xPosition = 0;
        float zPosition = 0;

        switch (spawnDirection)
        {
        case SpawnDirection.Left:
            xPosition = topLeft.position.x;
            zPosition = Random.Range(topLeft.position.y, bottomLeft.position.y);
            break;

        case SpawnDirection.Right:
            xPosition = topRight.position.x;
            zPosition = Random.Range(topRight.position.y, bottomRight.position.y);
            break;

        case SpawnDirection.Top:
            xPosition = Random.Range(topLeft.position.x, topRight.position.x);
            zPosition = topLeft.position.z;
            break;

        case SpawnDirection.Bottom:
            xPosition = Random.Range(bottomLeft.position.x, bottomRight.position.x);
            zPosition = bottomLeft.position.z;
            break;
        }

        GameObject gameObject = Instantiate(enemyPrefab.gameObject);

        gameObject.transform.position = new Vector3(xPosition, 0, zPosition);
        return(gameObject.GetComponent <Enemy>());
    }
Ejemplo n.º 2
0
    //public static Vector3 GetPointInsideArena(float maxOffsetX, float maxOffsetY)
    //{
    //    float x = Random.Range(-0.45f, 0.45f) * maxOffsetX;
    //    float y = Random.Range(-0.45f, 0.45f) * maxOffsetY;
    //    Rect scr = AspectUtility.screenRelativeRect;
    //    Vector3 point = new Vector3(scr.width * x, scr.height * y, 0.0f);
    //    return point;
    //}

    //public static Vector3 GetPointInsideScreen(float maxOffsetX, float maxOffsetY)
    //{
    //    float x = Random.Range(-0.5f, 0.5f) * maxOffsetX;
    //    float y = Random.Range(-0.5f, 0.5f) * maxOffsetY;
    //    Rect scr = AspectUtility.screenRelativeRect;
    //    Vector3 point = new Vector3(scr.width * x, scr.height * y, 0.0f);
    //    return point;
    //}

    public static Vector3 GetPointOutsideScreen(SpawnDirection dir, float offset, float maxDistFromCenter)
    {
        if (dir == SpawnDirection.Any)
        {
            dir = GetRandomDirAny();
        }

        if (dir == SpawnDirection.LeftOrRight)
        {
            dir = Random.value < 0.5f ? SpawnDirection.Left : SpawnDirection.Right;
        }
        else if (dir == SpawnDirection.TopOrBottom)
        {
            dir = Random.value < 0.5f ? SpawnDirection.Top : SpawnDirection.Bottom;
        }

        Rect  scr = AspectUtility.screenRelativeRect;
        float x = 0.0f; float y = 0.0f; float offsetX = 0.0f; float offsetY = 0.0f;
        float rnd = Random.Range(-1.0f, 1.0f) * maxDistFromCenter;

        switch (dir)
        {
        case SpawnDirection.Top:     x = 0.5f + rnd; y = 1.0f; offsetY = offset; break;

        case SpawnDirection.Bottom:  x = 0.5f + rnd; y = 0.0f; offsetY = -offset; break;

        case SpawnDirection.Left:    x = 0.0f; y = 0.5f + rnd; offsetX = -offset; break;

        case SpawnDirection.Right:   x = 1.0f; y = 0.5f + rnd; offsetX = offset; break;
        }

        Vector3 point = new Vector3(scr.xMin + scr.width * x + offsetX, scr.yMin + scr.height * y + offsetY, 0.0f);

        return(point);
    }
Ejemplo n.º 3
0
    public static IEnumerator SpawnGroup(
        ActorTypeEnum actorType,
        int count,
        float timeBetweenEntities,
        bool outsideScreen,
        SpawnDirection dir)
    {
        for (int entity = 0; entity < count; ++entity)
        {
            var     spawn  = EnemyManager.Instance.GetEnemyFromCache(actorType);
            float   offset = 2.0f;
            Vector3 pos;
            if (outsideScreen)
            {
                pos = GetPointOutsideScreen(dir, offset, Random.value * 0.5f);
            }
            else
            {
                pos = GetPointInsideArena(1.0f, 1.0f);
            }

            spawn.transform.position = pos;
            spawn.SetActive(true);
            if (timeBetweenEntities != 0.0)
            {
                yield return(new WaitForSeconds(timeBetweenEntities));
            }
        }
    }
Ejemplo n.º 4
0
 private void SetupSpawnDirections()
 {
     spawners = new SpawnDirection[6];
     for (int i = 0; i < 6; i++)
     {
         spawners[i] = new SpawnDirection(i);
     }
 }
Ejemplo n.º 5
0
 private void Update()
 {
     if (Time.time - m_lastSpawn > m_spawnDelay)
     {
         m_lastSpawn = Time.time;
         SpawnType      type      = SpawnType.SquareFighter;
         SpawnDirection direction = (SpawnDirection)Random.Range(0, 4);
         m_enemySpawner.SpawnEnemy(type, direction, Vector3.zero);
     }
 }
Ejemplo n.º 6
0
    public static void changeStartSpawnDirection()
    {
        switch (startSpawnDirection)
        {
        case SpawnDirection.LEFT:
            startSpawnDirection = SpawnDirection.RIGHT;
            break;

        case SpawnDirection.RIGHT:
            startSpawnDirection = SpawnDirection.LEFT;
            break;
        }
    }
Ejemplo n.º 7
0
 private void Start()
 {
     mapSides = new List <Vector2> {
         Vector2.left, Vector2.right, Vector2.up, Vector2.down
     };
     buildingPositions = new LinkedList <Vector2Int>();
     lastBuildingPos   = new Vector2Int(0, 0);
     greaterNeighbor   = lastBuildingPos;
     lesserNeighbor    = lastBuildingPos;
     buildingCount     = 0;
     spawnDirection    = new SpawnDirection(true, true, true, true);
     side = mapSides[Random.Range(0, mapSides.Count)];
 }
Ejemplo n.º 8
0
    public void SpawnEnemy(SpawnType type, SpawnDirection direction, Vector3 spawnOffset)
    {
        var spawnArea = direction switch
        {
            SpawnDirection.North => m_northSpawnArea,
            SpawnDirection.East => m_eastSpawnArea,
            SpawnDirection.South => m_southSpawnArea,
            SpawnDirection.West => m_westSpawnArea,
            _ => null,
        };
        Vector3 spawnPosition = spawnArea.bounds.center + spawnOffset;

        Instantiate(m_spawnLibrary.CheckOutPrefab(type), spawnPosition, spawnArea.gameObject.transform.rotation);
    }
Ejemplo n.º 9
0
    private SpawnDirection NewSpawnDirection()
    {
        int randomValue = _random.Next(0, 10);

        if (randomValue <= 4)
        {
            _spawnDirection = SpawnDirection.Left;
        }
        else if (randomValue >= 5)
        {
            _spawnDirection = SpawnDirection.Right;
        }

        return(_spawnDirection);
    }
Ejemplo n.º 10
0
    IEnumerator Spawning()
    {
        while (myShouldSpawn == true)
        {
            float timeToWait = UnityEngine.Random.Range(4f, 5f);
            yield return(new WaitForSeconds(timeToWait));

            SpawnDirection direction = (SpawnDirection)UnityEngine.Random.Range(0, (int)SpawnDirection.Length);
            Vector3        position  = new Vector3
            {
                y = UnityEngine.Random.Range(-1300, 500)
            };
            SpawnDirection sharkDiection = SpawnDirection.Length;
            switch (direction)
            {
            case SpawnDirection.Right:
                sharkDiection = SpawnDirection.Left;
                position.x    = 2000;
                myBackgroundShark.transform.localPosition = position;
                position.x = -3500;
                myShark.transform.localPosition        = position;
                myBackgroundShark.transform.localScale = new Vector3(1, 1, 1);
                myShark.transform.localScale           = new Vector3(-1, 1, 1);

                break;

            case SpawnDirection.Left:
                sharkDiection = SpawnDirection.Right;
                position.x    = -2000;
                myBackgroundShark.transform.localPosition = position;
                position.x = 3500;
                myShark.transform.localPosition        = position;
                myBackgroundShark.transform.localScale = new Vector3(-1, 1, 1);
                myShark.transform.localScale           = new Vector3(1, 1, 1);
                break;
            }

            myBackgroundShark.Init(direction);

            yield return(new WaitUntil(() => { return myBackgroundShark.myHasMovedAcross == true; }));

            yield return(new WaitForSeconds(UnityEngine.Random.Range(4, 6)));

            myShark.Init(sharkDiection);
            yield return(new WaitUntil(() => { return myShark.myHasMovedAcross == true; }));
        }
    }
Ejemplo n.º 11
0
    IEnumerator Spawning()
    {
        while (isRunning)
        {
            yield return(new WaitForSeconds(mySpawnTime));

            SpawnDirection direction = (SpawnDirection)UnityEngine.Random.Range(0, (spawnPoints.Count));
            GameObject     obj       = Instantiate(octo, spawnPoints[(int)direction]);
            obj.GetComponent <Wander>().Init(direction);
            obj.transform.localPosition = Vector3.zero;
            if (myTimerToReduceSpawnTime >= myTimeWhenShouldReduce)
            {
                myTimerToReduceSpawnTime = 0f;
                mySpawnTime -= myAmountToReduceSpawnTime;
                if (mySpawnTime <= myMinSpawnTime)
                {
                    mySpawnTime = myMinSpawnTime;
                }
            }
            //obj.GetComponent<Rigidbody2D>().AddForce(new Vector2(1f, 1f));
        }
    }
Ejemplo n.º 12
0
    /// <summary>
    /// Will return position for enemy to move towards
    /// Will skip parts of the playing field based on spawn direction
    /// Will look if near top/bottom or left/right in order to give a position that is the longest
    /// </summary>
    /// <param name="spawnDirection"></param>
    /// <param name="enemy"></param>
    /// <returns></returns>
    public Vector3 getMovePosition(SpawnDirection spawnDirection, Enemy enemy)
    {
        float xPosition = 0;
        float zPosition = 0;

        bool includeLeft  = true;
        bool includeRight = true;

        bool includeTop    = true;
        bool includeBottom = true;

        switch (spawnDirection)
        {
        case SpawnDirection.Left:
            includeLeft = false;     //Don't include left because already here
            float positionDistanceA = Vector3.Distance(enemy.transform.position, topLeft.position);
            if (positionDistanceA >= (leftDistance / 2))
            {
                includeTop = false;                                              //Is the near to the topLeft, so don't return top because it's too close
            }
            else
            {
                includeBottom = false;      //Is the near to the bottomLeft, so don't return bottom because it's too close
            }
            break;

        case SpawnDirection.Right:
            includeRight = false;
            float positionDistanceB = Vector3.Distance(enemy.transform.position, topRight.position);
            if (positionDistanceB >= (leftDistance / 2))
            {
                includeTop = false;
            }
            else
            {
                includeBottom = false;
            }
            break;

        case SpawnDirection.Top:
            includeTop = false;
            float positionDistanceC = Vector3.Distance(enemy.transform.position, topLeft.position);
            if (positionDistanceC >= (leftDistance / 2))
            {
                includeTop = false;
            }
            else
            {
                includeBottom = false;
            }
            break;

        case SpawnDirection.Bottom:
            includeBottom = false;
            float positionDistanceD = Vector3.Distance(enemy.transform.position, bottomLeft.position);
            if (positionDistanceD >= (leftDistance / 2))
            {
                includeTop = false;
            }
            else
            {
                includeBottom = false;
            }
            break;
        }

        List <Vector3> positions = new List <Vector3>();

        if (includeLeft)
        {
            positions.Add(getRandomPositionBetweenPoints(topLeft, bottomLeft));
        }
        if (includeRight)
        {
            positions.Add(getRandomPositionBetweenPoints(topRight, bottomRight));
        }
        if (includeBottom)
        {
            positions.Add(getRandomPositionBetweenPoints(bottomLeft, bottomRight));
        }
        if (includeTop)
        {
            positions.Add(getRandomPositionBetweenPoints(topLeft, topRight));
        }

        return(positions[Random.Range(0, positions.Count - 1)]);
    }
Ejemplo n.º 13
0
 private void Start()
 {
     startSpawnDirection = SpawnDirection.LEFT;
 }
Ejemplo n.º 14
0
 //Setup initial values of spawner
 public void SetupSpawnerBasics(int _numObjects, float _mapScale, SpawnDirection _direction)
 {
     numObjects = _numObjects;
     mapScale = _mapScale;
     direction = _direction;
     objects = new StatsStruct[numObjects];
     weightedSpawnChanceSum = new int[numObjects];
     randSpeedMod = Random.Range (0.5f, 2.0f);
 }