예제 #1
0
 void Movement()
 {
     if (Input.GetKeyDown(KeyCode.LeftArrow))
     {
         transform.position += new Vector3(-1, 0, 0);
         if (isDontCollide())
         {
             updateGrid();
         }
         else
         {
             transform.position += new Vector3(1, 0, 0);
         }
     }
     else if (Input.GetKeyDown(KeyCode.RightArrow))
     {
         transform.position += new Vector3(1, 0, 0);
         if (isDontCollide())
         {
             updateGrid();
         }
         else
         {
             transform.position += new Vector3(-1, 0, 0);
         }
     }
     else if (Input.GetKeyDown(KeyCode.UpArrow) && tag != "Square")
     {
         transform.Rotate(0, 0, -90);
         if (isDontCollide())
         {
             updateGrid();
         }
         else
         {
             transform.Rotate(0, 0, 90);
         }
     }
     else if (Input.GetKeyDown(KeyCode.DownArrow) || Time.time - falling >= toFall)
     {
         transform.position += new Vector3(0, -1, 0);
         if (isDontCollide())
         {
             updateGrid();
         }
         else
         {
             transform.position += new Vector3(0, 1, 0);
             Boundaries.deleteAll();
             if (SceneManager.GetActiveScene().buildIndex != 4)
             {
                 AudioSource.PlayClipAtPoint(BreakSound, Camera.main.transform.position);
             }
             gameObject.tag = "Dead";
             FindObjectOfType <Spawn>().Next();
             enabled = false;
         }
         falling = Time.time;
     }
 }
예제 #2
0
        private Board CreateBoard()
        {
            var screenBounds = pbCanvas.Bounds;
            var boundaries   = new Boundaries(screenBounds.Left, screenBounds.Top, screenBounds.Right, screenBounds.Bottom);

            return(new Board(boundaries, settings.SnakePartSize.Width));
        }
예제 #3
0
파일: Board.cs 프로젝트: sehta7/Ziarna
        private void SelectNotAll(bool notAll)
        {
            for (int i = 0; i < Width; i++)
            {
                for (int j = 0; j < Height; j++)
                {
                    if (notAll)
                    {
                        if (GrainsInPreviousStep[i, j].PenColor.Color == Color.White)
                        {
                            notBoundaries.Add(new Point(i, j));
                            continue;
                        }
                    }

                    if ((i < Width - 1 &&
                         GrainsInPreviousStep[i, j].PenColor != GrainsInPreviousStep[i + 1, j].PenColor) ||
                        (j < Height - 1 &&
                         GrainsInPreviousStep[i, j].PenColor != GrainsInPreviousStep[i, j + 1].PenColor))
                    {
                        Boundaries.Add(new Point(i, j));
                    }
                    else
                    {
                        notBoundaries.Add(new Point(i, j));
                    }
                }
            }
        }
예제 #4
0
        public virtual void Draw(SpriteBatch spriteBatch, Camera2D layoutCamera, float TileSize, PlanetLevel level)
        {
            drawArea = GetDrawTiles(spriteBatch, layoutCamera.Pos, TileSize, layoutCamera.Zoom, level);

            // Get variables from Vector Array
            right  = (int)drawArea.Right;
            left   = (int)drawArea.Left;
            top    = (int)drawArea.Top;
            bottom = (int)drawArea.Bottom;

            for (int y = top; y <= bottom; y++)
            {
                for (int x = left; x <= right; x++)
                {
                    if (x < 0 || x > level.PlanetMap.GetLength(0) - 1 ||
                        y < 0 || y > level.PlanetMap.GetLength(1) - 1)     // Draw into the infinite distance.
                    {
                        DrawTile(spriteBatch, new Tile {
                            position = new Vector2(x * TileSize, y * TileSize), type = TileTypes.Wall
                        });
                        continue;
                    }

                    DrawTile(spriteBatch, level.PlanetMap[x, y]);
                }
            }
        }
예제 #5
0
    /// <summary>
    /// Prints the tile to the texture
    /// </summary>
    public void TilesToTexture()
    {
        XY size = Boundaries.Size();

        for (int i = 0; i < size.x; ++i)
        {
            for (int j = 0; j < size.x; ++j)
            {
                Tile t = _tiles[i, j];
                if (t == Tile.WALL)
                {
                    _texture.SetPixel(i, j, Color.black);
                }
                else if (t == Tile.FLOOR)
                {
                    _texture.SetPixel(i, j, Color.white);
                }
                else
                {
                    _texture.SetPixel(i, j, _corridorColor);
                }
            }
        }
        _texture.Apply();
    }
예제 #6
0
        /// <summary>
        /// Returns the X's and Y's to draw. Min and Max.
        /// </summary>
        /// <param name="spriteBatch"></param>
        /// <param name="cameraPosition"></param>
        /// <param name="Tile"></param>
        /// <returns></returns>
        private Boundaries GetDrawTiles(SpriteBatch spriteBatch, Vector2 cameraPosition, float TileSize, float zoom,
                                        PlanetLevel level)
        {
            TileSize = ConvertUnits.ToDisplayUnits(TileSize);

            // Tiles need to be resized depending upon zoom level. Performance optimization
            float ZoomedTile = TileSize * zoom;

            // Everything is relative to the ship
            Vector2 TileShipIsOver = new Vector2(
                // Ceiling indicates the max. A few pixels offscreen is better than black bar!
                (float)Math.Floor(cameraPosition.X / TileSize),
                (float)Math.Floor(cameraPosition.Y / TileSize));

            float width, height; // # of tiles across screen

            width  = (float)Math.Ceiling(spriteBatch.GraphicsDevice.Viewport.Width / ZoomedTile);
            height = (float)Math.Ceiling(spriteBatch.GraphicsDevice.Viewport.Height / ZoomedTile);

            // Define boundaries for drawing, this is hackish still.
            Boundaries boundaries = new Boundaries();

            boundaries.Left   = (int)(TileShipIsOver.X - Math.Floor(width / 2f)) - 1;    // Left
            boundaries.Right  = (int)(TileShipIsOver.X + Math.Ceiling(width / 2f)) + 3;  // Right
            boundaries.Top    = (int)(TileShipIsOver.Y - Math.Floor(height / 2f)) - 1;   // Top
            boundaries.Bottom = (int)(TileShipIsOver.Y + Math.Ceiling(height / 2f)) + 4; // Bottom

            return(boundaries);
        }
예제 #7
0
        private void MapYAxis(IShip ship, ref SortedDictionary <Coordinate, Segment> temporarySegments)
        {
            coordinate = this.GenerateCoordinate();

            // Top is 1 to 5 and Bottom is 5 to 10
            Boundaries orientation = coordinate.Y > yMidPoint ? Boundaries.Top : Boundaries.Bottom;

            if (orientation == Boundaries.Top)
            {
                for (int y = coordinate.Y; y > coordinate.Y - ship.ShipLength; y--)
                {
                    if (!this.AddToYAxis(coordinate.X, y, ship, ref temporarySegments))
                    {
                        break;
                    }
                }
            }

            if (orientation == Boundaries.Bottom)
            {
                for (int y = coordinate.Y; y < coordinate.Y + ship.ShipLength; y++)
                {
                    if (!this.AddToYAxis(coordinate.X, y, ship, ref temporarySegments))
                    {
                        break;
                    }
                }
            }
        }
예제 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="idx">boundary index</param>
        /// <param name="level"></param>
        public void MoveBoundary(int idx, double level)
        {
            var copy = Boundaries.ToArray();

            copy[idx]  = new LayerBoundary(level, copy[idx].Rank);
            Boundaries = copy;
        }
예제 #9
0
        public Map(Boundaries boundaries)
        {
            Boundaries = boundaries;
            _impacts = new List<Position>();

            CreateMap();
        }
예제 #10
0
        public void TestFullCase()
        {
            string input =
                "1111111111\n"
                + "1111111111\n"
                + "1111111111\n"
                + "1111111111\n"
                + "1111111111\n"
                + "1111111111\n"
                + "1111111111\n"
                + "1111111111\n"
                + "1111111111\n"
                + "1111111111\n";

            bool[,] blob = Util.InputToMatrix(input);

            BoundaryFinder finder     = new BoundaryFinder();
            Boundaries     boundaries = finder.FindBoundaries(blob, 10);

            Assert.AreEqual(0, boundaries.Left);
            Assert.AreEqual(9, boundaries.Right);
            Assert.AreEqual(9, boundaries.Bottom);
            Assert.AreEqual(0, boundaries.Top);
            Assert.AreEqual(100, boundaries.CellReads);
        }
예제 #11
0
        private void MapXAxis(IShip ship, ref SortedDictionary <Coordinate, Segment> temporarySegments)
        {
            coordinate = this.GenerateCoordinate();

            // Left to Right 65 to 69 Right to Left 74 to 70
            Boundaries orientation = coordinate.X >= xMidPoint ? Boundaries.RightToLeft : Boundaries.LeftToRight;

            if (orientation == Boundaries.LeftToRight)
            {
                for (int x = coordinate.X; x < coordinate.X + ship.ShipLength; x++)
                {
                    if (!this.AddToXAxis(x, coordinate.Y, ship, ref temporarySegments))
                    {
                        break;
                    }
                }
            }

            if (orientation == Boundaries.RightToLeft)
            {
                for (int x = coordinate.X; x > coordinate.X - ship.ShipLength; x--)
                {
                    if (!this.AddToXAxis(x, coordinate.Y, ship, ref temporarySegments))
                    {
                        break;
                    }
                }
            }
        }
    void Update()
    {
        if (ButtonManager.GetDown(ButtonManager.ButtonID.SAVE, this))
        {
            print("save");
            Save();
        }

        if (ButtonManager.GetDown(ButtonManager.ButtonID.LOAD, this))
        {
            print("load");
            Load();
        }

        if (ButtonManager.GetDown(ButtonManager.ButtonID.CREATE, this))
        {
            print("create boundaries");
            Create(true);
        }

        if (ButtonManager.GetDown(ButtonManager.ButtonID.CREATE_SAVED, this))
        {
            print("create saved");
            Create(false);
        }

        if (ButtonManager.GetDown(ButtonManager.ButtonID.UPDATE_BOUNDARIES, this))
        {
            print("UPDATE_BOUNDARIES");
            boundariesDescription = save;
        }
    }
예제 #13
0
        public void UpdateBorder(int SizeOfSystem)
        {
            sizeOfSystem = SizeOfSystem;
            //Console.WriteLine("Setting size of system to " + SizeOfSystem);
            if (Border.Body != null && _physicsManager.World.BodyList.Contains(Border.Body))
            {
                Debugging.DisposeStack.Push(this.ToString());
                Border.Body.Dispose();
            }
            borderList.Clear();

            Vertices verts = Boundaries.CreateConcaveSemiCircle(SizeOfSystem / 100f, SizeOfSystem / 100);

            foreach (Vector2 v in verts)
            {
                borderList.Add(v);
            }



            Border = new PlanetBorder();
            var tempbd = new CollisionDataObject(Border, BodyTypes.WallTile);

            Debugging.AddStack.Push(this.ToString());
            Border.Body                 = BodyFactory.CreateLoopShape(_physicsManager.World, verts, Vector2.Zero, tempbd);
            Border.Body.IsStatic        = true;
            Border.Body.UserData        = tempbd;
            Border.Body.SleepingAllowed = true;
            Border.Body.Friction        = 0f;
            Border.Body.Restitution     = 0.2f;
        }
예제 #14
0
파일: Buffer.cs 프로젝트: shekky/reactive
                public void Run(Boundaries parent)
                {
                    _buffer = new List <TSource>();

                    base.Run(parent._source);
                    Disposable.SetSingle(ref _boundariesDisposable, parent._bufferBoundaries.SubscribeSafe(new BufferClosingObserver(this)));
                }
예제 #15
0
    public static LinkedList <Edge> FindPath(Node start, Node dest, Boundaries boundaries = null)
    {
        HashSet <GridTile>           Visited = new HashSet <GridTile>();
        Dictionary <GridTile, Edge>  Parent  = new Dictionary <GridTile, Edge>();
        Dictionary <GridTile, float> gScore  = new Dictionary <GridTile, float>();

        SimplePriorityQueue <Node, float> pq = new SimplePriorityQueue <Node, float>();

        float temp_gCost, prev_gCost;

        gScore[start.pos] = 0;
        pq.Enqueue(start, EuclidianDistance(start, dest));
        Node current;

        while (pq.Count > 0)
        {
            current = pq.Dequeue();
            if (current.pos.Equals(dest.pos))
            {
                //Rebuild path and return it
                return(RebuildPath(Parent, current));
            }


            Visited.Add(current.pos);

            //Visit all neighbours through edges going out of node
            foreach (Edge e in current.edges)
            {
                //If we defined boundaries, check if it crosses it
                if (boundaries != null && IsOutOfGrid(e.end.pos, boundaries))
                {
                    continue;
                }

                //Check if we visited the outer end of the edge
                if (Visited.Contains(e.end.pos))
                {
                    continue;
                }

                temp_gCost = gScore[current.pos] + e.weight;

                //If new value is not better then do nothing
                if (gScore.TryGetValue(e.end.pos, out prev_gCost) && temp_gCost >= prev_gCost)
                {
                    continue;
                }

                //Otherwise store the new value and add the destination into the queue
                Parent[e.end.pos] = e;
                gScore[e.end.pos] = temp_gCost;

                pq.Enqueue(e.end, temp_gCost + EuclidianDistance(e.end, dest));
            }
        }

        return(new LinkedList <Edge>());
    }
예제 #16
0
    private void Start()
    {
        GameObject boundaryObj = GameObject.Find("Boundaries");
        Boundaries boundary    = boundaryObj.GetComponent <Boundaries>();

        boundary_x = boundary.cameraBoundary_x;
        boundary_y = boundary.cameraBoundary_y;
    }
예제 #17
0
 void Awake()
 {
     Instance        = this;
     _topBoundary    = GetComponent <SpriteRenderer>().bounds.max.y;
     _bottomBoundary = GetComponent <SpriteRenderer>().bounds.min.y;
     _leftBoundary   = GetComponent <SpriteRenderer>().bounds.min.x;
     _rightBoundary  = GetComponent <SpriteRenderer>().bounds.max.x;
 }
예제 #18
0
 private void GetBoundaries()
 {
     boundaries = new Boundaries();
     topLeft = new Vector3(boundaries.LeftBoundary, 0, boundaries.TopBoundary);
     bottomLeft = new Vector3(boundaries.LeftBoundary, 0, boundaries.BottomBoundary);
     topRight = new Vector3(boundaries.RightBoundary, 0, boundaries.TopBoundary);
     bottomRight = new Vector3(boundaries.RightBoundary, 0, boundaries.BottomBoundary);
 }
예제 #19
0
 // Use this for initialization
 void Start()
 {
     _levelManager = FindObjectOfType <LevelManager>();
     _lastShotTime = -projectilesInterval;
     _size         = GetComponent <SpriteRenderer>().size;
     _boundaries   = new Boundaries(_size / 2);
     _movement     = new Movement(gameObject, _boundaries);
 }
예제 #20
0
 public AttackEvent()
 {
     Text    = "A horde of <b>Wasps</b> is going to attack our beehive!";
     Timeout = GameObject.FindObjectOfType <EventSpawner>().AttackTimeout;
     Level   = 3;
     Image   = spawner.AttackSprite;
     bounds  = GameObject.Find("Ground").GetComponent <Boundaries>();
 }
예제 #21
0
 public TanksGameState() : base(GameState.Running)
 {
     tanks       = new List <Tank>();
     obstacles   = new List <Obstacle>();
     projectiles = new List <Projectile>();
     boundaries  = new Boundaries(0, NokiaApp.ScreenWidth, 0, NokiaApp.ScreenHeight);
     Initialize();
 }
    // Update is called once per frame
    void FixedUpdate()
    {
        transform.Translate(Vector3.right * Input.GetAxis("Horizontal"));
        Vector3 position = transform.position;

        position.x         = Mathf.Clamp(position.x, Boundaries.Left(), Boundaries.Right());
        transform.position = position;
    }
예제 #23
0
    void Awake()
    {
        var boundaries = new Boundaries();

        var newGal = Instantiate(galaxy, new Vector3(boundaries.LeftBoundary + (boundaries.LeftBoundary + boundaries.RightBoundary) / 2, 0, boundaries.TopBoundary), Quaternion.identity);

        galaxies.Add(newGal);
    }
예제 #24
0
 //CharacterSelect selection;
 // Use this for initialization
 void Awake()
 {
     bounds            = GameObject.Find("Boundaries").GetComponent <Boundaries>();
     currentenemycount = enemycount;
     info = GameObject.Find("Selectmanager");
     DontDestroyOnLoad(info);
     choice = info.GetComponent <CharacterSelect>();
     Instantiate(choice.character[choice.getSelected()]);
 }
예제 #25
0
    void Movement()
    {
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            transform.position += new Vector3(-1, 0, 0);
            if (isDontCollide())
            {
                updateGrid();
            }
            else
            {
                transform.position += new Vector3(1, 0, 0);
            }
        }
        else if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            transform.position += new Vector3(1, 0, 0);

            if (isDontCollide())
            {
                updateGrid();
            }
            else
            {
                transform.position += new Vector3(-1, 0, 0);
            }
        }
        else if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            transform.Rotate(0, 0, -90);
            if (isDontCollide())
            {
                updateGrid();
            }
            else
            {
                transform.Rotate(0, 0, 90);
            }
        }
        else if (Input.GetKeyDown(KeyCode.DownArrow) || Time.time - falling >= 1)
        {
            transform.position += new Vector3(0, -1, 0);
            if (isDontCollide())
            {
                updateGrid();
            }
            else
            {
                transform.position += new Vector3(0, 1, 0);
                Boundaries.deleteAll();
                AudioSource.PlayClipAtPoint(BreakSound, Camera.main.transform.position);
                FindObjectOfType <Spawn>().Next();
                enabled = false;
            }
            falling = Time.time;
        }
    }
    IEnumerator WalkDice()
    {
        yield return(new WaitForSeconds(Random.Range(2.0f, 4.0f)));

        m_walkDestination = Random.Range(Boundaries.InnerLeft(), Boundaries.InnerRight());
        m_isWalking       = true;
        m_animator.Play("SubjectWalk");
        Debug.Log(gameObject.name + " WalkDice");
    }
예제 #27
0
        /// <summary>
        /// Recursively finds all content in this node and subnodes within the given bounds.
        /// </summary>
        /// <param name="bounds">The bounds.</param>
        /// <returns>An enumerable list of content.</returns>
        public IEnumerable <TContent> FindContentIn(Bounds bounds)
        {
            if (!Boundaries.Intersects(bounds))
            {
                return(Enumerable.Empty <TContent> ());
            }

            return(Content ?? (Children != null ? Children.SelectMany(c => c.FindContentIn(bounds)) : Enumerable.Empty <TContent> ()));
        }
예제 #28
0
 public bool AreSame(Boundaries b)
 {
     return(Top == b.Top &&
            Mid == b.Mid &&
            Bottom == b.Bottom &&
            Left == b.Left &&
            Center == b.Center &&
            Right == b.Right);
 }
예제 #29
0
 public Boundaries(Boundaries original)
 {
     Top    = original.Top;
     Mid    = original.Mid;
     Bottom = original.Bottom;
     Left   = original.Left;
     Center = original.Center;
     Right  = original.Right;
 }
예제 #30
0
                public IDisposable Run(Boundaries parent)
                {
                    _buffer = new List <TSource>();

                    var sourceSubscription     = parent._source.SubscribeSafe(this);
                    var boundariesSubscription = parent._bufferBoundaries.SubscribeSafe(new BufferClosingObserver(this));

                    return(StableCompositeDisposable.Create(sourceSubscription, boundariesSubscription));
                }
 public PlayerMoveBehaviour(Transform transformToMove, Boundaries boundaries, ISpeedValue speed, ISpeedValue blockerSpeed, IInput <ProbedDirectionInput> input, IAudioGraphicBehaviourController <Vector2> controller) :
     base(input, controller)
 {
     inputModule          = input;
     this.transformToMove = transformToMove;
     this.speed           = speed;
     this.blockerSpeed    = blockerSpeed;
     this.boundaries      = boundaries;
 }
        public static IGraph CreateAdvancedGraph(this GameMap gameMap, List<Fighter> fighters, List<Enemy> enemies, Vector2 start, Vector2 end, out Vector2 startGraph, out int beginning, out int destination)
        {
            // Punkt startowy i końcowy na siatce o gęstości wyznaczonej przez VerticesDensity
            Vector2 startPoint = new Vector2((float)Math.Round(start.X / VerticesDensity)*VerticesDensity, (float)Math.Round(start.Y / VerticesDensity)*VerticesDensity);
            Vector2 endPoint = new Vector2((float)Math.Round(end.X / VerticesDensity) * VerticesDensity, (float)Math.Round(end.Y / VerticesDensity) * VerticesDensity);

            // Jak dużo punktów mieści się na jednym Tile'u
            Vector2 tileDensity = new Vector2((float)Math.Ceiling(GameMap.TileShift.X / VerticesDensity), (float)Math.Ceiling(GameMap.TileShift.Y / VerticesDensity));

            // W którym miejscu na ekranie zaczyna się i kończy graf
            startGraph = new Vector2(Math.Min(startPoint.X, endPoint.X) - VerticesDensity * tileDensity.X, Math.Min(startPoint.Y, endPoint.Y) - VerticesDensity * tileDensity.Y);
            Vector2 endGraph = new Vector2(Math.Max(startPoint.X, endPoint.X) + VerticesDensity * tileDensity.X, Math.Max(startPoint.Y, endPoint.Y) + VerticesDensity * tileDensity.Y);

            // Rozmiar grafu
            Point size = new Point((int)((endGraph.X - startGraph.X) / VerticesDensity + 1), (int)((endGraph.Y - startGraph.Y) / VerticesDensity + 1));

            // ustalenie punktow poczatkowego i docelowego, na potrzeby wyszukiwania sciezek
            beginning = (int)((startPoint.X - startGraph.X) / VerticesDensity) + (int)((startPoint.Y - startGraph.Y) / VerticesDensity) * (size.X - 1);
            destination = (int)((endGraph.X - endPoint.X) / VerticesDensity) + (int)((endGraph.Y - endPoint.Y) / VerticesDensity) * (size.X - 1);

            // Tworzenie grafu o rozmiarze prostokata
            IGraph g = new AdjacencyMatrixGraph(false, (int)(size.X*size.Y));

            #region Boundaries
            // Utworzenie granic do sprawdzania czy da się przejść

            Boundaries[] b = new Boundaries[8];

            List<Vector2> points = new List<Vector2>();

            // Lewy górny
            points.Add(new Vector2(-Unit.BoundariesSize, 0));
            points.Add(new Vector2(0,Unit.BoundariesSize));
            points.Add(new Vector2(Unit.BoundariesSize, 0));
            points.Add(new Vector2(Unit.BoundariesSize - VerticesDensity, -VerticesDensity));
            points.Add(new Vector2(-VerticesDensity, -Unit.BoundariesSize - VerticesDensity));
            points.Add(new Vector2(-Unit.BoundariesSize - VerticesDensity, -VerticesDensity));

            b[0] = Boundaries.CreateFromPoints(points);

            // Górny
            points.Clear();
            points.Add(new Vector2(-Unit.BoundariesSize, 0));
            points.Add(new Vector2(0, Unit.BoundariesSize));
            points.Add(new Vector2(Unit.BoundariesSize, 0));
            points.Add(new Vector2(Unit.BoundariesSize, -VerticesDensity));
            points.Add(new Vector2(0, -Unit.BoundariesSize - VerticesDensity));
            points.Add(new Vector2(-Unit.BoundariesSize, -VerticesDensity));

            b[1] = Boundaries.CreateFromPoints(points);

            // Prawy górny
            points.Clear();
            points.Add(new Vector2(-Unit.BoundariesSize, 0));
            points.Add(new Vector2(0, Unit.BoundariesSize));
            points.Add(new Vector2(Unit.BoundariesSize, 0));
            points.Add(new Vector2(VerticesDensity + Unit.BoundariesSize, -VerticesDensity));
            points.Add(new Vector2(VerticesDensity, -Unit.BoundariesSize - VerticesDensity));
            points.Add(new Vector2(VerticesDensity - Unit.BoundariesSize, -VerticesDensity));

            b[2] = Boundaries.CreateFromPoints(points);

            // Prawy
            points.Clear();
            points.Add(new Vector2(0, Unit.BoundariesSize));
            points.Add(new Vector2(-Unit.BoundariesSize, 0));
            points.Add(new Vector2(0, -Unit.BoundariesSize));
            points.Add(new Vector2(VerticesDensity, -Unit.BoundariesSize));
            points.Add(new Vector2(VerticesDensity + Unit.BoundariesSize, 0));
            points.Add(new Vector2(VerticesDensity, Unit.BoundariesSize));
            b[3] = Boundaries.CreateFromPoints(points);

            // Prawy dolny
            points.Clear();
            points.Add(new Vector2(-Unit.BoundariesSize, 0));
            points.Add(new Vector2(0, -Unit.BoundariesSize));
            points.Add(new Vector2(Unit.BoundariesSize, 0));
            points.Add(new Vector2(VerticesDensity + Unit.BoundariesSize, VerticesDensity));
            points.Add(new Vector2(VerticesDensity, VerticesDensity + Unit.BoundariesSize));
            points.Add(new Vector2(VerticesDensity - Unit.BoundariesSize, VerticesDensity));

            b[4] = Boundaries.CreateFromPoints(points);

            // Dolny
            points.Clear();
            points.Add(new Vector2(-Unit.BoundariesSize, 0));
            points.Add(new Vector2(0, -Unit.BoundariesSize));
            points.Add(new Vector2(Unit.BoundariesSize, 0));
            points.Add(new Vector2(Unit.BoundariesSize, VerticesDensity));
            points.Add(new Vector2(0, VerticesDensity + Unit.BoundariesSize));
            points.Add(new Vector2(-Unit.BoundariesSize, VerticesDensity));

            b[5] = Boundaries.CreateFromPoints(points);

            // Lewy dolny
            points.Clear();
            points.Add(new Vector2(-Unit.BoundariesSize, 0));
            points.Add(new Vector2(0, -Unit.BoundariesSize));
            points.Add(new Vector2(Unit.BoundariesSize, 0));
            points.Add(new Vector2(-VerticesDensity + Unit.BoundariesSize, VerticesDensity));
            points.Add(new Vector2(-VerticesDensity, VerticesDensity + Unit.BoundariesSize));
            points.Add(new Vector2(-VerticesDensity - Unit.BoundariesSize, VerticesDensity));

            b[6] = Boundaries.CreateFromPoints(points);

            // Lewy
            points.Clear();
            points.Add(new Vector2(0, Unit.BoundariesSize));
            points.Add(new Vector2(Unit.BoundariesSize, 0));
            points.Add(new Vector2(0, -Unit.BoundariesSize));
            points.Add(new Vector2(-VerticesDensity, -Unit.BoundariesSize));
            points.Add(new Vector2(-VerticesDensity - Unit.BoundariesSize, 0));
            points.Add(new Vector2(-VerticesDensity, Unit.BoundariesSize));

            b[7] = Boundaries.CreateFromPoints(points);
            #endregion

            // Tworzenie grafu, TODO: do poprawki ta pętla
            for (int i = 1; i < size.X - 1; i+=2)
            {
                for (int j = 1; j < size.Y - 1; j+=2)
                {
                    g.UpdateGraph(i, j, i - 1, j - 1, startGraph, size, VerticesDensity, gameMap, b[0]);
                    g.UpdateGraph(i, j, i, j - 1, startGraph, size, VerticesDensity, gameMap, b[1]);
                    g.UpdateGraph(i, j, i + 1, j - 1, startGraph, size, VerticesDensity, gameMap, b[2]);
                    g.UpdateGraph(i, j, i + 1, j, startGraph, size, VerticesDensity, gameMap, b[3]);
                    g.UpdateGraph(i, j, i + 1, j + 1, startGraph, size, VerticesDensity, gameMap, b[4]);
                    g.UpdateGraph(i, j, i, j + 1, startGraph, size, VerticesDensity, gameMap, b[5]);
                    g.UpdateGraph(i, j, i - 1, j + 1, startGraph, size, VerticesDensity, gameMap, b[6]);
                    g.UpdateGraph(i, j, i - 1, j, startGraph, size, VerticesDensity, gameMap, b[7]);

                    #region komentarz
                    /*
                    Vector2 mapPosition = new Vector2(startGraph.X + i * VerticesDensity, startGraph.Y + j * VerticesDensity);
                    bool intersects = false;
                    int x = startGraph.GetMapPosition(gameMap).X;
                    int y = startGraph.GetMapPosition(gameMap).Y;

                    foreach (var mo in gameMap[x + i - 1, y + j - 1].mapObjects)
                        if ((b[0] + mapPosition).Intersects(mo.boundaries)) intersects = true;
                    foreach (var mo in gameMap[x + i , y + j].mapObjects)
                        if ((b[0] + mapPosition).Intersects(mo.boundaries)) intersects = true;
                    if (!intersects)
                        g.AddEdge(i - 1 + (j - 1) * (size.X - 1), i + j * (size.X - 1));
                    else
                        g.DelEdge(i - 1 + (j - 1) * (size.X - 1), i + j * (size.X - 1));

                    intersects = false;
                    foreach (var mo in gameMap[x + i, y + j - 1].mapObjects)
                        if ((b[1] + mapPosition).Intersects(mo.boundaries)) intersects = true;
                    foreach (var mo in gameMap[x + i, y + j].mapObjects)
                        if ((b[1] + mapPosition).Intersects(mo.boundaries)) intersects = true;
                    if (!intersects)
                        g.AddEdge(i + (j - 1) * (size.X - 1), i + j * (size.X - 1));

                    intersects = false;
                    foreach (var mo in gameMap[x + i + 1, y + j - 1].mapObjects)
                        if ((b[2] + mapPosition).Intersects(mo.boundaries)) intersects = true;
                    foreach (var mo in gameMap[x + i, y + j].mapObjects)
                        if ((b[2] + mapPosition).Intersects(mo.boundaries)) intersects = true;
                    if (!intersects)
                        g.AddEdge(i + 1 + (j - 1) * (size.X - 1), i + j * (size.X - 1));

                    intersects = false;
                    foreach (var mo in gameMap[x + i + 1, y + j].mapObjects)
                        if ((b[3] + mapPosition).Intersects(mo.boundaries)) intersects = true;
                    foreach (var mo in gameMap[x + i, y + j].mapObjects)
                        if ((b[3] + mapPosition).Intersects(mo.boundaries)) intersects = true;
                    if (!intersects)
                        g.AddEdge(i + 1 + j * (size.X - 1), i + j * (size.X - 1));

                    intersects = false;
                    foreach (var mo in gameMap[x + i + 1, y + j + 1].mapObjects)
                        if ((b[4] + mapPosition).Intersects(mo.boundaries)) intersects = true;
                    foreach (var mo in gameMap[x + i, y + j].mapObjects)
                        if ((b[4] + mapPosition).Intersects(mo.boundaries)) intersects = true;
                    if (!intersects)
                        g.AddEdge(i + 1 + (j + 1) * (size.X - 1), i + j * (size.X - 1));

                    intersects = false;
                    foreach (var mo in gameMap[x + i, y + j + 1].mapObjects)
                        if ((b[5] + mapPosition).Intersects(mo.boundaries)) intersects = true;
                    foreach (var mo in gameMap[x + i, y + j].mapObjects)
                        if ((b[5] + mapPosition).Intersects(mo.boundaries)) intersects = true;
                    if (!intersects)
                        g.AddEdge(i + (j + 1) * (size.X - 1), i + j * (size.X - 1));

                    intersects = false;
                    foreach (var mo in gameMap[x + i - 1, y + j + 1].mapObjects)
                        if ((b[6] + mapPosition).Intersects(mo.boundaries)) intersects = true;
                    foreach (var mo in gameMap[x + i, y + j].mapObjects)
                        if ((b[6] + mapPosition).Intersects(mo.boundaries)) intersects = true;
                    if (!intersects)
                        g.AddEdge(i - 1 + (j + 1) * (size.X - 1), i + j * (size.X - 1));

                    intersects = false;
                    foreach (var mo in gameMap[x + i - 1, y + j].mapObjects)
                        if ((b[7] + mapPosition).Intersects(mo.boundaries)) intersects = true;
                    foreach (var mo in gameMap[x + i, y + j].mapObjects)
                        if ((b[7] + mapPosition).Intersects(mo.boundaries)) intersects = true;
                    if (!intersects)
                        g.AddEdge(i - 1 + j * (size.X - 1), i + j * (size.X - 1));
             */
                    #endregion
                }
            }

            return g;
        }
        /// <summary>
        /// Aktualizacja grafu - dodawanie krawedzi
        /// Metoda rozszerzająca
        /// </summary>
        /// <param name="g">graf</param>
        /// <param name="x1">Punkt x1 (startowy)</param>
        /// <param name="y1">Punkt y1 (startowy)</param>
        /// <param name="x2">Punkt x2</param>
        /// <param name="y2">Punkt y2</param>
        /// <param name="startGraph">Gdzie na mapie zaczyna się graf</param>
        /// <param name="size">Rozmiar grafu (w ilości punktów oddalonych od siebie o VerticesDensity)</param>
        /// <param name="VerticesDensity">Oddalenie punktów od siebie nawzajem</param>
        /// <param name="gameMap">mapa</param>
        /// <param name="b">ograniczenie dla tych dwóch konkretnych punktów</param>
        private static void UpdateGraph(this IGraph g, int x1, int y1, int x2, int y2, Vector2 startGraph, Point size, float VerticesDensity, GameMap gameMap, Boundaries b)
        {
            Vector2 mapPosition1 = new Vector2(startGraph.X + x1 * VerticesDensity, startGraph.Y + y1 * VerticesDensity);
            Vector2 mapPosition2 = new Vector2(startGraph.X + x2 * VerticesDensity, startGraph.Y + y2 * VerticesDensity);
            Point mapPoint1 = mapPosition1.GetMapPosition(gameMap);
            Point mapPoint2 = mapPosition2.GetMapPosition(gameMap);
            Boundaries shift = b.Clone();
            shift += mapPosition1;
            bool intersects = false;

            foreach (MapObject mo in gameMap[mapPoint1.X, mapPoint1.Y].mapObjects)
                if (shift.Intersects(mo.boundaries)) intersects = true;
            foreach (MapObject mo in gameMap[mapPoint2.X, mapPoint2.Y].mapObjects)
                if (shift.Intersects(mo.boundaries)) intersects = true;
            if (!intersects)
                g.AddEdge(x1 + y1 * (size.X - 1), x2 + y2 * (size.X - 1));
            else
                g.DelEdge(x1 + y1 * (size.X - 1), x2 + y2 * (size.X - 1));
        }
예제 #34
0
        public Boundaries CheckBoundaries(int[] pixels)
        {
            // check left
            double boundayFactor = 0.1; //10% of the image width/height
            limit = GetIntensity(pixels);
            Boundaries b = new Boundaries();

            b.Bottom = CheckRight(pixels, boundayFactor);
            b.Top = CheckLeft(pixels, boundayFactor);
            b.Right = CheckTop(pixels, boundayFactor);
            b.Left = CheckBottom(pixels, boundayFactor);
            return b;
        }
예제 #35
0
 void Start()
 {
     bounds = GameObject.FindWithTag("Ground").GetComponent<Boundaries>();
 }