void Awake() { //Core classes initiation (learn more about system calls in “Additional options” of “User’s guide.pdf” document ClearResorces(); constraints = new SpaceConstraints(xMin, xMax, yMin, yMax, zMin, zMax); spaceGraph = new SpaceGraph(constraints, spaceFragmentation, 0.7d, this); }
public WaveTrace(SpaceConstraints spaceConstraintsInp, object cTInstance, Vector3 start, Vector3 goal) { this.cTInstance = (CancellationToken)cTInstance; spaceConstarintsInst = spaceConstraintsInp; this.start = SpaceGraph.GetCellIndexFromCoordOnLevel(start, 0); this.goal = SpaceGraph.GetCellIndexFromCoordOnLevel(goal, 0); waves = new List <HashSet <Vector3> >(); }
public bool RedefineConstraints(float XMin, float XMax, float YMin, float YMax, float ZMin, float ZMax, float SideLength, double heur_fact) { if (XMin < XMax && YMin < YMax && ZMin < ZMax && SideLength > 0 && heur_fact >= 0.5f && heur_fact <= 1) { constraints = new SpaceConstraints(XMin, XMax, YMin, YMax, ZMin, ZMax); spaceGraph = new SpaceGraph(constraints, SideLength, heur_fact, this); return(true); } else { return(false); } }
public void CreateDungeon() { float roomRatio = 0.6875f; // 256x176 // Use CountConstraints to make a truly random map. /* * CountConstraints constraints = new CountConstraints((int)maxSpaces, (int)maxKeys, (int)maxSwitches); * Debug.Log("Constraints: " + maxSpaces + "," + maxKeys + "," + maxSwitches); */ // Use SpaceConstraints to make a map fitting to a shape. ///* MZSpaceMap spaceMap = new MZSpaceMap(); //random tile map //tileMap = tileMapObjects[Random.Range(0, tileMapObjects.Length)].GetComponentInChildren<Tilemap>(); tileMap = tileMapObjects[0].GetComponentInChildren <Tilemap>(); foreach (Vector3Int posWithZ in tileMap.cellBounds.allPositionsWithin.GetEnumerator()) { if (tileMap.HasTile(posWithZ)) { Vector2Int pos = new Vector2Int(posWithZ.x, posWithZ.y); spaceMap.Set(pos, true); } } SpaceConstraints constraints = new SpaceConstraints(spaceMap, (int)maxKeys, (int)maxSwitches); //*/ generator = new LinearDungeonGenerator(Random.Range(0, int.MaxValue), constraints, numberOfRooms, (int)maxGenerations); //generator = new DungeonGenerator(Random.Range(0, int.MaxValue), constraints, numberOfRooms); Debug.Log("Generate()"); generator.Generate(); dungeon = generator.GetMZDungeon(); foreach (MZRoom room in dungeon.GetRooms()) { MZSymbol item = room.GetItem(); GameObject toInstantiate = normalRoom; Color roomColor = new Color((float)room.GetIntensity(), 1.0f - (float)room.GetIntensity(), 0.5f - (float)room.GetIntensity() / 2); if (item != null) { switch (item.GetValue()) { case (int)MZSymbol.MZSymbolValue.Start: toInstantiate = entranceRoom; roomColor = Color.white; break; case (int)MZSymbol.MZSymbolValue.Boss: toInstantiate = bossRoom; break; case (int)MZSymbol.MZSymbolValue.Goal: toInstantiate = goalRoom; roomColor = Color.white; break; default: break; } if (item.GetValue() >= 0) { GameObject keyObjectInstance = Instantiate(key, new Vector3(room.GetCoords()[0].x, room.GetCoords()[0].y * roomRatio, 0), Quaternion.identity, transform); keyObjectInstance.GetComponent <SpriteRenderer>().color = keyColors[item.GetValue()]; keyObjectInstance.transform.localScale += new Vector3(2, 2, 2); instances.Add(keyObjectInstance); } else if (item.GetValue() == (int)MZSymbol.MZSymbolValue.Switch) { GameObject keyObjectInstance = Instantiate(roomSwitch, new Vector3(room.GetCoords()[0].x, room.GetCoords()[0].y * roomRatio, 0), Quaternion.identity, transform); keyObjectInstance.transform.localScale += new Vector3(2, 2, 2); instances.Add(keyObjectInstance); } } GameObject roomObject = Instantiate(toInstantiate, new Vector3(room.GetCoords()[0].x, room.GetCoords()[0].y * roomRatio, 0), Quaternion.identity, transform); roomObject.GetComponent <SpriteRenderer>().color = roomColor; instances.Add(roomObject); foreach (MZEdge edge in room.GetEdges()) { MZRoom targetRoom = dungeon.Get(edge.GetTargetRoomId()); Vector2Int edgeDir = targetRoom.GetCoords()[0] - room.GetCoords()[0]; toInstantiate = openDoor; GameObject keyObject = null; Color keyColor = Color.white; if (edge.GetSymbol() != null) { switch (edge.GetSymbol().GetValue()) { case (int)MZSymbol.MZSymbolValue.SwitchOn: toInstantiate = blockedDoor; keyObject = roomSwitchOn; break; case (int)MZSymbol.MZSymbolValue.SwitchOff: toInstantiate = blockedDoor; keyObject = roomSwitchOff; break; default: break; } if (edge.GetSymbol().GetValue() >= 0) { toInstantiate = lockedDoor; keyObject = key; keyColor = keyColors[edge.GetSymbol().GetValue()]; } } //this only works for identically sized rooms Vector3 pos = Vector3.zero; if (edgeDir == Vector2Int.right) { pos = new Vector3(room.GetCoords()[0].x + 0.5f, room.GetCoords()[0].y * roomRatio, 0); GameObject doorObject = Instantiate(toInstantiate, pos, Quaternion.identity, transform); instances.Add(doorObject); if (keyObject != null) { GameObject keyObjectInstance = Instantiate(keyObject, pos, Quaternion.identity, transform); instances.Add(keyObjectInstance); keyObjectInstance.GetComponent <SpriteRenderer>().color = keyColor; keyObjectInstance.transform.localScale += new Vector3(1, 1, 1); } } else if (edgeDir == Vector2Int.down) { pos = new Vector3(room.GetCoords()[0].x, room.GetCoords()[0].y * roomRatio - (roomRatio / 2), 0); Vector2Int relativePos = Vector2Int.zero + Vector2Int.up; float angle = Mathf.Atan2(relativePos.y, relativePos.x) * Mathf.Rad2Deg; Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward); //90 degrees GameObject doorObject = Instantiate(toInstantiate, pos, rotation, transform); instances.Add(doorObject); if (keyObject != null) { GameObject keyObjectInstance = Instantiate(keyObject, pos, Quaternion.identity, transform); instances.Add(keyObjectInstance); keyObjectInstance.GetComponent <SpriteRenderer>().color = keyColor; keyObjectInstance.transform.localScale += new Vector3(1, 1, 1); } } } } foreach (var room in dungeon.GetRooms()) { foreach (var edge in room.GetEdges()) { //wrap this up laterino } } }