Esempio n. 1
0
    public bool requireSpawn()
    {
        int count = rgb2d.Cast(-Vector2.up, contactFilter, hitBuffer, shellRadius);
        var d     = new Dictionary <RaycastHit2D, float>();

        if (count > 0)
        {
            for (int i = 0; i < count; i++)
            {
                d.Add(hitBuffer[i], hitBuffer[i].distance);
            }
            d.OrderBy(item => item.Value);
            //var hit = d.First().Key;
            foreach (var hitData in d)
            {
                var   hit              = hitData.Key;
                float soilUpperBound   = hit.collider.gameObject.GetComponent <Collider2D>().bounds.center.y + hit.collider.gameObject.GetComponent <Collider2D>().bounds.extents.y;
                float playerLowerBound = GetComponent <BoxCollider2D>().bounds.center.y - GetComponent <BoxCollider2D>().bounds.extents.y;

                if (hit.collider != null && soilUpperBound <= playerLowerBound)
                {
                    SpawnerTile st = hit.collider.gameObject.GetComponent <SpawnerTile>();
                    Vector3     pt = hit.point - Vector2.up * spawnOffset;
                    if (st != null)
                    {                                 // check whether the object hit has a spawnertile component (that means, if it can spawn plants)
                        st.spawnHere(gameObject, pt); // invoke spawn passing the player as arg
                        //StartCoroutine(splat(hit.collider.gameObject));
                        GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerPosUpdater>().setParams(20, 3.5f, 5f);
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
Esempio n. 2
0
 public void genRowSpawners(int curHeight)
 {
     //float totalPillars = pillarsLeft;
     for (int i = 0; i < width; i++)
     {
         Vector3Int v = new Vector3Int(i, curHeight, 0);
         if (otherTiles.spawnerPossible(i, curHeight, spawnersLeft))
         {
             int x = r.Next(1000);
             //Debug.Log(streak);
             //Debug.Log(x);
             if (x < (spawnersLeft * 2000) / (width * height))
             {
                 //Debug.Log(x);
                 //Debug.Log(((pillarsLeft / (width * height)) * 80000));
                 SpawnerTile t = chooseSpawner(v);
                 spawnerTiles.Add(t);
                 theSpawners.SetTile(v, t);
                 //tileCost[x][y] = 10000000;
                 spawnersLeft--;
                 Vector2 temp = new Vector2(v.x, v.y);
                 //spawnerSet.Add(temp);
             }
         }
     }
 }
Esempio n. 3
0
 public void ResetToInitialState()
 {
     m_WaveNumber         = 1;
     m_WaveText.text      = "Wave: " + m_WaveNumber;
     m_Spawner            = null;
     m_WaveTimerText.text = "Click Next Wave to Start";
     StopCoroutine(m_WaveTimerCoroutine);
     StopCoroutine(m_SpawnerCoroutine);
 }
Esempio n. 4
0
    public void LoadLevel(Level level)
    {
        if (level == null)
        {
            throw new ArgumentNullException();
        }

        DestroyLoadedLevel();

        m_LoadedLevel = level;

        Vector2 topLeft = new Vector2(m_MapRoot.transform.position.x - level.m_Width / 2, m_MapRoot.transform.position.y + level.m_Height / 2);

        List <Vector2> worldWaypoints = new List <Vector2>();

        foreach (Vector2Int point in level.m_Waypoints)
        {
            worldWaypoints.Add(topLeft + new Vector2(point.x, -point.y));
        }


        for (int row = 0; row < level.m_Height; row++)
        {
            for (int col = 0; col < level.m_Width; col++)
            {
                Vector3 tilePos = new Vector3(topLeft.x + col, topLeft.y - row);

                switch (level.m_Map[row, col])
                {
                case Level.Tile.Buildable:
                    Instantiate(level.m_BuildableTile, tilePos, Quaternion.identity, m_MapRoot);
                    break;

                case Level.Tile.Path:
                    Instantiate(level.m_PathTile, tilePos, Quaternion.identity, m_MapRoot);
                    break;

                case Level.Tile.Spawner:
                    GameObject  tile    = Instantiate(level.m_SpawnerTile, tilePos, Quaternion.identity, m_MapRoot);
                    SpawnerTile spawner = tile.GetComponent <SpawnerTile>();
                    spawner.m_Waypoints = worldWaypoints.ToArray();
                    break;

                case Level.Tile.Goal:
                    Instantiate(level.m_GoalTile, tilePos, Quaternion.identity, m_MapRoot);
                    break;
                }
            }
        }

        m_Camera.m_CameraBounds.extents = new Vector3(level.m_Width / 2 + m_CameraBoundsPadding.x, level.m_Height / 2 + m_CameraBoundsPadding.y);
    }
Esempio n. 5
0
    // for funsies
    //private HashSet<Vector2> spawnerSet;ev

    // Start is called before the first frame update
    void Start()
    {
        main     = this;
        camera   = Camera.main.gameObject;
        player   = PlayerClass.main.gameObject;
        spawners = new List <SpawnerClass>();
        for (int i = 0; i < spritesToMatch.Count; i++)
        {
            spawners.Add(new SpawnerClass(spritesToMatch[i], enemiesToMatch[i]));
        }
        tm = this.gameObject.GetComponent <Tilemap>();
        Vector3Int starter = new Vector3Int(0, 0, 0);

        otherTiles = floorPillars.gameObject.GetComponent <TileSetter>();
        Vector3Int ender = new Vector3Int(otherTiles.getWidth() - 1, otherTiles.getHeight() - 1, 0);

        tm.BoxFill(ender, theFloor, starter.x, starter.y, ender.x, ender.y);
        width  = otherTiles.getWidth();
        height = otherTiles.getHeight();
        //Debug.Log(width);
        initialSpawnersLeft = spawnersLeft;
        for (int i = 0; i < height; i++)
        {
            genRowSpawners(i);
            //Debug.Log(i);
        }
        if (initialSpawnersLeft == spawnersLeft && initialSpawnersLeft > 0)
        {
            Vector3Int  v = new Vector3Int(width - 1, height - 1, 0);
            SpawnerTile t = chooseSpawner(v);
            spawnerTiles.Add(t);
            theSpawners.SetTile(v, t);
        }
        genWalls();
        int larger = Math.Max(width, height);

        camera.transform.position = new Vector3(width / 2.0f, height / 2.0f, -10);
        camera.GetComponent <Camera>().orthographicSize = (camScaling / 10.0f) * larger;
        Vector2[] thePoints = { new Vector2(-20, -20), new Vector2(width + 20, -20), new Vector2(width + 20, height + 20), new Vector2(-20, height + 20), new Vector2(-20, -20) };
        theWalls = GameObject.Find("Walls");
        theWalls.GetComponent <EdgeCollider2D>().points     = thePoints;
        theWalls.GetComponent <EdgeCollider2D>().edgeRadius = 20;
        if (TryGetComponent <RedDragonFloor>(out RedDragonFloor rdf))
        {
            rdf.changeCamera(camera);
        }

        StartCoroutine("beAsleep");
    }
Esempio n. 6
0
    private SpawnerTile chooseSpawner(Vector3Int v)
    {
        //SpawnerClass temp = spawners[r.Next(spawners.Count)];
        SpawnerClass temp     = spawners[r.Next(spawners.Count)];
        Vector3      changedV = floorPillars.gameObject.GetComponentInParent <Grid>().CellToWorld(v) + offset;
        SpawnerTile  t        = (SpawnerTile)ScriptableObject.CreateInstance("SpawnerTile");// SpawnerTile(temp.sprite, temp.spawnedEnemy, genWaves(AvgMobs, waves, spawners.Count), changedV);

        t.sprite         = temp.sprite;
        t.spawnedEnemy   = temp.spawnedEnemy;
        t.wavesTillSpawn = genWaves(AvgMobs, waves, initialSpawnersLeft);
        t.pos            = changedV;
        t.player         = player;
        t.f = this.gameObject;

        return(t);
    }
Esempio n. 7
0
 private void Awake()
 {
     sTile = GetComponent <SpawnerTile>();
 }