Beispiel #1
0
        public void ResetGen()
        {
            List <twin> cells = new List <twin>();

            extrabounds.DoEach(cell =>
            {
                xxi.Sett(cell, 1);
            });
            bounds.DoEach(cell => {
                cells.Add(cell);
            });
            Util.shufl(ref cells);

            this.open   = new List <twin>();
            this.closed = new List <twin>();

            open.Add(this.firstCell = new twin(
                         Random.Range(bounds.min.x, bounds.max.x + 1),
                         Random.Range(bounds.min.y, bounds.max.y + 1)
                         ));

            for (int i = 0; i < 5; i++)
            {
                NextGenStep();
            }
        }
Beispiel #2
0
    void SpawnDirtParts(twin cell, twinrect subpartrect)
    {
        var bottomleftpos = tilemap.CellToWorld(cell) + twin.one;

        subpartrect.DoEach(subpart =>
        {
            banks["dirtpart"].Spawn(GetEntLot("dirts"), bottomleftpos + subpart * 2);
        });
    }
Beispiel #3
0
        public HashSet <MazeBody> GetBodiesNearCell(twin cell_pos, float cell_dist)
        {
            int      max_int_cell_dist = Mathf.CeilToInt(cell_dist + .5f);
            twin     max_rel_twin      = twin.one * max_int_cell_dist;
            twinrect zone   = new twinrect(cell_pos - max_rel_twin, cell_pos + max_rel_twin);
            var      bodies = new HashSet <MazeBody>();

            zone.DoEach((test_pos) =>
            {
                if ((test_pos - cell_pos).sqrLength <= cell_dist * cell_dist)
                {
                    bodies.UnionWith(GetBodiesAt(test_pos));
                }
            });
            return(bodies);
        }
Beispiel #4
0
    // Start is called before the first frame update
    void Start()
    {
        Instance = this;
        InitializeAStar();
        InitializeTileSystem();
        //InitializeManualTT();
        twinrect rect_outer      = new twinrect(0, 0, 19, 17);
        twinrect rect_inner      = new twinrect(rect_outer.min + twin.one, rect_outer.max - twin.one);
        twinrect rect_innerinner = new twinrect(rect_outer.min + twin.one * 2, rect_outer.max - twin.one * 2);

        rect_outer.DoEach(cell =>
        {
            if (rect_inner.Contains(cell))
            {
                float chance_of_wall = .02f;
                if (cell.x % 2 == 0)
                {
                    chance_of_wall += .1f;
                }
                if (cell.y % 2 == 0)
                {
                    chance_of_wall += .1f;
                }

                if (Random.value < chance_of_wall && (cell - twin.one).taxicabLength > 3 && (cell - new twin(18, 16)).taxicabLength > 3)
                {
                    Sett(cell, 1);
                }
                else
                {
                    Sett(cell, 0);
                    if (Random.value < .12f)
                    {
                        banks["ant"].Spawn <CommuterAnt>(GetEntLot("ants")).Setup(master, cell, pather_solids);
                    }
                }
            }
            else
            {
                // border wall
                Sett(cell, 1);
            }
        });

        banks["player"].Spawn <BaseCommuter>(GetEntLot("player")).Setup(master, new twin(18, 16), pather_solids);
    }
    private void Start()
    {
        Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("Bad"), LayerMask.NameToLayer("Bad"));

        InitializeManualTT();
        var bounds      = new twinrect(-1, 0, 20, 10 - 1);
        var innerbounds = new twinrect(bounds.min + twin.one, bounds.max - twin.one);

        bounds.DoEach(cell =>
        {
            var EntPos = tilemap.layoutGrid.GetCellCenterWorld(cell);
            if (innerbounds.Contains(cell))
            {
                int storey = cell.y / 3 % 2 + 1;
                if (cell.y % 3 == 0)
                {
                    if (cell.x % 4 != (storey))
                    {
                        Sett(cell, 10);
                    }
                }
                if (cell.y % 3 == 1)
                {
                    if (cell.x % 4 == (storey + 2) % 4)
                    {
                        if (GetEntLot("machines").IsEmpty())
                        {
                            banks["avatar"].Spawn(GetEntLot("players"), EntPos);
                        }

                        banks["machine"].Spawn <Machine>(GetEntLot("machines"), EntPos).Setup();
                    }
                }
            }
            else
            {
                Sett(cell, 10);
            }
        });

        banks["gross_smoker"].Spawn <Smoker>(GetEntLot("bads"), new Vector3(84, 120)).Setup(this);
    }
Beispiel #6
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.R))
        {
            player.transform.position = mazeMaster.grid.GetCellCenterWorld(new twin(0, 8));
        }

        twin camcell = new twin(Mathf.FloorToInt(player.transform.position.x / 160f), Mathf.FloorToInt(player.transform.position.y / 144f));

        gameCamera.transform.position = camcell.Scale(160, 144) + new Vector3(80, 72, -10);

        if (currentCamCell != camcell)
        {
            GetEntLot("losers").Clear();
            ClearAllTiles();

            Random.InitState(1024132 + camcell.x + 992 * camcell.y);

            float density = .2f + camcell.taxicabLength * .05f;

            var root  = camcell.Scale(20, 18);
            var outer = new twinrect(root, root + new twin(20 - 1, 18 - 1));
            var inner = new twinrect(outer.min + twin.one, outer.max - twin.one);
            outer.DoEach(cell =>
            {
                if (cell.y == outer.mid.y || cell.y == outer.mid.y + 1 || cell.x == outer.mid.x || cell.x == outer.mid.x + 1)
                {
                    // if in center aisles and close to the edge
                    if (!inner.Contains(cell))
                    {
                        Sett(cell, 2); // 'no ai past this point'
                    }
                    else if (cell.x < inner.min.x + 3 || cell.x > inner.max.x - 3 || cell.y < inner.min.y + 2 || cell.y > inner.max.y - 2)
                    {
                        Sett(cell, 0);
                    }
                    // if in center aisles and close to the middle of the room
                    else
                    {
                        SpawnRandom(cell, density);
                    }
                }
                else if (inner.Contains(cell)) // if in meat of room and *not* in center aisles
                {
                    if (Random.value < density)
                    {
                        Sett(cell, 1);
                    }
                }
                else // if along outer edge
                {
                    Sett(cell, 1);
                }
            });


            if (camcell.y > currentCamCell.y)
            {
                var jumper = player.GetComponent <navdi3.jump.Jumper>();
                jumper.body.velocity = new Vector2(jumper.body.velocity.x, jumper.y_JumpSpeed);
            }

            currentCamCell = camcell;

            var xlabel = "--";
            if (camcell.x != 0)
            {
                xlabel = Mathf.Abs(camcell.x) + (camcell.x < 0 ? "w" : "e");
            }
            var ylabel = "--";
            if (camcell.y != 0)
            {
                ylabel = Mathf.Abs(camcell.y) + (camcell.y < 0 ? "s" : "n");
            }

            position_label.Print(xlabel + "/" + ylabel);
        }
    }
Beispiel #7
0
        bool GenerateNewLevel()
        {
            // clear everything
            fullScreen.DoEach(cell => { Sett(cell, 1); });

            // generate list
            var cells = new List <twin>();

            playArea.DoEach(cell => { cells.Add(cell); });
            Util.shufl(ref cells);

            var open   = new List <twin>();
            var closed = new List <twin>();

            open.Add(new twin(
                         Random.Range(playArea.min.x, playArea.max.x + 1),
                         Random.Range(playArea.min.y, playArea.max.y + 1)
                         ));

            while (open.Count > 0)
            {
                var open_index = Random.Range(0, open.Count);
                var cell       = open[open_index];
                open.RemoveAt(open_index);
                twin.ShuffleCompass();

                foreach (var dir in twin.compass)
                {
                    var ok = true;

                    foreach (var dx in new int[] { -1, 1 })
                    {
                        foreach (var dy in new int[] { -1, 1 })
                        {
                            if (Gett(cell + new twin(dx, dy)) == 0)
                            {
                                // empty corner. only allowed if it connects a proper path:
                                var path = 0;
                                if (Gett(cell + new twin(dx, 0)) == 0)
                                {
                                    path++;
                                }
                                if (Gett(cell + new twin(0, dy)) == 0)
                                {
                                    path++;
                                }
                                if (path != 1)
                                {
                                    ok = false;
                                }
                            }
                        }
                    }

                    if (ok && open.Count > 5 && Random.value < .25f)
                    {
                        ok = false;
                    }

                    if (ok)
                    {
                        Sett(cell, 0);

                        var newopen = cell + dir;
                        if (!playArea.Contains(newopen))
                        {
                            continue;
                        }
                        if (open.Contains(newopen))
                        {
                            continue;
                        }
                        if (closed.Contains(newopen))
                        {
                            continue;
                        }
                        open.Add(newopen);

                        closed.Add(cell); // do i need this?
                    }
                    else
                    {
                        continue;
                    }
                }
            }


            int deadEndsCleanedUp = int.MaxValue;

            while (deadEndsCleanedUp > 5)
            {
                deadEndsCleanedUp = 0;

                // clean up dead ends
                playArea.DoEach(cell =>
                {
                    if (Gett(cell) == 0)
                    {
                        var pathcount = 0;
                        foreach (var dir in twin.compass)
                        {
                            if (Gett(cell + dir) == 0)
                            {
                                pathcount++;
                            }
                        }
                        if (pathcount < 2)
                        {
                            Sett(cell, 1);
                            deadEndsCleanedUp++;
                        }
                    }
                });
            }

            foreach (var agent in GetEntLot("guys").GetComponentsInChildren <InsiderBasicAgent>())
            {
                Object.Destroy(agent.gameObject);
            }

            var freeSpawnCells = new List <twin>();

            playArea.DoEach(cell => { if (Gett(cell) == 0)
                                      {
                                          freeSpawnCells.Add(cell);
                                      }
                            });
            Util.shufl(ref freeSpawnCells);

            banks["player"].Spawn <InsiderBasicAgent>(GetEntLot("guys")).Setup(mazeMaster, freeSpawnCells[0]);

            bloodSpawnPoint = freeSpawnCells[1];

            for (int i = 0; i < 2; i++)
            {
                banks["redblood"].Spawn <InsiderBasicAgent>(GetEntLot("guys")).Setup(mazeMaster, bloodSpawnPoint);
                banks["whiteblood"].Spawn <InsiderBasicAgent>(GetEntLot("guys")).Setup(mazeMaster, bloodSpawnPoint);
            }

            oxygenIntakes = new twin[4];

            for (int i = 0; i < 4; i++)
            {
                oxygenIntakes[i] = freeSpawnCells[2 + i];
                banks["virus"].Spawn <InsiderBasicAgent>(GetEntLot("guys")).Setup(mazeMaster, oxygenIntakes[i]);
            }

            return(true);
        }