Inheritance: MonoBehaviour
        private static bool RemoveLongestEdge(Tiling gPlanar, List <Vertex> face)
        {
            double longestLength = -1, length;
            Vertex initialVertex = null, oldVertex = null;
            Vertex removeA = null, removeB = null;

            foreach (Vertex boundaryVertex in face)
            {
                if (oldVertex == null)
                {
                    initialVertex = oldVertex = boundaryVertex;
                    continue;
                }
                length = gPlanar.GetEucledianDist(boundaryVertex.Id, oldVertex.Id);
                if (longestLength < length)
                {
                    removeA       = oldVertex;
                    removeB       = boundaryVertex;
                    longestLength = length;
                }
                oldVertex = boundaryVertex;
            }
            length = gPlanar.GetEucledianDist(oldVertex.Id, initialVertex.Id);
            if (longestLength < length)
            {
                removeA       = initialVertex;
                removeB       = oldVertex;
                longestLength = length;
            }
            //Console.WriteLine("Removing an edge of length "+ longestLength);
            //remove the longest edge
            return(gPlanar.RemoveEdge(removeA.Id, removeB.Id));
        }
Ejemplo n.º 2
0
        public MapData(Grid floor, Tilemap ground, Tilemap onGround, Tilemap blaind, Tiling til)
        {
            this.oneFloor      = floor;
            this.layerGround   = ground;
            this.layerOnGround = onGround;
            this.layerBlaind   = blaind;
            this.til           = til;
            this.Hex2MoveCost  = new Dictionary <HexSprite, int>()
            {
            };
            this.Hex2Trap = new Dictionary <HexSprite, int>()
            {
            };

            this.A  = HexUnit2World(gen.A);
            this.B  = HexUnit2World(gen.B);
            this.C  = HexUnit2World(gen.C);
            this.BC = HexUnit2World(gen.BC);
            this.CA = HexUnit2World(gen.CA);
            this.AB = HexUnit2World(gen.AB);

            this.unit2World
                = new Dictionary <gen.unit, Vector3>()
                {
                { gen.unit.a, A },
                { gen.unit.ab, AB },
                { gen.unit.b, B },
                { gen.unit.bc, BC },
                { gen.unit.c, C },
                { gen.unit.ca, CA },
                };
        }
Ejemplo n.º 3
0
        public static Tiling DeserializeTilingSettings(string str)
        {
            int xi = str.IndexOf("tx");
            int yi = str.IndexOf("ty");
            int si = str.IndexOf("ts");

            if (xi < 0 || yi < 0 || si < 0)
            {
                Debug.Log(Misc.warningText + "Couldn't deserialize tiling settings -- using default");
                return(tilingPresets[0]);
            }
            else
            {
                string xs = str.Substring(xi + 2, 2);
                string ys = str.Substring(yi + 2, 2);
                string ss = str.Substring(si + 2, 4);

                Tiling tiling = new Tiling(
                    "deserialized",
                    int.Parse(xs),
                    int.Parse(ys),
                    int.Parse(ss)
                    );

                return(tiling);
            }
        }
Ejemplo n.º 4
0
        public static void Experiment()
        {
            TilingConfig config = new TilingConfig(4, 3);
            Tiling       tiling = new Tiling();

            tiling.Generate(config);

            HashSet <H3.Cell.Edge> completed = new HashSet <H3.Cell.Edge>(new H3.Cell.EdgeEqualityComparer());

            string fileName = "hopf.pov";

            using (StreamWriter sw = File.CreateText(fileName))
            {
                Tile[] tiles = tiling.Tiles.ToArray();
                //foreach( Tile t in tiling.Tiles )
                foreach (Tile t in new Tile[] { tiles[0] })
                {
                    foreach (Segment seg in t.Boundary.Segments)
                    {
                        H3.Cell.Edge e = new H3.Cell.Edge(seg.P1, seg.P2);
                        if (completed.Contains(e))
                        {
                            continue;
                        }

                        HopfLink(sw,
                                 Sterographic.PlaneToSphereSafe(e.Start),
                                 Sterographic.PlaneToSphereSafe(e.End), anti: false);
                        completed.Add(e);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private static List <Vector3D[]> BasePointsTiling()
        {
            TilingConfig config = new TilingConfig(3, 7, maxTiles: 100);
            Tiling       tiling = new Tiling();

            tiling.Generate(config);

            HashSet <H3.Cell.Edge> finished = new HashSet <H3.Cell.Edge>(new H3.Cell.EdgeEqualityComparer());

            int numPerSeg = 25;
            List <Vector3D[]> basePoints = new List <Vector3D[]>();

            foreach (Tile t in tiling.Tiles)
            {
                foreach (Segment s in t.Boundary.Segments)
                {
                    H3.Cell.Edge e = new H3.Cell.Edge(s.P1, s.P2);
                    if (finished.Contains(e))
                    {
                        continue;
                    }
                    finished.Add(e);

                    Vector3D[] points = s.Subdivide(numPerSeg).Select(p =>
                    {
                        p = new Vector3D(p.X, 0, p.Y);
                        return(H3Models.BallToUHS(p));
                    }).ToArray();
                    basePoints.Add(points);
                }
            }

            return(basePoints);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="TilingController" /> class.
        /// </summary>
        /// <param name="tiling">The tiling.</param>
        /// <param name="view">The view.</param>
        /// <exception cref="System.ArgumentNullException">
        /// </exception>
        /// <exception cref="System.InvalidOperationException"></exception>
        public TilingController([NotNull] Tiling tiling, [NotNull] IView view)
            : base(view)
        {
            if (tiling == null)
            {
                throw new ArgumentNullException(nameof(tiling));
            }

            _tiling = tiling;

            IResourceManager resourceManager = DependencyManger.GetResourceManager(StyleManager);

            _resourceManager = resourceManager;

            resourceManager.Add(SolidColourStyle.Transparent);
            resourceManager.Add(SolidColourStyle.White);
            resourceManager.Add(SolidColourStyle.Black);
            resourceManager.Add(SolidColourStyle.Gray);
            resourceManager.Add(SolidColourStyle.CornflowerBlue);
            resourceManager.Add(TransparentBlue);

            _tiles = _tiling.GetTiles(view.ViewBounds, Enumerable.Empty <TileBase>());

            _styleManagerChangedHandler = _styleManager_Changed;
            StyleManager.StylesChanged += _styleManagerChangedHandler;

            Tools = new Tool[]
            {
                EditLine  = new EditLineTool(this, _tolerance),
                SplitLine = new SplitLineTool(this, _tolerance)
            };

            view.ViewBoundsChanged += View_ViewBoundsChanged;
        }
Ejemplo n.º 7
0
 public static string SerializeTilingSettings(Tiling tiling)
 {
     return
         ("tx" + tiling.tilesX.ToString("00") +
          "ty" + tiling.tilesY.ToString("00") +
          "ts" + tiling.quiltSize.ToString("0000"));
 }
Ejemplo n.º 8
0
        internal List <Point> GetPath(VisibilityVertex vs, VisibilityVertex vt,
                                      bool shrinkDistances, Tiling g)
        {
            var pathPoints = new List <Point>();

            vs.IsShortestPathTerminal = vt.IsShortestPathTerminal = true;
            _visGraph.ClearPrevEdgesTable();
            var router = new SingleSourceSingleTargetShortestPathOnVisibilityGraph(_visGraph, vs, vt, g)
            {
                LengthMultiplier         = 0.8,
                LengthMultiplierForAStar = 0.3
            };
            var vpath = router.GetPath(shrinkDistances);

            if (vpath == null)
            {
                Console.WriteLine("seeing a null path");
                vs.IsShortestPathTerminal = vt.IsShortestPathTerminal = false;
                return(pathPoints);
            }
            var path = vpath.ToList();

            for (int i = 0; i < path.Count(); i++)
            {
                pathPoints.Add(path[i].Point);
            }


            vs.IsShortestPathTerminal = vt.IsShortestPathTerminal = false;
            return(pathPoints);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     Sets the tiling.
        /// </summary>
        /// <param name="tiling">The tiling.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.InvalidOperationException"></exception>
        public void SetTiling([NotNull] Tiling tiling)
        {
            if (tiling == null)
            {
                throw new ArgumentNullException(nameof(tiling));
            }

            if (tiling == _tiling)
            {
                return;
            }

            StyleManager oldStyleManager = StyleManager;

            Debug.Assert(oldStyleManager != null, "oldStyleManager != null");
            oldStyleManager.StylesChanged -= _styleManagerChangedHandler;

            _tiling = tiling;

            StyleManager.StylesChanged += _styleManagerChangedHandler;

            IResourceManager resourceManager    = DependencyManger.GetResourceManager(tiling.StyleManager);
            IResourceManager oldResourceManager = Interlocked.Exchange(ref _resourceManager, resourceManager);

            DependencyManger.ReleaseResourceManager(ref oldResourceManager, oldStyleManager);

            resourceManager.Add(SolidColourStyle.Transparent);
            resourceManager.Add(SolidColourStyle.White);
            resourceManager.Add(SolidColourStyle.Black);
            resourceManager.Add(SolidColourStyle.Gray);
            resourceManager.Add(SolidColourStyle.CornflowerBlue);
            resourceManager.Add(TransparentBlue);

            _tiles = _tiling.GetTiles(View.ViewBounds, Enumerable.Empty <TileBase>());
        }
Ejemplo n.º 10
0
        public void ApplyPreset()
        {
            if (tilingPresetIndex < tilingPresets.Length)
            {
                tiling = tilingPresets[tilingPresetIndex];
            }
            else if (tilingPresetIndex == tilingPresets.Length)
            {
                // if it's default (dynamic with player settings)
                if (QualitySettings.lodBias < 0.5f)
                {
                    tiling = tilingPresets[3]; // extra low
                }
                else if (QualitySettings.lodBias < 1)
                {
                    tiling = tilingPresets[0]; // standard
                }
                else
                {
                    tiling = tilingPresets[1]; // hq
                }
            }

            tiling.Setup();

            SetupQuilt();
        }
Ejemplo n.º 11
0
        public static Tiling DeserializeTilingSettings(string str)
        {
            int xi = str.IndexOf("tx");
            int yi = str.IndexOf("ty");
            int wi = str.IndexOf("qw");
            int hi = str.IndexOf("qh");

            if (xi < 0 || yi < 0 || wi < 0 || hi < 0)
            {
                Debug.Log(Misc.debugLogText + "Couldn't deserialize tiling settings -- using default");
                return(tilingPresets[0]);
            }
            else
            {
                string xs = str.Substring(xi + 2, 2);
                string ys = str.Substring(yi + 2, 2);
                string ws = str.Substring(wi + 2, 4);
                string hs = str.Substring(hi + 2, 4);

                Tiling tiling = new Tiling(
                    "deserialized",
                    int.Parse(xs),
                    int.Parse(ys),
                    int.Parse(ws),
                    int.Parse(hs)
                    );

                return(tiling);
            }
        }
Ejemplo n.º 12
0
        IEnumerator Screenshot3D()
        {
            var previousTiling = tiling;

            tiling = tilingPresets[0];
            SetupQuilt();

            yield return(null);

            Texture2D quiltTex = new Texture2D(quiltRT.width, quiltRT.height, TextureFormat.RGB24, false);

            RenderTexture.active = quiltRT;
            quiltTex.ReadPixels(new Rect(0, 0, quiltRT.width, quiltRT.height), 0, 0);
            RenderTexture.active = null;
            var    bytes = quiltTex.EncodeToPNG();
            string fullPath;
            string fullName;

            if (!Misc.GetNextFilename(Path.GetFullPath("."), Application.productName + "_" + SerializeTilingSettings(tiling), ".png", out fullName, out fullPath))
            {
                Debug.LogWarning(Misc.debugLogText + "Couldn't save screenshot");
            }
            else
            {
                // fullFileName += DateTime.Now.ToString(" yyyy MMdd HHmmss");
                // fullFileName = fullFileName.Replace(" ", "_") + ".png";
                File.WriteAllBytes(fullPath, bytes);
                Debug.Log(Misc.debugLogText + "Wrote screenshot to " + fullName);
            }

            tiling = previousTiling;
            SetupQuilt();
        }
Ejemplo n.º 13
0
    // a function that creates a buddy on the side required
    void MakeNewBuddy(int rightOrLeft)
    {
        // calculating the new position for our new buddy
        Vector3 newPosition = new Vector3(myTransform.position.x + spriteWidth * (float)rightOrLeft, myTransform.position.y, myTransform.position.z);
        // instantating our new body and storing him in a variable
        Transform newBuddy = Instantiate(myTransform, newPosition, myTransform.rotation) as Transform;

        // if not tilable let's reverse the x size og our object to get rid of ugly seams
        if (reverseScale == true)
        {
            newBuddy.localScale = new Vector3(newBuddy.localScale.x * -1, newBuddy.localScale.y, newBuddy.localScale.z);
        }

        newBuddy.parent = myTransform.parent;
        if (rightOrLeft > 0)
        {
            newBuddy.GetComponent <Tiling>().hasALeftBuddy = true;
            newBuddy.GetComponent <Tiling>().leftBuddy     = this;
            rightBuddy = newBuddy.GetComponent <Tiling>();
        }
        else
        {
            newBuddy.GetComponent <Tiling>().hasARightBuddy = true;
            newBuddy.GetComponent <Tiling>().rightBuddy     = this;
            leftBuddy = newBuddy.GetComponent <Tiling>();
        }
    }
Ejemplo n.º 14
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="TilingController" /> class.
        /// </summary>
        /// <param name="tiling">The tiling.</param>
        /// <param name="view">The view.</param>
        /// <exception cref="System.ArgumentNullException">
        /// </exception>
        /// <exception cref="System.InvalidOperationException"></exception>
        public TilingController([NotNull] Tiling tiling, [NotNull] IView view)
            : base(view)
        {
            if (tiling == null) throw new ArgumentNullException(nameof(tiling));

            _tiling = tiling;

            IResourceManager resourceManager = DependencyManger.GetResourceManager(StyleManager);
            _resourceManager = resourceManager;

            resourceManager.Add(SolidColourStyle.Transparent);
            resourceManager.Add(SolidColourStyle.White);
            resourceManager.Add(SolidColourStyle.Black);
            resourceManager.Add(SolidColourStyle.Gray);
            resourceManager.Add(SolidColourStyle.CornflowerBlue);
            resourceManager.Add(TransparentBlue);

            _tiles = _tiling.GetTiles(view.ViewBounds, Enumerable.Empty<TileBase>());

            _styleManagerChangedHandler = _styleManager_Changed;
            StyleManager.StylesChanged += _styleManagerChangedHandler;

            Tools = new Tool[]
            {
                EditLine = new EditLineTool(this, _tolerance),
                SplitLine = new SplitLineTool(this, _tolerance)
            };

            view.ViewBoundsChanged += View_ViewBoundsChanged;
        }
Ejemplo n.º 15
0
        public static void Cell633()
        {
            TilingConfig config = new TilingConfig(6, 3, maxTiles: 20000);
            Tiling       tiling = new Tiling();

            tiling.GenerateInternal(config, Polytope.Projection.VertexCentered);

            double edgeLength = Honeycomb.EdgeLength(6, 3, 3);

            double z      = 0.25;
            double offset = H3Models.UHS.ToEHorizontal(edgeLength, z);
            double scale  = offset / tiling.Tiles.First().Boundary.Segments.First().Length;

            foreach (Tile tile in tiling.Tiles)
            {
                tile.Transform(Mobius.Scale(scale));
            }

            Vector3D dummy;
            double   radius;

            H3Models.UHS.Geodesic(new Vector3D(0, 0, z), new Vector3D(scale, 0, z), out dummy, out radius);
            Vector3D midradius = H3Models.UHSToBall(new Vector3D(0, 0, radius));
            double   temp      = midradius.Z;
            double   temp2     = (1 - temp) / 2;
            double   temp3     = temp + temp2;
            double   temp4     = temp3;

            Vector3D circumradius = H3Models.UHSToBall(new Vector3D(0, 0, z));

            temp  = circumradius.Z;
            temp2 = (1 - temp) / 2;
            temp3 = temp + temp2;
            temp4 = temp3;

            // Checking

            /*
             * Vector3D test = new Vector3D( offset, 0, z );
             * test = H3Models.UHSToBall( test );
             * double edgeLength2 = DonHatch.e2hNorm( test.Abs() );
             * edgeLength2 += 0;
             */

            HashSet <H3.Cell.Edge> edges = new HashSet <H3.Cell.Edge>();

            foreach (Tile tile in tiling.Tiles)
            {
                foreach (Segment seg in tile.Boundary.Segments)
                {
                    H3.Cell.Edge edge = new H3.Cell.Edge(
                        H3Models.UHSToBall(seg.P1 + new Vector3D(0, 0, z)),
                        H3Models.UHSToBall(seg.P2 + new Vector3D(0, 0, z)));
                    edges.Add(edge);
                }
            }

            PovRay.WriteH3Edges(new PovRay.Parameters(), edges.ToArray(), "edges.pov");
        }
Ejemplo n.º 16
0
 public MapGenerator(MapData map, int sightRadius, int r = 0)
 {
     this.map             = map;
     this.til             = map.til;
     this.generatedCenter = new HexTile(map, 0, 0, 0);
     this.generatedRadius = r;
     this.sightRadius     = sightRadius;
 }
Ejemplo n.º 17
0
 public static string SerializeTilingSettings(Tiling tiling)
 {
     return
         "tx" + tiling.tilesX.ToString("00") +
         "ty" + tiling.tilesY.ToString("00") +
         "qw" + tiling.quiltW.ToString("0000") +
         "qh" + tiling.quiltH.ToString("0000");
 }
Ejemplo n.º 18
0
 public MapGenerator(HexTile center, int sightRadius, int r = 0)
 {
     this.generatedCenter = center;
     this.generatedRadius = r;
     this.sightRadius     = sightRadius;
     this.til             = generatedCenter.til;
     this.map             = generatedCenter.map;
 }
 internal SingleSourceSingleTargetShortestPathOnVisibilityGraph(VisibilityGraph visGraph, VisibilityVertex sourceVisVertex, VisibilityVertex targetVisVertex, Tiling g)
 {
     _visGraph        = visGraph;
     _source          = sourceVisVertex;
     _target          = targetVisVertex;
     _source.Distance = 0;
     _g = g;
 }
Ejemplo n.º 20
0
 public void GenerateTilesByCity()
 {
     tiling = Tiling.City;
     foreach (Place place in Places)
     {
         UpdatePlacesByCity(place);
     }
     tilesGenerated = true;
 }
 private static bool AllBoundaryVerticesAreJunctions(Tiling gPlanar, List <Vertex> face)
 {
     foreach (Vertex boundaryVertex in face)
     {
         if (boundaryVertex.Id < gPlanar.N)
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 22
0
 // Use this for initialization
 void Start()
 {
     tiling1 = GameObject.Find("1_plan").GetComponent <Tiling>();
     tiling2 = GameObject.Find("2_plan").GetComponent <Tiling>();
     main    = GameObject.Find("Main Camera").GetComponent <LevelCreator>();
     up      = main.GetComponent <up_down>();
     end     = new Vector3(player.position.x + 10.7f, player.position.y + 2f, -1f);
     score   = GameObject.Find("ScoreC").GetComponent <Canvas>();
     menu    = GameObject.Find("Canvas").GetComponent <Canvas>();
     input   = GameObject.Find("Main Camera").GetComponent <inputController>();
     anim    = GameObject.Find("Player").GetComponent <playerHandler>();
 }
Ejemplo n.º 23
0
        // https://plus.google.com/u/0/117663015413546257905/posts/BnCEkdNiTZ2
        public static void TwinDodecs()
        {
            Tiling       tiling = new Tiling();
            TilingConfig config = new TilingConfig(5, 3);

            tiling.GenerateInternal(config, Polytope.Projection.VertexCentered);                // Vertex-centered makes infinities tricky

            Dodec dodec = new Dodec();

            foreach (Tile tile in tiling.Tiles)
            {
                foreach (Segment seg in tile.Boundary.Segments)
                {
                    Vector3D p1 = seg.P1, p2 = seg.P2;
                    if (Infinity.IsInfinite(p1))
                    {
                        p1 = Infinity.InfinityVector;
                    }
                    if (Infinity.IsInfinite(p2))
                    {
                        p2 = Infinity.InfinityVector;
                    }

                    dodec.Verts.Add(p1);
                    dodec.Verts.Add(p2);
                    dodec.Midpoints.Add(Halfway(p1, p2));
                }
            }

            // Now recursively add more vertices.
            HashSet <Vector3D> allVerts = new HashSet <Vector3D>();

            foreach (Vector3D v in dodec.Verts)
            {
                allVerts.Add(v);
            }
            RecurseTwins(allVerts, dodec, 0);

            using (StreamWriter sw = File.CreateText("dual_dodecs_points_sphere.pov"))
            {
                foreach (Vector3D vert in allVerts)
                {
                    Vector3D onSphere = Sterographic.PlaneToSphereSafe(vert);
                    sw.WriteLine(PovRay.Sphere(new Sphere()
                    {
                        Center = onSphere, Radius = 0.01
                    }));

                    //if( !Infinity.IsInfinite( vert ) )
                    //	sw.WriteLine( PovRay.Sphere( new Sphere() { Center = vert, Radius = 0.01 } ) );
                }
            }
        }
Ejemplo n.º 24
0
        public float Grade(Tiling tiling, int height, int width)
        {
            List <List <int> > loops = new List <List <int> >();
            int localFullCount       = 0;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    PriorityTile tile = tiling.GetTile(y * width + x);
                    if (!tile.tile.hasEdgeColor(1))
                    {
                        localFullCount++;
                    }
                    List <TileNode> smallestIncidentLoop = getSmallestLoop(tiling, tile, y, x, width);
                    if (smallestIncidentLoop == null)
                    {
                        continue;
                    }
                    List <int> loop = smallestIncidentLoop.Select(l => l.i * 100 + l.j).ToList();
                    loop.Sort();
                    if (!loops.Any(p => p.SequenceEqual(loop)))
                    {
                        loops.Add(loop);
                    }
                }
            }

            int localCount = loops.Count;

            if (localCount == 0)
            {
                localCount = 1;
            }
            float localAverage = (float)loops.Sum(x => x.Count) / (float)localCount;

            localCount = Math.Abs(localCount - loopCount);
            if (localCount < loopCountRange)
            {
                localCount = 0;
            }
            else
            {
                localCount -= loopCountRange;
            }

            localAverage = Math.Abs(localAverage - averageLoopSize);

            float localFilledDifference = Math.Abs(percentMazeFilled - ((float)localFullCount / (float)(width * height)));

            return(localCount + localAverage * 2 + localFilledDifference * 2);
        }
Ejemplo n.º 25
0
    // Use this for initialization
    void Start()
    {
        Registrar reg = this.GetComponent <Registrar> ();

        tiling = reg.tiling;

        ballRend = ball.gameObject.GetComponent <Renderer> ();
        IP       = this.GetComponent <InitialPoses> ();

        //Vector3 ballInitPos = IP.ballInitialPosition;
        //Vector4 ballInititalPosition = new Vector4(ballInitPos.x, ballInitPos.y, ballInitPos.z, 1f);
        //initial_diff = ballInititalPosition - wrap(ballInititalPosition);
    }
Ejemplo n.º 26
0
 public virtual void Start()
 {
     background   = GameObject.FindWithTag("Background").GetComponent <Tiling>();
     playerObject = GameObject.FindWithTag("Player");
     player       = playerObject.GetComponent <Player>();
     sound        = GameObject.FindWithTag("SoundManager").GetComponent <SoundManager>();
     difficulty   = PlayerPrefs.GetFloat("Difficulty", 1.0f);
     pickupMod    = 1.0f / PlayerPrefs.GetFloat("Difficulty", 1.0f);
     damageMod    = PlayerPrefs.GetFloat("Difficulty", 1.0f);
     if (screenShake > 0)
     {
         cameraShakeScript = Camera.main.gameObject.GetComponent <CameraShakeScript>();
     }
 }
Ejemplo n.º 27
0
    // Use this for initialization
    void Start()
    {
        #region Button init
        //find buttons
        StartButton = GameObject.Find("ButtonStart").GetComponent <Button>();
        if (StartButton == null)
        {
            Debug.LogError("ButtonStart not found.");
        }
        CreditsButton = GameObject.Find("ButtonCredits").GetComponent <Button>();
        if (CreditsButton == null)
        {
            Debug.LogError("ButtonCredits not found.");
        }
        QuitButton = GameObject.Find("ButtonQuit").GetComponent <Button>();
        if (QuitButton == null)
        {
            Debug.LogError("ButtonQuit not found.");
        }

        //add listeners to the buttons
        StartButton.onClick.AddListener(StartButtonService);
        CreditsButton.onClick.AddListener(CreditsButtonService);
        QuitButton.onClick.AddListener(QuitButtonService);
        #endregion

        #region Hide credits
        menuElements = GameObject.FindGameObjectsWithTag("UI");

        for (int i = 0; i < menuElements.Length; i++)
        {
            if (menuElements[i].name == "Credits")
            {
                menuElements[i].SetActive(false);
            }
        }
        #endregion

        #region Tile the background
        tiler = GetComponent <Tiling>();
        if (tiler == null)
        {
            Debug.LogError("Tiler not found.");
        }
        else //tile the world
        {
            tiler.TileWorld("Prefabs/Tileset/Tile_Roof_", 10.0f, 10.0f, false, false, false, false, 3, 3);
        }
        #endregion
    }
Ejemplo n.º 28
0
    // Use this for initialization
    void Start()
    {
        //globalGameManager = GameObject.Find("GlobalManager").GetComponent<GlobalGameManager>();

        #region World bound support
        mainCamera  = Camera.main;
        worldBounds = new Bounds(Vector3.zero, Vector3.one);
        UpdateWorldWindowBound();
        #endregion

        #region Enemy spawning
        if (EnemyToSpawn == null)
        {
            EnemyToSpawn = Resources.Load("Prefabs/Enemy") as GameObject;
        }
        if (EnemyToSpawn == null)
        {
            Debug.LogError("Enemy not found.");
        }

        // first 50 enemies
        for (int i = 0; i < initialSpawn; i++)
        {
            SpawnAnEnemy(true);
        }
        #endregion

        #region Other references
        scoreText = GameObject.Find("Score").GetComponent <Text>();
        if (scoreText == null)
        {
            Debug.LogError("Score not found.");
        }
        statusText = GameObject.Find("Status").GetComponent <Text>();
        if (statusText == null)
        {
            Debug.LogError("Status not found.");
        }

        tiler = GameObject.Find("Tiler").GetComponent <Tiling>();
        if (tiler == null)
        {
            Debug.LogError("Tiler not found.");
        }
        else //tile the world
        {
            tiler.TileWorld("Prefabs/Tileset/Tile_Wood_", 11.8f, 11.8f, false, false);
        }
        #endregion
    }
Ejemplo n.º 29
0
        void Update()
        {
            if (Input.GetKeyUp(KeyCode.Space))
            {
                found = false;
            }
            if (found)
            {
                return;
            }
            if (mode == SceneMode.Generate)
            {
                Tiling[] tilings = new Tiling[4];

                for (int i = 0; i < 4; i++)
                {
                    List <PriorityTile> tileSet = tileSets[i];

                    Tiling tiling = BuildTiling(tileSet);

                    GradeTiling(tiling);

                    tilings[i] = tiling;
                }

                List <PriorityTile> optimalTileSet = null;
                if (EvaluateGeneration(tilings, ref optimalTileSet))
                {
                    found = true;
                    foreach (PriorityTile tile in optimalTileSet)
                    {
                        Debug.Log(tile.tile + ":" + tile.priority);
                    }
                }
            }
            else
            {
                Tiling tiling = BuildTiling(tiles);
                GradeTiling(tiling);
                while (tiling.grade > threshold)
                {
                    tiling = BuildTiling(tiles);
                    GradeTiling(tiling);
                }
                InstantiateTiling(tiling);
                found = true;

                level++;
            }
        }
        /*
         * input: A geometric planar graph
         * output: remove a long edge from each face if the face does not contain any real node
         */
        public static void RemoveLongEdgesFromThinFaces(Tiling gPlanar)
        {
            Console.WriteLine("Removing Thin Faces");
            //bool searchFurther = true;
            //while (searchFurther)
            //{
            //you need to handle face one after another - since you are changing the adjacency list
            //searchFurther = false;
            List <Face> faces = new List <Face>();

            for (int nodeIndex = 0; nodeIndex < gPlanar.NumOfnodes; nodeIndex++)
            {
                for (int neighborIndex = 0; neighborIndex < gPlanar.DegList[nodeIndex]; neighborIndex++)
                {
                    bool          degenerate;
                    Vertex        tailVertex = gPlanar.VList[nodeIndex];
                    Vertex        headVertex = gPlanar.VList[gPlanar.EList[nodeIndex, neighborIndex].NodeId];
                    List <Vertex> boundary   = GetRightIncidentFace(gPlanar, tailVertex, headVertex, out degenerate);
                    if (degenerate)
                    {
                        continue;            // Console.WriteLine("Found a degenerate face!");
                    }
                    //check whether if all the boundary vertices are junctions
                    if (AllBoundaryVerticesAreJunctions(gPlanar, boundary) == false)
                    {
                        continue;
                    }

                    faces.Add(new Face(boundary));
                    //if (searchFurther) break;
                }
                //if (searchFurther) break;
            }
            foreach (var face in faces)
            {
                //if not a valid boundary continue
                if (!FaceIsStillValid(gPlanar, face.boundary))
                {
                    continue;
                }
                //check whether the face is thin, and if so, find the longest edge in this face and remove it
                if (GetFacewidth(face.boundary) > gPlanar.thinness)
                {
                    continue;
                }
                //searchFurther =
                RemoveLongestEdge(gPlanar, face.boundary);
            }
            //}
        }
Ejemplo n.º 31
0
        public PointSet(int n, Tiling g, int pointsPerLevel)
        {
            NumPoints = n;
            Pt        = new WeightedPoint[n + 1];
#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=340
            throw new InvalidOperationException();
#else
            pointMap = new int[g.NumOfnodes + 1, g.NumOfnodes + 1];
#endif
            _selected = new int[g.NumOfnodes + 1];
            Random r1 = new Random(1);


            //generate points in random
            while (n > 0)
            {
                var temp = r1.Next(1, g.NumOfnodes); //,temp2;
                if (_selected[temp] == 1 || (g.VList[temp].XLoc + g.VList[temp].YLoc) % 2 == 1)
                {
                    continue;
                }
                Pt[n]           = new WeightedPoint(g.VList[temp].XLoc, g.VList[temp].YLoc, 0);
                _selected[temp] = 1;
                //compute weight based on point density
                Pt[n].GridPoint      = temp;
                g.VList[temp].Weight = Pt[n].Weight;
                n--;
            }
            AssignWeight(Pt, NumPoints, (int)Math.Sqrt(g.NumOfnodes));


            NumOfLevels = NumPoints / pointsPerLevel;
            if (NumPoints % pointsPerLevel > 0)
            {
                NumOfLevels++;
            }

            for (int index = 1; index <= NumPoints; index++)
            {
                Pt[index].ZoomLevel = 1 + (index - 1) / pointsPerLevel;
            }

            for (int i = 1; i <= NumPoints; i++)
            {
                g.VList[Pt[i].GridPoint].Weight    = Pt[i].Weight;
                g.VList[Pt[i].GridPoint].ZoomLevel = Pt[i].ZoomLevel;
                pointMap[Pt[i].X, Pt[i].Y]         = i;
            }
        }
Ejemplo n.º 32
0
        /// <summary>
        ///     Sets the tiling.
        /// </summary>
        /// <param name="tiling">The tiling.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.InvalidOperationException"></exception>
        public void SetTiling([NotNull] Tiling tiling)
        {
            if (tiling == null) throw new ArgumentNullException(nameof(tiling));

            if (tiling == _tiling) return;

            StyleManager oldStyleManager = StyleManager;
            Debug.Assert(oldStyleManager != null, "oldStyleManager != null");
            oldStyleManager.StylesChanged -= _styleManagerChangedHandler;

            _tiling = tiling;

            StyleManager.StylesChanged += _styleManagerChangedHandler;

            IResourceManager resourceManager = DependencyManger.GetResourceManager(tiling.StyleManager);
            IResourceManager oldResourceManager = Interlocked.Exchange(ref _resourceManager, resourceManager);

            DependencyManger.ReleaseResourceManager(ref oldResourceManager, oldStyleManager);

            resourceManager.Add(SolidColourStyle.Transparent);
            resourceManager.Add(SolidColourStyle.White);
            resourceManager.Add(SolidColourStyle.Black);
            resourceManager.Add(SolidColourStyle.Gray);
            resourceManager.Add(SolidColourStyle.CornflowerBlue);
            resourceManager.Add(TransparentBlue);

            _tiles = _tiling.GetTiles(View.ViewBounds, Enumerable.Empty<TileBase>());
        }
        private static Tiling CreateTiling(double offsetX, double offsetY, double width, SimpleColor color)
        {
            Tiling tiling = new Tiling(new Rect(0, 0, width, 2));
            tiling.Position.Translate(offsetX, offsetY);
            var tilingEditor = new FixedContentEditor(tiling);
            tilingEditor.GraphicProperties.IsStroked = false;
            tilingEditor.GraphicProperties.FillColor = color;
            tilingEditor.DrawRectangle(new Rect(0, 0, width, 1));
            LinearGradient gradient = new LinearGradient(new Point(0, 0), new Point(width, 0));
            gradient.GradientStops.Add(new GradientStop(color, 0));
            gradient.GradientStops.Add(new GradientStop(RgbColors.White, .5));
            gradient.GradientStops.Add(new GradientStop(color, 1));
            tilingEditor.GraphicProperties.FillColor = gradient;
            tilingEditor.DrawRectangle(new Rect(0, 1, width, 1));

            return tiling;
        }