void SpawnDirtParts(twin cell, twinrect subpartrect) { var bottomleftpos = tilemap.CellToWorld(cell) + twin.one; subpartrect.DoEach(subpart => { banks["dirtpart"].Spawn(GetEntLot("dirts"), bottomleftpos + subpart * 2); }); }
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); }
// 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); }
void Dig(twin cell, bool dirty = true) // dirty is the default! { twinrect dirtyrect = new twinrect(0, 0, 3, 3); if (Gett(cell) == 3) { dirtyrect.min += twin.up * 2; } Sett(cell, 0); if (Gett(cell + twin.up) == 2) { Sett(cell + twin.up, 3); dirtyrect.max += twin.up * 2; } SpawnDirtParts(cell, dirtyrect); }
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); }
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); } }