示例#1
0
        /// <summary>
        /// Tests whether any non-moving items are currently occupying the specified position
        /// </summary>
        /// <remarks>This is to be used when looking to place another non-moving item</remarks>
        /// <param name="tp">The tile position to test</param>
        /// <returns>True if there is already a static item occupying the specified position</returns>
        public bool IsStaticItemOnTile(TilePos tp)
        {
            var objectsAtPosition = this.GetItemsOnTile(tp);
            var result            = objectsAtPosition.Any(gi => gi.Properties.Get(GameObjectProperties.Solidity) != ObjectSolidity.Insubstantial);

            return(result);
        }
示例#2
0
    IEnumerator IELoadTile(TilePos pos)
    {
        if (tileList.Contains(pos))
        {
            yield break;
        }

        tileList.Add(pos);

        TilePos playerTile;

        do
        {
            playerTile = Player.Instance.tilePos;
            yield return(null);
        }while (Mathf.Abs(pos.x - playerTile.x) > 1 || Mathf.Abs(pos.y - playerTile.y) > 1);

        Transform tileObj     = Instantiate(tilePrefab, Vector3.zero, transform.rotation) as Transform;
        TilePos   relativePos = new TilePos(pos.x - startPos.x, pos.y - startPos.y);

        tileObj.position           = new Vector3(relativePos.x * TILE_WIDTH, 0, relativePos.y * TILE_WIDTH);
        tileObj.transform.rotation = Quaternion.Euler(90, 0, 0);

        StartCoroutine(IELoadTex(pos, tileObj.GetComponent <SpriteRenderer>()));

        StartCoroutine(IELoadTile(new TilePos(pos.x + 1, pos.y)));
        StartCoroutine(IELoadTile(new TilePos(pos.x - 1, pos.y)));
        StartCoroutine(IELoadTile(new TilePos(pos.x, pos.y + 1)));
        StartCoroutine(IELoadTile(new TilePos(pos.x, pos.y - 1)));
    }
        private void AddBoulder(XmlElement boulderDef)
        {
            var tilePos  = new TilePos(int.Parse(boulderDef.GetAttribute("Left")), int.Parse(boulderDef.GetAttribute("Top")));
            var position = tilePos.ToPosition();

            this._gameState.AddBoulder(position);
        }
示例#4
0
        public bool Request(TilePos index, GenerationStage stage, string reason, Action <bool, Tile> action

                            /*    ,   [CallerMemberName] string memberName = "",
                             *     [CallerFilePath] string sourceFilePath = "",
                             *     [CallerLineNumber] int sourceLineNumber = 0*/)
        {
            using (Profiler.CurrentProfiler.Begin("Requesting Tile Stage"))
            {
                //Debug.WriteLine($"Requested Tile {index} stage {stage} because: {reason}");
                return(Load(index, (wasImmediate0, tile) =>
                {
                    tile.ScheduleOnUpdate(wasImmediate1 =>
                    {
                        if (tile.IsAtPhase(stage))
                        {
                            action(wasImmediate0 && wasImmediate1, tile);
                        }
                        else
                        {
                            tile.InvokeWhenCompleted(stage, b => action(b && wasImmediate0 && wasImmediate1, tile), $"awaiting stage {stage}");// from {memberName} at {sourceFilePath}:{sourceLineNumber}");
                            QueueTile(tile, stage);
                        }
                    }, "running task in-thread");
                }));
            }
        }
示例#5
0
 public SetPropertyCommand(PuzzleLayout sut, TilePos position, string key, object value)
 {
     _sut      = sut;
     _position = position;
     _key      = key;
     _value    = value;
 }
        public bool IsPositionWithinBoundary(TilePos tilePos)
        {
            var roomBoundary = World.GetContainingRoom(this._gameObject.TilePosition);
            var result       = roomBoundary.Contains(tilePos);

            return(result);
        }
示例#7
0
        public static List <ICollisionObject> MapObjects(TilePos tile)
        {
            List <ICollisionObject> result = new List <ICollisionObject>();

            foreach (TileDir dir in gmap.ReverseDirs(tile))
            {
                result.Add(new CollisionSide(tile, dir));
            }

            HashSet <TileDir> edgeDirs = new HashSet <TileDir>();

            foreach (TileDir dir1 in gmap.Dirs(tile))
            {
                foreach (TileDir dir2 in gmap.Dirs(tile))
                {
                    if (dir1 != dir2)
                    {
                        edgeDirs.Add(dir1 + dir2);
                    }
                }
            }
            edgeDirs.ExceptWith(new HashSet <TileDir> {
                TileDir.Zero
            });

            foreach (TileDir dir in edgeDirs)
            {
                result.Add(new CollisionCircle(tile.ToVector(0.5 * (1 + dir.X), 0.5 * (1 + dir.Y)), game.TrackTileMargin));
            }

            return(result);
        }
示例#8
0
        /// <summary>
        /// Tests whether an impassable object is occupying the specified position
        /// </summary>
        /// <remarks>This is to be used when looking for a clear path or line of sight</remarks>
        /// <param name="tp">The tile position to test</param>
        /// <returns>True if there is an impassable object occupying the specified position</returns>
        public bool IsImpassableItemOnTile(TilePos tp)
        {
            var objectsAtPosition = this.GetItemsOnTile(tp);
            var result            = objectsAtPosition.Any(gi => gi.Properties.Get(GameObjectProperties.Solidity) == ObjectSolidity.Impassable);

            return(result);
        }
示例#9
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.CompareTag("Terrain"))
     {
         TilePos tilePos = PathfindingMap.WorldToTilePos(other.transform.position);
         int     tileId  = map.GetTile(tilePos.x, tilePos.y).blockTypeId;
         if (tileId == 3)   // collectible
         {
             Destroy(other.gameObject);
             collectibleSpawner.SpawnCollectible();
             bar.PickupCollectible();
         }
         else if (tileId == 2)     // throttle
         {
             Throttle();
         }
         else if (tileId == 4 && cash > 0)     //paywall
         {
             map.RemoveObstacle(tilePos.x, tilePos.y);
             cash -= 1; //temp
             UpdateCashText();
             Destroy(other.gameObject);
         }
     }
 }
示例#10
0
        private Vector EndSidePos()
        {
            TilePos pos    = path[0].Pos;
            TileDir dir    = path[0].DirOut;
            TileDir normal = new TileDir(0);

            for (int i = 1; i < Math.Min(5, path.Count); i++)
            {
                if (null == path[i].DirOut)
                {
                    pos = path[0].Pos + dir * 4;
                    break;
                }

                if (path[i].DirIn != path[i].DirOut)
                {
                    normal = path[i].DirOut;
                    break;
                }

                pos = path[i].Pos;
                dir = path[i].DirIn;
            }

            if (normal == dir.Negative())
            {
                normal = dir;
            }

            return(EndSidePos(pos, dir, normal.Negative()));
        }
示例#11
0
 public Tile(TilePos pos)
 {
     DensityMap = new Voxel[16, 16, 16];
     Pos        = pos;
     StartPos   = pos.ToVoxelPos();
     EndPos     = pos.Add(1, 1, 1).ToVoxelPos();
 }
示例#12
0
 public TileSearchInfo(Tile _tile, Tile _parent)
 {
     tile          = _tile;
     pos           = tile.Pos;
     parent        = _parent;
     distFromStart = 0;
 }
示例#13
0
        protected PathCheckResult checkAround(int offset = 0)
        {
            if (2 + offset >= path.Count)
            {
                return(PathCheckResult.Unknown);
            }

            TilePos posIn  = path[1 + offset].Pos;
            TilePos posOut = path[2 + offset].Pos;

            TileDir dirIn  = path[1 + offset].DirIn;
            TileDir dirOut = path[2 + offset].DirOut;

            if (null == dirOut || dirOut == TileDir.Zero)
            {
                return(PathCheckResult.Unknown);
            }

            bool isLine = dirIn == path[1 + offset].DirOut || path[2 + offset].DirIn == dirOut;

            if (!isLine && dirIn == dirOut.Negative() && posIn != posOut)
            {
                return(PathCheckResult.Yes);
            }
            else
            {
                return(PathCheckResult.No);
            }
        }
示例#14
0
        public override ConfirmedDirection GetDirection()
        {
            IDirectionChosen directionTowardsPlayer = this.Monster.DetermineDirectionTowardsPlayer();

            if (!(directionTowardsPlayer is ConfirmedDirection))
            {
                bool notPossibleToGoInDirectionTowardsPlayer = !this.Monster.ConfirmDirectionToMoveIn(directionTowardsPlayer, out ConfirmedDirection feasibleDirection);
                if (notPossibleToGoInDirectionTowardsPlayer || feasibleDirection == Direction.None)
                {
                    return(feasibleDirection);
                }
            }

            // we know at this point that we could move in DirectionTowardsPlayer HOWEVER we don't want to actually step onto the same tile as the player
            TilePos potentiallyMovingTowards = this.Monster.TilePosition.GetPositionAfterOneMove(directionTowardsPlayer.Direction);

            if (potentiallyMovingTowards != GlobalServices.GameState.Player.TilePosition)
            {
                // it's okay. we'll be closer to the player without actually touching the player
                return(directionTowardsPlayer.Confirm());
            }

            var directionAwayFromPlayer = MonsterMovement.AlterDirectionByVeeringAway(directionTowardsPlayer.Direction);

            this.Monster.ConfirmDirectionToMoveIn(directionAwayFromPlayer, out ConfirmedDirection result);
            return(result);
        }
示例#15
0
        protected PathCheckResult checkSnakeWithOffset(int offset = 0)
        {
            if (3 + offset >= path.Count)
            {
                return(PathCheckResult.Unknown);
            }

            TilePos posIn  = path[1 + offset].Pos;
            TilePos posOut = path[2 + offset].Pos;

            TileDir dirIn  = path[1 + offset].DirIn;
            TileDir dirOut = path[2 + offset].DirOut;

            if (null == dirOut || dirOut == TileDir.Zero)
            {
                return(PathCheckResult.Unknown);
            }

            TileDir dir = new TileDir(posOut.X - posIn.X, posOut.Y - posIn.Y);

            if (dirIn == dirOut && (dir == dirIn.PerpendicularLeft() || dir == dirIn.PerpendicularRight()))
            {
                return(PathCheckResult.Yes);
            }
            else
            {
                return(PathCheckResult.No);
            }
        }
示例#16
0
 public IEnumerable<StaticItem> GetGameObjects(World world)
 {
     var result = new List<StaticItem>();
     var lines = this._layout.Split(new [] { "\r\n" }, StringSplitOptions.None);
     for (int y = 0; y < lines.Count(); y++)
         {
         for (int x = 0; x < lines[y].Length; x++)
             {
             var position = new TilePos(x, y).ToPosition();
             var c = lines[y][x];
             switch (c)
                 {
                 case ' ':
                     break;
                 case '#':
                     Trace.WriteLine(System.IO.Directory.GetCurrentDirectory());
                     result.Add(new Wall(world, position, "Tiles/Floor1"));
                     break;
                 case 'p':
                     result.Add(new Player(world, position, 255));
                     break;
                 case 'b':
                     result.Add(new Boulder(world, position));
                     break;
                 case 'g':
                     result.Add(new Grave(world, position));
                     break;
                 default:
                     throw new InvalidOperationException();
                 }
             }
         }
     return result;
 }
示例#17
0
 public Tile(GameObject go, int x, int y)
 {
     this.go = go;
     visited = false;
     pos     = new TilePos(x, y);
     isWall  = true;
 }
示例#18
0
        public Grave AddGrave(TilePos tp)
        {
            var g = new Grave(tp.ToPosition());

            this._gameObjectCollection.Add(g);
            return(g);
        }
示例#19
0
 public void setAISimFromParent(PassiveObject parent)
 {
     curTilePos = new TilePos(parent.curTilePos);
     isDone     = parent.isDone;
     isAISim    = true;
     type       = parent.type;
 }
        private PossibleDirection GetIntendedDirection(Monster monster)
        {
            TilePos tp             = monster.TilePosition;
            TilePos playerPosition = GlobalServices.GameState.Player.TilePosition;
            int     yDiff          = tp.Y - playerPosition.Y; // +ve and the monster is below, -ve and the monster is above
            int     xDiff          = tp.X - playerPosition.X; // +ve and the monster is to the right, -ve and the monster is to the left

            var orientation = this.CurrentDirection.Orientation();

            if (orientation == Orientation.Horizontal)
            {
                if (yDiff > 0)
                {
                    return(PossibleDirection.Up);
                }
                if (yDiff < 0)
                {
                    return(PossibleDirection.Down);
                }
            }
            else if (orientation == Orientation.Vertical)
            {
                if (xDiff > 0)
                {
                    return(PossibleDirection.Left);
                }
                if (xDiff < 0)
                {
                    return(PossibleDirection.Right);
                }
            }

            return(MonsterMovement.RandomDirection());
        }
示例#21
0
        TilePos MoveByRandom(TilePos pos, int distance)
        {
            if (distance == 0)
            {
                return(pos);
            }

            var newDistance = seed.Random();

            while (newDistance > distance)
            {
                newDistance /= 2;
            }

            var orient256 = seed.Random();
            var x         = pos.X + ((stepX[orient256] * newDistance * 16) / 128);
            var y         = pos.Y - ((stepY[orient256] * newDistance * 16) / 128);

            /* Out of map size check: 64 * 256 = 16384 */
            if (x > 16384 || y > 16384)
            {
                return(pos);
            }

            x = (x & 0xff00) | 0x80;
            y = (y & 0xff00) | 0x80;

            return(new TilePos(x, y));
        }
示例#22
0
 public void setupGeneral(TilePos _curTile)
 {
     curTilePos = new TilePos(_curTile);
     isDone     = false;
     isAISim    = false;
     GameObjectManager.instance.getPassiveObjectGO().activate(this);
 }
示例#23
0
        void Move(Direction LTRBDir)
        {
            if (actor.Dead)
            {
                return;
            }

            this.keyLTRB = LTRBDir;

            if (!moving)
            {
                SetDir(LTRBDir);

                TilePos           targetTilePos = curTilePos + LTRBDir;
                SquareTileMapNode node          = TileMapEngine.Instance.GetTileNode(targetTilePos);
                if (node)
                {
                    if (!node.Invalid)
                    {
                        this.targetTilePos      = targetTilePos;
                        this.targetTileWorldPos = node.WorldPosition;

                        StartCoroutine(MoveProcess());
                    }
                }
            }
        }
示例#24
0
 private void PropertyChanged(TilePos position, string key, object value)
 {
     if (_layoutLink.Position == position && key == "IsLoaded")
     {
         UpdateLoadedState((bool)value);
     }
 }
示例#25
0
    protected Vector3 GetCameraPosition()
    {
        TilePos centertile = new TilePos((int)TileManager.Instance.GridWidth / 2,
                                         Mathf.Min(TileManager.Instance.GetLastActiveRow(), TileManager.Instance.GridHeight - 1));

        return(TileManager.Instance.GetTileClamped(centertile.x, centertile.z).GetPosition());
    }
示例#26
0
    void PlaceStuffs( )
    {
        List <TilePos> placements = new List <TilePos>();

        for (int j = 0; j < tilemap.GetLength(1); j++)
        {
            for (int i = 0; i < tilemap.GetLength(0); i++)
            {
                if (tilemap[i, j] == 0)
                {
                    placements.Add(new TilePos(i, j));
                }
            }
        }

        placements.Shuffle();


        float[] pctForDifficulty = { 0.2f, 0.15f, 0.1f, 0.05f, 0.01f };
        int     numThings        = (int)(placements.Count * pctForDifficulty[difficulty - 1]);

        for (int i = 0; i < numThings; i++)
        {
            TilePos pos = placements[i];
            tilemap[pos.x, pos.y] = 2;
        }
    }
        private PossibleDirection GetIntendedDirection()
        {
            TilePos tp = this.Monster.TilePosition;

            PossibleDirection newDirection;
            TilePos           playerPosition = GlobalServices.GameState.Player.TilePosition;
            int yDiff = tp.Y - playerPosition.Y;    // +ve and the player is above, -ve and the player is below
            int xDiff = tp.X - playerPosition.X;    // +ve and the player is to the left, -ve and the player is to the right

            // if on the same row or column as the player then will be at risk of being shot
            if ((xDiff == 0 || yDiff == 0) && ShouldMakeMoveToAvoidTrouble())
            {
                newDirection = GetRandomPerpendicularDirection(this.CurrentDirection);
            }
            else if ((this.CurrentDirection == Direction.Left && xDiff <= -5) || (this.CurrentDirection == Direction.Right && xDiff >= 5))
            {
                newDirection = yDiff > 0 ? PossibleDirection.Up : PossibleDirection.Down;
            }
            else if ((this.CurrentDirection == Direction.Up && yDiff <= -5) || (this.CurrentDirection == Direction.Down && yDiff >= 5))
            {
                newDirection = xDiff > 0 ? PossibleDirection.Left : PossibleDirection.Right;
            }
            else if (GlobalServices.Randomness.Next(16) == 0)
            {
                newDirection = GetRandomPerpendicularDirection(this.CurrentDirection);
            }
            else
            {
                newDirection = new PossibleDirection(this.CurrentDirection);
            }

            return(newDirection);
        }
示例#28
0
        private void ValidateGameState(GameState gameState)
        {
            var msg = new WorldLoaderProgress("Validating gamestate");

            Messenger.Default.Send(msg);

            var tcv    = new TileContentValidator();
            var issues = new List <string>();
            var cy     = this._worldSize.Y;
            var cx     = this._worldSize.X;

            for (int y = 0; y < cy; y++)
            {
                for (int x = 0; x < cx; x++)
                {
                    var tp    = new TilePos(x, y);
                    var items = gameState.GetItemsOnTile(tp).ToList();
                    if (!tcv.IsListOfObjectsValid(items, out string reason))
                    {
                        issues.Add(tp + ": " + reason);
                    }
                }
            }

            if (issues.Count != 0)
            {
                var message = string.Join("\r\n", issues);
                throw new InvalidOperationException(message);
            }
        }
示例#29
0
 public Tile this[TilePos tp]
 {
     get
         {
         return null;
         }
 }
示例#30
0
        /// <summary>
        /// Returns a list of all extant game objects that are located on the specified tile
        /// </summary>
        /// <param name="tp">Specifies the tile position to inspect</param>
        /// <returns>A lazy enumeration of all the matching game objects</returns>
        public IEnumerable <IGameObject> GetItemsOnTile(TilePos tp)
        {
            var listOfItems = this._gameObjectCollection.ItemsAtPosition(tp);
            var result      = listOfItems.Where(gi => gi.IsExtant && gi.TilePosition == tp);

            return(result);
        }
示例#31
0
文件: Board.cs 项目: thalbern/Dejarik
    /// <summary>
    /// Get the set of tiles reachable from the given starting position with the exact move count,
    /// and which are not already occupied. Tiles reachable with less moves are not returned.
    /// </summary>
    /// <param name="startPos">Tile where the move starts.</param>
    /// <param name="moveCount">Number of moves from the starting position.</param>
    /// <returns>The set of non-occupied tiles reachable from the starting position.</returns>
    public HashSet <Tile> GetMovableTiles(TilePos startPos, int moveCount)
    {
        HashSet <Tile> movableTiles = new HashSet <Tile>();

        void depthFirstSearch(TilePos curPos, int remainingMovement, List <TilePos> path)
        {
            path.Add(curPos);

            if (remainingMovement <= 0)
            {
                movableTiles.Add(tiles[curPos]);
                return;
            }

            foreach (Tile tile in tiles[curPos].connections)
            {
                if (!tile.occupied && !path.Contains(tile.position))
                {
                    depthFirstSearch(tile.position, remainingMovement - 1, new List <TilePos>(path));
                }
            }
        }

        depthFirstSearch(startPos, moveCount, new List <TilePos>());

        return(movableTiles);
    }
示例#32
0
文件: Board.cs 项目: thalbern/Dejarik
 /// <summary>
 /// Retrieve a tile by position and set its occupied state.
 /// </summary>
 /// <param name="position">The tile position.</param>
 /// <param name="occupied">The occupied state to set.</param>
 public void SetTileOccupied(TilePos position, bool occupied)
 {
     if (tiles.TryGetValue(position, out Tile tile))
     {
         tile.occupied = occupied;
     }
 }
示例#33
0
 public void TestBackAndForth()
 {
     for (int x = 0; x < 256; x++)
         {
         for (int y = 0; y < 40; y++)
             {
             var tp = new TilePos(x, y);
             var mc = tp.MortonCode;
             var tp2 = TilePos.FromMortonCode(mc);
             Assert.AreEqual(tp, tp2);
             }
         }
 }
示例#34
0
 public void TestTilePosToPosition()
 {
     for (int x = 0; x <= 1000; x++)
         {
         for (int y = 0; y <= 1000; y++)
             {
             var tp = new TilePos(x, y);
             var p = tp.ToPosition();
             var tp2 = TilePos.TilePosFromPosition(p);
             Assert.AreEqual(tp, tp2);
             }
         }
 }
示例#35
0
 public int GetWorldAreaIdForTilePos(TilePos tp)
 {
     return 0;
 }
示例#36
0
 public StartState(TilePos playerPosition, int playerEnergy)
 {
     this.PlayerPosition = playerPosition;
     this.PlayerEnergy = playerEnergy;
 }
示例#37
0
 public StartState GetStartStateForWorldAreaId(int id)
 {
     var lines = this._layout.Split(new [] { "\r\n" }, StringSplitOptions.None);
     TilePos? tp = null;
     for (int y = 0; y < lines.Count(); y++)
         {
         int x = lines[y].IndexOf('p');
         if (x != -1)
             {
             tp = new TilePos(x, y);
             break;
             }
         }
     if (!tp.HasValue)
         throw new InvalidOperationException();
     var result = new StartState(tp.Value, 255);
     return result;
 }
示例#38
0
 public float distance(TilePos other)
 {
     return (new Vector2(x - other.x, y - other.y)).magnitude;
 }