private void RotateTile(TileDirection direction) { var rotationVector = Vector3.zero; switch (direction) { case TileDirection.Up: rotationVector.y = 270f; break; case TileDirection.Down: rotationVector.y = 90f; break; case TileDirection.Left: rotationVector.y = 180f; break; case TileDirection.Right: rotationVector.y = 0f; break; default: break; } transform.localRotation = Quaternion.Euler(rotationVector); }
public HexTileCoord AddDirection(TileDirection dir) { switch (dir) { case TileDirection.Right: return(this + Right); case TileDirection.UpRight: return(this + UpRight); case TileDirection.UpLeft: return(this + UpLeft); case TileDirection.Left: return(this + Left); case TileDirection.DownLeft: return(this + DownLeft); case TileDirection.DownRight: return(this + DownRight); default: throw new InvalidOperationException(); } }
public ExpressConveyorBelt(Board board, Tile baseTile, TileDirection direction, TurnDirection turn, int x, int y) : base(board, baseTile, x, y) { Direction = direction; Turn = turn; }
public DirectionalCircle(Vector2 ptCenter, TileDirection tileDir, bool bClockwise) { this.center = ptCenter; this.clockwise = bClockwise; if (this.clockwise) { // startTheta = this.clockwise ? Mathf.PI : 0.0f; startTheta = -Mathf.PI; startTheta -= (Mathf.PI / 4.0f) * (int)tileDir; // if(startTheta > Mathf.PI * 2.0f) // { // startTheta -= Mathf.PI * 2.0f; // } // if(startTheta > Mathf.PI * 2.0f) // { // startTheta -= Mathf.PI * 2.0f; // } } else { startTheta = 0; startTheta += (Mathf.PI / 4.0f) * (int)tileDir; // if(startTheta < -Mathf.PI * 2.0f) // { // startTheta += Mathf.PI * 2.0f; // } } if (startTheta > Mathf.PI) { startTheta -= Mathf.PI * 2.0f; } if (startTheta < -Mathf.PI) { startTheta += Mathf.PI * 2.0f; } if (MyMath.IsNearZero(startTheta)) { startTheta = 0.0f; } // if(startTheta > Mathf.PI) // startTheta -= Mathf.PI; //startTheta = RestrictAngle(startTheta); // startTheta = this.clockwise ? Mathf.PI : 0.0f; // startTheta += (Mathf.PI/4.0f) * (int)tileDir; // // if(startTheta > Mathf.PI * 2.0f) // { // startTheta -= Mathf.PI * 2.0f; // } }
public bool RaycastSquare(Vector2 origin, float size, TileDirection direction, float len, out TileHitInfo hitInfo) { size *= 0.95f; hitInfo = new TileHitInfo(); int iterations = Mathf.Max(Mathf.CeilToInt(size / TILE_SIZE), 1); Vector2 from = origin - GetTanget(origin, direction) * (size * 0.5f); Vector2 step = GetTanget(origin, direction) * (size / iterations); bool hitAny = false; TileHitInfo localHitInfo; for (int i = 0; i <= iterations; i++) { if (Raycast(from, direction, len, out localHitInfo)) { if (!hitAny) { hitAny = true; hitInfo = localHitInfo; } else if (localHitInfo.hitDistance < hitInfo.hitDistance) { hitInfo = localHitInfo; } } from += step; } return(hitAny); }
/// <summary> /// returns all map tiles of a ring around center in order specified by parameters (startDirection, clockwise) /// </summary> public List <Vector3Int> Ring(Vector3Int center, int radius, TileDirection startDirection, bool clockwise) { List <Vector3Int> positions = HexGrid.GetTiles.Ring(center, radius, startDirection, clockwise); positions = GetValidTileCoordinates(positions); return(positions); }
void buildBounceTile(Vector3 pos, TileDirection dir) { GameObject go = (GameObject)Instantiate(bounceTile, pos, Quaternion.identity); go.GetComponent <BounceTile>().setDirection(dir); bounceTiles.Add(go); }
static void ConnectNearTilePushedItems( Dictionary <Vector2, GameObject> tiles, Vector2 nearPosition, TileDirection direction, PushedItemsEventNode.EventType moveEvent, List <PlayerBase> playerBases ) { var nearPlayerBase = playerBases.FirstOrDefault(playerBase => playerBase.Contains(nearPosition)); if (nearPlayerBase != null) { var action = new UnityAction <PushedItemsEventNode.Data>(nearPlayerBase.Player.PullItems); UnityEventTools.AddPersistentListener(moveEvent, action); } else if (tiles.ContainsKey(nearPosition)) { var nearTile = tiles[nearPosition]; var nearDirection = nearTile.GetComponent <TileDirection>(); var action = new UnityAction <PushedItemsEventNode.Data>(nearDirection.PullItems); UnityEventTools.AddPersistentListener(moveEvent, action); } }
public Tile GetNeighbourInDirection(TileDirection direction) { switch (direction) { case TileDirection.Left: return(this.Left); case TileDirection.Right: return(this.Right); case TileDirection.TopLeft: return(this.TopLeft); case TileDirection.TopRight: return(this.TopRight); case TileDirection.BottomLeft: return(this.BottomLeft); case TileDirection.BottomRight: return(this.BottomRight); default: return(this); } }
/// <summary> /// Initializes a new instance of the <see cref="Animation"/> class. /// </summary> /// <param name="fps"> The frames per second for the animation. </param> /// <param name="animatedObject"> The animated game object. </param> /// <param name="frameCount"> The amount of frames. </param> /// <param name="firstFrame"> A rectangle defining the size and position for the first frame. </param> /// <param name="tileDirection"> The animations tile direction on the sprite sheet. </param> public Animation(int fps, GameObject animatedObject, int frameCount, Rectangle firstFrame, TileDirection tileDirection) { // Assign class members this.animatedObject = animatedObject; // Calculate the time duration between each frame. this.frameDeltaTime = 1f / fps; // We changed frame, so next frame will be in 'frame delta' seconds this.lastFrameChange = DateTime.Now; // Set frame sources this.frameSources = new Rectangle[frameCount]; for (int i = 0; i < frameCount; i++) { switch (tileDirection) { case TileDirection.Down: this.frameSources[i] = new Rectangle(firstFrame.X, firstFrame.Y + (firstFrame.Height * i), firstFrame.Width, firstFrame.Height); break; case TileDirection.Right: this.frameSources[i] = new Rectangle(firstFrame.X + (firstFrame.Width * i), firstFrame.Y, firstFrame.Width, firstFrame.Height); break; } } }
public BuildState(Unit unit, MapTile targetTile, BuildingType buildingType, TileDirection direction) { this.unit = unit; this.targetTile = targetTile; this.buildingType = buildingType; this.direction = direction; }
public TileMatch(TileDirection direction, Tile[] matchingTileArray, Vector3 position) { Direction = direction; MatchingTileArray = matchingTileArray; MatchSize = matchingTileArray.Length; Position = position; }
public void Set(int X, int Y, int Index, int BlendLayer, ushort Type, int WeatherIntensity) { Tile Tile = new Tile((Index % MaxX) * TileSize, (Index / MaxX) * TileSize, TileSize, Type, WeatherIntensity); Tile.BlendLayer = BlendLayer; Tiles[X, Y] = Tile; for (int YAdd = -1; YAdd < 2; YAdd++) { for (int XAdd = -1; XAdd < 2; XAdd++) { if (YAdd == 0 && XAdd == 0) { continue; } int XNew = X + XAdd; int YNew = Y + YAdd; if (XNew >= 0 && XNew < Width && YNew >= 0 && YNew < Height) { TileDirection Direction = PointToTileDirection(new IntLocation(XAdd + 1, YAdd + 1)); Tile.CompareTo(Tiles[XNew, YNew], (int)Direction, (int)OppositeTileDirection(Direction)); } } } }
public void GoTo(Vector2Int dest) { List <Vector2Int> path = PathFinding.AStar.FindPath(levelInfo.tiles, m_characterMovement.coordinate, dest); if (path == null) { return; } m_path = path; m_pathIndex = 0; // skip the first if already there if (m_path[m_pathIndex] == m_characterMovement.coordinate) { m_pathIndex++; } m_nextDir = TileDirectionEnum.Get_TD(m_characterMovement.coordinate, m_path[m_pathIndex]); destination = dest; if (m_characterMovement.coordinate == destination) { OnArrive?.Invoke(destination); } }
public Tile FindTileInDirection(Vector2Int position, TileDirection direction) { if (!TileExistsInDirection(position, direction)) { return(null); } switch (direction) { case TileDirection.Left: { return(table.TileMatrix[position.x - 1, position.y]); } case TileDirection.Right: { return(table.TileMatrix[position.x + 1, position.y]); } case TileDirection.Up: { return(table.TileMatrix[position.x, position.y - 1]); } case TileDirection.Down: { return(table.TileMatrix[position.x, position.y + 1]); } default: { throw new UnityException(INVALID_DIRECTION_MESSAGE); } } }
private void Awake() { m_Mover = GetComponent <PlatformerMover>(); m_TileDirection = GetComponent <TileDirection>(); BeginRamping(); }
public Vector3 offsetPointInDirection(Vector3 point, float offset, TileDirection dir) { switch (dir) { case TileDirection.N: return(new Vector3(point.x, point.y, point.z + offset)); case TileDirection.NE: return(new Vector3(point.x + offset, point.y, point.z + offset)); case TileDirection.E: return(new Vector3(point.x + offset, point.y, point.z)); case TileDirection.SE: return(new Vector3(point.x + offset, point.y, point.z - offset)); case TileDirection.S: return(new Vector3(point.x, point.y, point.z - offset)); case TileDirection.SW: return(new Vector3(point.x - offset, point.y, point.z - offset)); case TileDirection.W: return(new Vector3(point.x - offset, point.y, point.z)); case TileDirection.NW: return(new Vector3(point.x - offset, point.y, point.z + offset)); default: return(point); } }
// Update is called once per frame void UpdateCurrentDirection() { if (currentDirection == TileDirection.Empty) { return; // not allowed to change direction for empty tiles } switch (currentDirection) { case (TileDirection.Up): currentDirection = TileDirection.Down; break; case (TileDirection.Down): currentDirection = TileDirection.Left; break; case (TileDirection.Left): currentDirection = TileDirection.Right; break; case (TileDirection.Right): currentDirection = TileDirection.Up; break; } }
public Vector3 getPseudoNeighbourCenterPosition(int idx, TileDirection dir) { float step = tileSize; Vector3 center = indexToPosition(idx); return(offsetPointInDirection(center, step, dir)); }
public void ChangeNextTile(TileDirection direction) { tileDirection = direction; switch (direction) { case TileDirection.Up: nextTile = Up; break; case TileDirection.Down: nextTile = Down; break; case TileDirection.Left: nextTile = Left; break; case TileDirection.Right: nextTile = Right; break; default: break; } RotateTile(direction); }
private TileMatch FindMatchInRow(int row, TileDirection direction) { int consecutive = 0; bool match = false; _tileList.Clear(); for (int i = 1; i < table.Rows; i++) { _tileA = direction == TileDirection.Horizontal ? table.TileMatrix[i - 1, row] : table.TileMatrix[row, i - 1]; _tileB = direction == TileDirection.Horizontal ? table.TileMatrix[i, row] : table.TileMatrix[row, i]; if (_tileA.Equals(_tileB)) { if (consecutive == 0) { _tileList.Add(_tileA); consecutive += 2; } else { consecutive++; } _tileList.Add(_tileB); } else { if (match) { break; } else { consecutive = 0; _tileList.Clear(); } } if (consecutive >= 3 || match == true) { match = true; } } if (match) { // position of the match is position of the middle cleared Tile int middleIndex = Mathf.CeilToInt(_tileList.Count / 2); Vector3 position = _tileList[middleIndex].transform.position; return(new TileMatch(direction, _tileList.ToArray(), position)); } else { return(null); } }
public void CycleNextTile() { currentTileIndex++; currentTileIndex %= 4; tileDirection = (TileDirection)currentTileIndex; ChangeNextTile(tileDirection); }
/// <summary> /// 선택한 타일에 인접한 8개의 타일에 대해 탐색한다. /// </summary> /// <param name="cur"> 현재 노드 </param> private void CheckNearNode(Node curNode) { // 시계방향으로 돈다. for (int i = 0; i < directions.Length; i++) { // 방향에 따른 인접타일의 좌표 TileDirection dir = directions[i]; int x = curNode.X + dir.X; int y = curNode.Y + dir.Y; // 맵의 크기를 벗어나는지 확인 if (x < 0 || y < 0 || x >= MapW || y >= MapH) { continue; } // 타일좌표에 해당하는 노드를 가져온다. Node node = MapInfoList[(MapH * x) + y]; // 장애물이면 무시한다. if (node.TileType == NodeType.Obstacle) { continue; } // 닫힘목록에 있다면 무시한다. if (_closeList.Contains(node)) { continue; } // 만약, 열림목록에 있지 않다면 if (!_openList.Contains(node)) { // F, G, H 값 계산 PathScoring(curNode, node); // 부모를 현재 타일로 설정 node.ParentNode = curNode; // 열림목록에 추가 _openList.Add(node); } else // 열림목록에 있다면 { // G비용을 이용하여 이 사각형이 더 나은가 알아보고 //if (node.G < (curNode.G + dir.W)) //{ // Debug.LogFormat("Node : ({0},{1}) === CurNode({2},{3}), G({4} / {5})", node.X, node.Y, curNode.X, curNode.Y, node.G, (curNode.G + dir.W)); //} if (node.G > (curNode.G + dir.W)) { PathScoring(curNode, node); node.ParentNode = curNode; } } } }
public MapTile GetNeighbourTile(MapTile t, TileDirection tileDirection) { // find index for t int x = t.Dx; int y = (t.Dy + (t.Dx + 1) % 2) / 2; Debug.Assert(tiles[x, y] == t); return(GetNeighbourTile(x, y, tileDirection)); }
private void Awake() { m_Transform = transform; m_TileDirection = GetComponent <TileDirection>(); GlobalData.PlayModePreToggle += OnPlayModePreToggle; GlobalData.PlayModeToggled += OnPlayModeToggled; GlobalData.HeroReturned += OnHeroReturned; }
/// <summary> /// Gets the adjacent tile of 'tile' in the given direction. /// </summary> /// <returns>The adjacent tile, or null if out of bounds.</returns> /// <param name="tile">Tile.</param> /// <param name="direction">Direction.</param> public Tile GetAdjacent(Tile tile, TileDirection direction) { int dx = 0; int dy = 0; switch (direction) { case TileDirection.North: dx = 0; dy = 1; break; case TileDirection.NorthEast: dx = 1; dy = 1; break; case TileDirection.East: dx = 1; dy = 0; break; case TileDirection.SouthEast: dx = 1; dy = -1; break; case TileDirection.South: dx = 0; dy = -1; break; case TileDirection.SouthWest: dx = -1; dy = -1; break; case TileDirection.West: dx = -1; dy = 0; break; case TileDirection.NorthWest: dx = -1; dy = 1; break; } int i = tile.posX + dx; int j = tile.posY + dy; if (i > 0 && i < width && j > 0 && j < height) { return(GetTile(i, j)); } return(null); }
public void TileAdd(int tileNum, TileDirection tileOutwardOrientation, UInt32 chance) { Array.Resize(ref Tiles, TileCount + 1); Tiles[TileCount].TextureNum = tileNum; Tiles[TileCount].Direction = tileOutwardOrientation; Tiles[TileCount].Chance = chance; TileCount++; TileChanceTotal += Convert.ToInt32(chance); }
public override TileDirection[] HasWalls() { var old = base.HasWalls(); var result = new TileDirection[old.Length + 1]; for (var i = 0; i < old.Length; i++) { result[i] = old[i]; } result[result.Length - 1] = Direction; return result; }
public TileType GetTile(Vector2Int atLocation, TileDirection towards) { Vector2Int newLoc = atLocation + TileDirectionVec2.Get_V2I(towards); if (newLoc.x < 0 || newLoc.y < 0 || newLoc.x >= width || newLoc.y >= height) { return(TileType.NULL); } return(tiles[atLocation.x, atLocation.y]); }
static void AddSelectorDirectionChangeListeners(TileDirection direction, Dictionary <int, Controller> controllers) { for (var playerIndex = 1; playerIndex <= playersCount; ++playerIndex) { UnityEventTools.AddIntPersistentListener( controllers[playerIndex].DownButton.TurnOn, new UnityAction <int>(direction.ChangeDirection), playerIndex ); } }
public void Copy(Tile TileToCopy) { Texture = TileToCopy.Texture; Tri = TileToCopy.Tri; TriTopLeftIsCliff = TileToCopy.TriTopLeftIsCliff; TriTopRightIsCliff = TileToCopy.TriTopRightIsCliff; TriBottomLeftIsCliff = TileToCopy.TriBottomLeftIsCliff; TriBottomRightIsCliff = TileToCopy.TriBottomRightIsCliff; Terrain_IsCliff = TileToCopy.Terrain_IsCliff; DownSide = TileToCopy.DownSide; }
public Pusher(Board board, Tile baseTile, TileDirection direction, bool[] activeTurns, int x, int y) : base(board, baseTile, x, y) { if (activeTurns.Length == 5) { Direction = direction; ActiveTurns = activeTurns; } else { throw new Exception("Pusher initialization error; Length of ActiveTurns does not equal 5"); } }
public override TileDirection[] HasWalls() { var old = base.HasWalls(); var result = new TileDirection[old.Length + 1]; for (var i = 0; i < old.Length; i++) { result[i] = old[i]; } result[result.Length - 1] = Direction; return(result); }
public TileDirection GetRotated(TileOrientation Orientation) { var returnResult = new TileDirection(); if ( Orientation.SwitchedAxes ) { if ( Orientation.ResultXFlip ) { returnResult.X = (byte)(2 - Y); } else { returnResult.X = Y; } if ( Orientation.ResultYFlip ) { returnResult.Y = (byte)(2 - X); } else { returnResult.Y = X; } } else { if ( Orientation.ResultXFlip ) { returnResult.X = (byte)(2 - X); } else { returnResult.X = X; } if ( Orientation.ResultYFlip ) { returnResult.Y = (byte)(2 - Y); } else { returnResult.Y = Y; } } return returnResult; }
internal void MoveAIOnce(AI ai, TileDirection direction) { if (direction != TileDirection.None) { var toX = ai.X; var toY = ai.Y; switch (direction) { case TileDirection.Up: toY--; break; case TileDirection.Down: toY++; break; case TileDirection.Left: toX--; break; case TileDirection.Right: toX++; break; } //Check if movement is off the board if (toX < 0 || toY < 0 || toX >= Width || toY >= Height) { if (!this[ai.X, ai.Y].HasWall(direction)) { ai.Die(); } } else { //Check if movement is blocked by walls if (!this[ai.X, ai.Y].HasWall(ai.Direction) && !this[toX, toY].HasWall(TileDirectionUtil.Opposite(direction))) { //Check if movement is into a Pit if (this[toX, toY].IsPit()) { ai.X = toX; ai.Y = toY; ai.Die(); } else { //Check if an AI is already on the new Tile if (this[toX, toY].HasAI() != null) { //Move the AI on the new Tile (if not possible the AI stays) //MoveAIOnce(this[toX, toY].HasAI(), direction); //If the other AI moved, move this AI if (this[toX, toY].HasAI() == null) { ai.X = toX; ai.Y = toY; } } else { //When there are no problems, just move the AI ai.X = toX; ai.Y = toY; } } } } } }
public Entity MakeTileable(TileDirection tileDirection) { TileDirection = tileDirection; IsTileable = true; return this; }
public Wall(Board board, Tile baseTile, TileDirection direction, int x, int y) : base(board, baseTile, x, y) { Direction = direction; }
public override bool HasWall(TileDirection direction) { return BaseTile.HasWall(direction) || Direction == direction; }
private bool IsExistTile(int y,int x,TileDirection dir) { switch (dir){ case TileDirection.TOP: //上にマスがあるかどうか return y >= 1; case TileDirection.UNDER: //下にマスがあるかどうか return y <= Const.BOARD_HEIGHT - 2; case TileDirection.LEFT: return x >= 1; case TileDirection.RIGHT: return x <= Const.BOARD_WIDTH - 2; } return false; }
public virtual bool HasWall(TileDirection direction) { return false; }
private void UpdateObjectsAt(int x, int y, TileType type, KeyType keyType, TileDirection dir) { if (currObjects[x,y] != null) GameObject.Destroy(currObjects[x,y]); if (type == TileType.EMPTY) return; //works as eraser Transform newObjT = (Transform) Instantiate(tileLib.GetTilePrefab(type), TileLibrary.GetTilePos(new Vector2(x, y)), Quaternion.identity); currObjects[x,y] = newObjT.gameObject; //Should be painted? if (type == TileType.DOOR || type == TileType.KEY){ newObjT.GetComponent<SpriteRenderer>().color = tileLib.GetTileColor(keyType); } //Rotate newObjT.rotation = Quaternion.AngleAxis(90f * (int) dir, Vector3.forward); }
/// <summary> /// タイルをなぞる(2枚目以降 /// </summary> /// <param name="y">The y coordinate.</param> /// <param name="x">The x coordinate.</param> /// <param name="dir">Dir.</param> public void TraceTile(int y,int x,TileDirection dir) { if (CanDrawLine (y, x, dir)) return; int nextX = y; int nextY = x; ReturnNextPosition (ref nextY,ref nextX, dir); tracingTiles.Add (board.TileArray[nextY,nextX]); }
// public TileObject(Transform boxObject, TileType type, int x, int y){ // this.boxObject = boxObject; // this.type = type; // this.x = x; // this.y = y; // } public void Init(Transform boxObject, TileType type, KeyType keyType, TileDirection dir, int x, int y) { this.boxObject = boxObject; this.type = type; this.keyType = keyType; this.x = x; this.y = y; }
private void ReturnNextPosition(ref int y,ref int x,TileDirection dir) { switch(dir){ case TileDirection.LEFT: x -= 1; break; case TileDirection.RIGHT: x += 1; break; case TileDirection.TOP: y -= 1; break; case TileDirection.UNDER: y += 1; break; } }
public Tile(TileType type, TileDirection direction = TileDirection.UP, KeyType keyType = KeyType.RED, List<int> buttonConnections = null) { this.type = type; this.direction = direction; this.keyType = keyType; this.buttonConnections = buttonConnections; }
/// <summary> /// 指定した座標にタイルがあるかどうか /// </summary> // /// <returns><c>true</c> if this instance is exist tile the specified y x; otherwise, <c>false</c>.</returns> // /// <param name="y">The y coordinate.</param> // /// <param name="x">The x coordinate.</param> // private bool IsExistTile(int y,int x){ // return (y >= 0 && y < Const.BOARD_HEIGHT) || (x >= 0 && x < Const.BOARD_WIDTH); // } /// <summary> /// 指定の座標から指定の方向へ行った時になぞれるかチェック /// </summary> /// <returns><c>true</c>, if can draw line was checked, <c>false</c> otherwise.</returns> /// <param name="y">The y coordinate.</param> /// <param name="x">The x coordinate.</param> /// <param name="dir">Dir.</param> private bool CanDrawLine(int y,int x,TileDirection dir) { int currentNum = board.TileArray [y, x].num; int nextX = y; int nextY = x; ReturnNextPosition (ref nextY, ref nextX, dir); if (!TileUtil.IsExistTile (nextY, nextX)) return false; return currentNum == board.TileArray [nextY, nextX].num; }