Esempio n. 1
0
	public void Start()
	{
		bigDimensions = bigSize.GetRectPoint();
		smallDimensions = smallSize.GetRectPoint();

		Reset();
	}
Esempio n. 2
0
		private void CreateBlast( RectPoint blastOrigin )
		{
			foreach ( RectPoint point in grid.GetNeighborHood( blastOrigin, BLAST_RADIUS )) 
			{
				if ( grid[point].Color != Color.black )
				{
					GameObject blast = (GameObject)Instantiate ( blastPrefab );
					blast.transform.parent = grid[point].transform;
					blast.transform.localPosition = Vector3.zero;
					blast.transform.localScale = Vector3.one * 100.0f;

					if ( map[ player.transform.localPosition ] == point )
					{
						Destroy (player.gameObject);
					}
					List<GameObject> deadEnemies = new List<GameObject>();
					foreach( GameObject enemy in enemies )
					{
						if (map[ enemy.transform.localPosition ] == point)
						{
							deadEnemies.Add (enemy);
						}
					}

					foreach( GameObject enemy in deadEnemies)
					{
						enemies.Remove(enemy);
						Destroy(enemy.gameObject);
					}
					StartCoroutine( Blast(blast) );
				}
			}
			   
		}
Esempio n. 3
0
 //All tile points are relative to CurrentPosition
 public void AddTile(RectPoint tilePoint, SpriteCell tileObject)
 {
     tileObjects[tilePoint] = tileObject;
 }
Esempio n. 4
0
 /**
  *      @version1_8
  */
 public InspectableVectorPoint(RectPoint point)
 {
     x = point.X;
     y = point.Y;
 }
Esempio n. 5
0
	private void SelectFirstPoint(RectPoint point)
	{
		cellSelectionState = 1;

		point0 = point;
		pathRoot.transform.DestroyChildren();

		var bigPathPoint = grid.GetBigPoint(point);
		var smallPathPoint = grid.GetSmallPoint(point);
		var pathMarker = Instantiate(pathPrefab);
		pathMarker.name = "";
		pathMarker.Color = Color.black;

		pathMarker.transform.parent = pathRoot.transform;
		pathMarker.transform.localScale = Vector3.one * 4;
		pathMarker.transform.localPosition = bigMap[bigPathPoint] + smallMap[smallPathPoint] - Vector3.forward;
	}
			//All tile points are relative to CurrentPosition
			public void AddTile(RectPoint tilePoint, SpriteCell tileObject)
			{
				tileObjects[tilePoint] = tileObject;
			}
		private Block MakeBlock(int id, BlockType type, RectPoint initialPosition)
		{
			var block = new Block(id);

			if (type == BlockType.Horizontal)
			{
				block.AddTile(RectPoint.Zero, MakeTile());
				block.AddTile(RectPoint.East, MakeTile());
			}
			else
			{
				block.AddTile(RectPoint.Zero, MakeTile());
				block.AddTile(RectPoint.North, MakeTile());
			}

			if (CanOccupy(block, initialPosition))
			{
				foreach (SpriteCell tile in block.TileObjects)
				{
					tile.Color = colors[id];
					tile.name = "" + id;
				}

				PlaceTile(block, initialPosition);
				block.UpdateTilePositions(map);
			}
			else
			{
				Debug.LogError("Invalid placement. Making block empty");

				foreach (SpriteCell tile in block.TileObjects)
				{
					Destroy(tile.gameObject);
				}

				block.Clear();
			}

			return block;
		}
		private SpriteCell MakeCell(RectPoint point)
		{
			var cell = Instantiate(cellPrefab);
			cell.transform.parent = uiRoot.transform;
			cell.transform.localScale = Vector3.one;
			cell.transform.localPosition = map[point] + Vector3.forward;
			cell.Color = ExampleUtils.ColorFromInt(40, 40, 40);
			cell.HighlightOn = false;
			cell.name = "";
			return cell;
		}
Esempio n. 9
0
 /**
  *      This is a norm defined on the point, such that `p1.Difference(p2).Abs()` is equal to
  *      `p1.DistanceFrom(p2)`.
  */
 public RectPoint Translate(RectPoint translation)
 {
     return(new RectPoint(x + translation.X, y + translation.Y));
 }
Esempio n. 10
0
        public bool Equals(RectPoint other)
        {
            bool areEqual = (x == other.X) && (y == other.Y);

            return(areEqual);
        }
Esempio n. 11
0
 /**
  *      The lattice distance from this point to the other.
  */
 public int DistanceFrom(RectPoint other)
 {
     return(Subtract(other).Magnitude());
 }
    private List <RectPoint> GetLinePoints(RectPoint p1, RectPoint p2)
    {
        List <RectPoint> linePath = new List <RectPoint>();
        int x = p1.X;
        int y = p1.Y;

        int  dx = p2.X - x;
        int  dy = p2.Y - y;
        bool isVerticalFunction = Math.Abs(dx) < Math.Abs(dy);

        int move;
        int gradientMove;
        int biggerAxis;
        int smallerAxis;

        if (isVerticalFunction)
        {
            biggerAxis   = Math.Abs(dy);
            smallerAxis  = Math.Abs(dx);
            move         = Math.Sign(dy);
            gradientMove = Math.Sign(dx);
        } // end if
        else
        {
            biggerAxis   = Math.Abs(dx);
            smallerAxis  = Math.Abs(dy);
            move         = Math.Sign(dx);
            gradientMove = Math.Sign(dy);
        } // end else

        int totalGradient = biggerAxis / 2;

        for (int i = 0; i < biggerAxis; i++)
        {
            RectPoint point = new RectPoint(x, y);
            linePath.Add(point);
            if (isVerticalFunction)
            {
                y += move;
            }
            else
            {
                x += move;
            }

            totalGradient += smallerAxis;
            if (totalGradient >= biggerAxis)
            {
                if (isVerticalFunction)
                {
                    x += gradientMove;
                }
                else
                {
                    y += gradientMove;
                }
                totalGradient -= biggerAxis;
            }
        } // end for
        return(linePath);
    }
    private List <RectPoint> GetConnectionTiles(RectPoint startTile, RectPoint endTile)
    {
        List <RectPoint> linearPath = GetLinePoints(startTile, endTile);

        return(GetCompletePathTiles(linearPath));
    }
Esempio n. 14
0
 internal static Point GetPoint(this Rect rect, RectPoint rectPoint)
 {
     return(RectUtils.GetPoint(rect, rectPoint));
 }
		/**
			@version1_8
		*/
		public InspectableVectorPoint(RectPoint point)
		{
			x = point.X;
			y = point.Y;
		}
		private void BuildPuzzle()
		{
			const int size = 5;

			tileGrid = RectGrid<SpriteCell>.Rectangle(size, size);
			blocksGrid = (RectGrid<Block>) tileGrid.CloneStructure<Block>();

			map = new RectMap(new Vector2(152, 152))
				.AnchorCellMiddleCenter()
				.WithWindow(ExampleUtils.ScreenRect)
				.AlignMiddleCenter(tileGrid)
				.To3DXY();

			foreach (RectPoint point in tileGrid)
			{
				var cell = MakeCell(point);

				tileGrid[point] = cell;
				blocksGrid[point] = null;
			}

			blocks = new List<Block>();

			AddFirstBlock();
			AddOtherBlocks();

			winPosition = new RectPoint(4, 2);
		}
Esempio n. 17
0
 /**
  *      Subtracts the other point from this point, and returns the result.
  */
 public RectPoint Subtract(RectPoint other)
 {
     return(new RectPoint(x - other.X, y - other.Y));
 }
		private bool CanOccupy(Block block, RectPoint gridPoint)
		{
			foreach (RectPoint tilePoint in block.TilePoints)
			{
				var absoluteTilePoint = gridPoint + tilePoint;

				if (!tileGrid.Contains(absoluteTilePoint))
				{
					return false;
				}

				if ((blocksGrid[absoluteTilePoint] != null) && (blocksGrid[absoluteTilePoint] != block))
				{
					return false;
				}
			}

			return true;
		}
Esempio n. 19
0
 public RectPoint MoveBy(RectPoint translation)
 {
     return(Translate(translation));
 }
		private void PlaceTile(Block block, RectPoint gridPoint)
		{
			foreach (RectPoint tilePoint in block.TilePoints)
			{
				tileGrid[gridPoint + tilePoint].gameObject.SetActive(false);
				blocksGrid[gridPoint + tilePoint] = block;
			}

			block.CurrentPosition = gridPoint;
		}
Esempio n. 21
0
 public RectPoint MoveBackBy(RectPoint translation)
 {
     return(Translate(translation.Negate()));
 }
Esempio n. 22
0
	private void SelectLastPoint(RectPoint point)
	{
		cellSelectionState = 0;
		point1 = point;

		var path = Algorithms.AStar(grid, point0, point1, (p, q) => p.DistanceFrom(q), cell => !cell.HighlightOn, (p, q) => p.DistanceFrom(q));

		foreach (var pathPoint in path.ButFirst())
		{
			var bigPathPoint = grid.GetBigPoint(pathPoint);
			var smallPathPoint = grid.GetSmallPoint(pathPoint);
			var pathMarker = Instantiate(pathPrefab);

			pathMarker.name = ("");
			pathMarker.Color = Color.black;

			pathMarker.transform.parent = pathRoot.transform;
			pathMarker.transform.localScale = Vector3.one*4;
			pathMarker.transform.localPosition = bigMap[bigPathPoint] + smallMap[smallPathPoint] - Vector3.forward;
		}
	}
Esempio n. 23
0
 /**
  *      @version1_7
  */
 public int Dot(RectPoint other)
 {
     return(x * other.X + y * other.Y);
 }
Esempio n. 24
0
 /**
  *      @version1_7
  */
 public int PerpDot(RectPoint other)
 {
     return(x * other.Y - y * other.x);
 }
Esempio n. 25
0
 private HostAnchor(RectPoint position)
 {
     _position = position;
 }