Esempio n. 1
0
 /*
  * Inform chunks arround the current chunk what their state in the next fixed update is to be.
  * (State is purely a function of proximity to the current occuppied chunk(s))
  */
 private void QueueNextStateForChunks(ChunkIndex currentChunk)
 {
     for (int x = -3; x <= 3; x++)
     {
         for (int y = -3; y <= 3; y++)
         {
             Chunk chunk    = Chunks.GetChunk(currentChunk.Add(x, y));
             int   distance = Mathf.Max(Mathf.Abs(x), Mathf.Abs(y));
             if (distance == 0)
             {
                 chunk.NextState = ChunkState.Occupied;
             }
             else if (distance == 1)
             {
                 chunk.NextState = ChunkState.Live;
             }
             else if (distance == 2)
             {
                 chunk.NextState = ChunkState.SpawningGrounds;
             }
             else if (distance == 3)
             {
                 chunk.NextState = ChunkState.Inactive;
             }
         }
     }
 }
Esempio n. 2
0
        public bool FixedUpdate()
        {
            if (!Initialized)
            {
                return(false);
            }
            else
            {
                for (int chunkX = 0; chunkX < Tiles.GetLength(0); chunkX++)
                {
                    for (int chunkY = 0; chunkY < Tiles.GetLength(1); chunkY++)
                    {
                        Tiles[chunkX, chunkY].FixedUpdate();
                    }
                }
                List <EnemyManager> emigrantEnemies = new List <EnemyManager>();
                foreach (EnemyManager enemyManager in ResidentEnemies)
                {
                    enemyManager.CheckTreadmill();
                    if (!WithinChunk(enemyManager.GetPosition()))
                    {
                        emigrantEnemies.Add(enemyManager);
                        ChunkIndex newHome = GameManager.Singleton.World.GetChunkIndex(enemyManager.GetPosition());
                        GameManager.Singleton.World.GetChunk(newHome).RecieveImmigrantEnemy(enemyManager);
                        enemyManager.Immigrate(newHome);
                    }
                }
                foreach (EnemyManager enemyManager in emigrantEnemies)
                {
                    ResidentEnemies.Remove(enemyManager);
                }

                return(true);
            }
        }
Esempio n. 3
0
 public Chunk(ChunkIndex chunkIndex)
 {
     ChunkIndex      = chunkIndex;
     DangerRating    = DecideDangerRating();
     MaxEnemies      = Configuration.MAXIMUM_ENEMIES(DangerRating);
     ImportedRivers  = new List <RiverPackage>();
     RiverNodes      = CreateRiverNodes();
     Tiles           = CreateTiles();
     ResidentEnemies = new List <EnemyManager>();
 }
Esempio n. 4
0
        public void Sleep()
        {
            Active = false;
            ChunkIndex currentchunk = GetChunkIndex(PlayerManager.GetPosition());

            for (int indexX = currentchunk.X - 5; indexX <= currentchunk.X + 5; indexX++)
            {
                for (int indexY = currentchunk.Y - 5; indexY <= currentchunk.Y + 5; indexY++)
                {
                    Chunks.GetChunk(new ChunkIndex(indexX, indexY)).Sleep();
                }
            }
            PlayerManager.Sleep();
        }
Esempio n. 5
0
        public void InitializeRiverLocality(ChunkIndex chunkIndex)
        {
            float radius      = Helpers.ArrayMaximum(GenerationParameters.TopographyPeriods);
            int   chunkRadius = (int)(radius / Configuration.CHUNK_SIZE) + 2;

            for (int indexX = chunkIndex.X - chunkRadius; indexX <= chunkIndex.X + chunkRadius; indexX++)
            {
                for (int indexY = chunkIndex.Y - chunkRadius; indexY <= chunkIndex.Y + chunkRadius; indexY++)
                {
                    Chunk chunk = Chunks.GetChunk(new ChunkIndex(indexX, indexY));
                    if (!chunk.RiversInitialized)
                    {
                        chunk.InitializeRivers();
                    }
                }
            }
        }
Esempio n. 6
0
        public void FinalLocalityInitialization(ChunkIndex chunkIndex)
        {
            int radius = 2;

            for (int indexX = chunkIndex.X - radius; indexX <= chunkIndex.X + radius; indexX++)
            {
                for (int indexY = chunkIndex.Y - radius; indexY <= chunkIndex.Y + radius; indexY++)
                {
                    Chunk chunk = Chunks.GetChunk(new ChunkIndex(indexX, indexY));
                    if (!chunk.Initialized)
                    {
                        chunk.FinalInitialization();
                    }
                }
            }
            Chunks.GetChunk(chunkIndex).LocalityInitialized  = true;
            Chunks.GetChunk(chunkIndex).InitializingLocality = false;
        }
Esempio n. 7
0
 public Chunk(
     bool riversInitialized,
     bool initialized,
     bool localityInitialized,
     List <EnemyManager> residentEnemies,
     ChunkIndex chunkIndex,
     RiverNode[,] riverNodes,
     List <RiverPackage> importedRivers,
     Tile[,] tiles)
 {
     RiversInitialized   = riversInitialized;
     Initialized         = initialized;
     LocalityInitialized = localityInitialized;
     ResidentEnemies     = residentEnemies;
     ChunkIndex          = chunkIndex;
     RiverNodes          = riverNodes;
     ImportedRivers      = importedRivers;
     Tiles = tiles;
 }
Esempio n. 8
0
        public Chunk GetChunk(ChunkIndex chunkIndex)
        {
            Chunk chunk;

            if (chunkIndex.X >= 0 && chunkIndex.Y >= 0)
            {
                chunk = QuadOne.Get(chunkIndex.X, chunkIndex.Y);
                if (chunk == null)
                {
                    chunk = new Chunk(chunkIndex);
                    QuadOne.Set(chunkIndex.X, chunkIndex.Y, chunk);
                }
            }
            else if (chunkIndex.X < 0 && chunkIndex.Y >= 0)
            {
                chunk = QuadTwo.Get(-chunkIndex.X, chunkIndex.Y);
                if (chunk == null)
                {
                    chunk = new Chunk(chunkIndex);
                    QuadTwo.Set(-chunkIndex.X, chunkIndex.Y, chunk);
                }
            }
            else if (chunkIndex.X < 0 && chunkIndex.Y < 0)
            {
                chunk = QuadThree.Get(-chunkIndex.X, -chunkIndex.Y);
                if (chunk == null)
                {
                    chunk = new Chunk(chunkIndex);
                    QuadThree.Set(-chunkIndex.X, -chunkIndex.Y, chunk);
                }
            }
            else
            {
                chunk = QuadFour.Get(chunkIndex.X, -chunkIndex.Y);
                if (chunk == null)
                {
                    chunk = new Chunk(chunkIndex);
                    QuadFour.Set(chunkIndex.X, -chunkIndex.Y, chunk);
                }
            }
            return(chunk);
        }
Esempio n. 9
0
        public void FixedUpdate()
        {
            if (!Active)
            {
                return;
            }

            UpdateWorldInitializers();

            ChunkIndex currentChunk = GetChunkIndex(PlayerManager.GetPosition());

            QueueNextStateForChunks(currentChunk);

            LiveChunks.Clear();
            bool allLiveChunksLoaded = true;

            for (int x = -3; x <= 3; x++)
            {
                for (int y = -3; y <= 3; y++)
                {
                    Chunk chunk = Chunks.GetChunk(currentChunk.Add(x, y));

                    TransitionChunkState(chunk);

                    if (chunk.State == ChunkState.Occupied || chunk.State == ChunkState.Live)
                    {
                        LiveChunks.Add(chunk);
                        allLiveChunksLoaded &= chunk.FixedUpdate();
                    }
                }
            }
            if (allLiveChunksLoaded)
            {
                GameManager.Singleton.TakeInput(GameInputType.WorldLoaded);
            }
        }