private void SpawnRandomItemOnMap(List <Transform> items) { if (items.Count > 0) { int id = UnityEngine.Random.Range(0, items.Count); GeneratedPath.AddItem(Instantiate(items[id], MapManager.m.spawnPoint.transform.position, new Quaternion())); } else { Debug.Log("No items to spawn."); } }
// Creates every floor tile for a given room. // Room r - the room to have its floor tiles created // GameObject floor - the floor tile prefab to be created. See CreateDoor for notes about this. // float baseX, baseZ - the beginning of a maze. Position at which the 0, 0 room's floor tile will go. // float size - the size of a floor tile. Used for positioning with relative indices in room objects. private void CreateFloors(Room r, GameObject floor, float baseX, float baseZ, float size, HashSet <Room> inclusions) { IEnumerator <Vector2> enumer = r.Space.GetEnumerator(); enumer.MoveNext(); Vector2 first = enumer.Current; float minX = first.x; float minY = first.y; foreach (Vector2 point in r.Space) { if (point.x < minX) { minX = point.x; } if (point.y < minY) { minY = point.y; } } List <Vector2> aspTiles = new List <Vector2>(); List <Vector2> aspStartPoints = new List <Vector2>(); foreach (Vector2 point in r.Space) { aspTiles.Add(new Vector2(point.x - minX, point.y - minY)); } foreach (Room adj in r.Adj) { if (inclusions.Contains(adj)) { aspStartPoints.AddRange(ConnectingPoints(r, adj, minX, minY)); } } foreach (Vector2 pt in r.Space) { foreach (Connection c in connections) { if (c.Point.x - baseX == pt.x && c.Point.y - baseZ == pt.y) { float x = 0; float y = 0; switch (c.Dir) { case Direction.Up: x = (pt.x - minX) * GridSizeOfEachTile + (GridSizeOfEachTile / 2); y = (pt.y - minY) * GridSizeOfEachTile + GridSizeOfEachTile - 1; break; case Direction.Down: x = (pt.x - minX) * GridSizeOfEachTile + (GridSizeOfEachTile / 2); y = (pt.y - minY) * GridSizeOfEachTile; break; case Direction.Left: x = (pt.x - minX) * GridSizeOfEachTile; y = (pt.y - minY) * GridSizeOfEachTile + (GridSizeOfEachTile / 2); break; case Direction.Right: x = (pt.x - minX) * GridSizeOfEachTile + GridSizeOfEachTile - 1; y = (pt.y - minY) * GridSizeOfEachTile + (GridSizeOfEachTile / 2); break; } aspStartPoints.Add(new Vector2(x, y)); } } } //Debug.Log("Creating floors for room " + r.Id); IEnumerator <Vector2> pointEnumer = r.Space.GetEnumerator(); pointEnumer.MoveNext(); //Debug.Log("Room " + r.Id + "contains a point " + pointEnumer.Current); //Debug.Log("room " + r.Id + " has " + r.Space.Count + " rooms"); //Debug.Log("TIles"); foreach (Vector2 v in aspTiles) { //Debug.Log(v); } //Debug.Log("start points"); foreach (Vector2 v in aspStartPoints) { //Debug.Log(v); } GeneratedPath p = PathGeneration.RunPathGeneration(aspTiles, aspStartPoints, NumModels, GridSizeOfEachTile, aspTiles.Count * (2 * (int)GridSizeOfEachTile - 1), Random.Range(0, 2)); List <Vector2> points = p.Spaces; HashSet <Vector2> rampPoints = new HashSet <Vector2>(p.Ramps); //Debug.Log("Now laying tiles..."); //Debug.Log("BaseX: " + baseX); //Debug.Log("BaseZ: " + baseZ); //Debug.Log("MinY: " + minY); //Debug.Log("MinX: " + minX); //Debug.Log("Size: " + size); float scale = 1 / GridSizeOfEachTile; Debug.Log(scale); //Center to edge of a tile float offset = TileWidth / 2; float indexMultiple = 10 / GridSizeOfEachTile; foreach (Vector2 v in points) { if (!rampPoints.Contains(v)) { float basePositionX = minX * size + baseX * size; float basePositionY = minY * size + baseZ * size; // Now with 100% fewer magic numbers! float offsetX = v.x * indexMultiple - offset * (1 - 1 / (float)GridSizeOfEachTile); float offsetY = v.y * indexMultiple - offset * (1 - 1 / (float)GridSizeOfEachTile); Vector3 pos = new Vector3(basePositionX + offsetX, 0, basePositionY + offsetY); GameObject g = Instantiate(FloorTilePiece, pos, Quaternion.identity); g.transform.localScale = new Vector3(g.transform.localScale.x * scale, 1, g.transform.localScale.z * scale); } } if (p.Ramps.Count > 0) { for (int i = 0; i < p.Ramps.Count; i += 3) { Vector2 avg = AveragePoint(p.Ramps, i, i + 3); float basePositionX = minX * size + baseX * size; float basePositionY = minY * size + baseZ * size; // magic numbers are BAD GABE WHY YOU DO THIS // currently they're magic for GridSize=4 // They're magic because I don't actually know what their values are supposed to be. float offsetX = avg.x * indexMultiple - offset * (1 - 1 / (float)GridSizeOfEachTile); float offsetY = avg.y * indexMultiple - offset * (1 - 1 / (float)GridSizeOfEachTile); Vector3 pos = new Vector3(basePositionX + offsetX, 0, basePositionY + offsetY); GameObject g = Instantiate(Ramp, pos, DirectionOfPoints(p.Ramps, i)); g.transform.localScale = new Vector3(g.transform.localScale.x * scale, 1, g.transform.localScale.x * scale); } } //foreach (Vector2 point in r.Space) //{ // float x = point.x * size + baseX * size; // float y = 0; // float z = point.y * size + baseZ * size; // floors.Add(Instantiate(floor, new Vector3(x, y, z), Quaternion.identity)); //} }