Example #1
0
        public EnemyData AddEnemy(EnemyData.EnemyType type, int offset_x, int offset_y)
        {
            EnemyData enemy_data = map_manager_.mapFactory.GetDefaultEnemyData(type).Clone() as EnemyData;

            MapVector current_offset = CurrentGroundOffset;

            enemy_data.spawnPosition = new MapVector(current_offset.x + offset_x, current_offset.y + offset_y);
            enemies_.Add(enemy_data);

            return(enemy_data);
        }
Example #2
0
        public TerrainData AddObstacle(int width, int height, int offset_x, int offset_y)
        {
            TerrainData terrian_data = new TerrainData();

            terrian_data.terrainType     = TerrainData.TerrainType.Ground;
            terrian_data.interactiveType = TerrainData.InteractiveType.Solid;

            MapVector current_offset = CurrentGroundOffset;

            terrian_data.region = new MapRect(
                current_offset.x + offset_x, current_offset.y + offset_y,
                width, height);
            widgets_.Add(terrian_data);

            return(terrian_data);
        }
Example #3
0
        public IEnumerator Generate()
        {
            map_data = builder_.InitMapData();

            builder_.Reset();

            int       num_ground = 10000;
            MapVector random_ground_width_range  = new MapVector(4, 20);
            MapVector random_ground_offset_range = new MapVector(2, 5);

            builder_.NewGround(
                0, 0, Mathf.Max(12, random_.Next(random_ground_width_range.x, random_ground_width_range.y)));

            // Try to add a test enemy
            builder_.AddEnemy(EnemyData.EnemyType.Dog, 10);

            bool last_is_high_ground = false;

            for (int i = 1; i < num_ground; i++)
            {
                bool this_is_high_ground  = random_.NextDouble() < 0.25 /* 25% possibility to be a high ground */;
                bool close_to_last_ground = last_is_high_ground != this_is_high_ground?random_.NextDouble() < 0.5 : false /* 50% possibility to be a closed ground */;

                var ground_data = builder_.NewGround(
                    close_to_last_ground ? 0 : random_.Next(random_ground_offset_range.x, random_ground_offset_range.y),
                    this_is_high_ground ? 1 : 0,
                    random_.Next(random_ground_width_range.x, random_ground_width_range.y / 2 * 2 /* round down */));

                if (random_.NextDouble() < 0.5)
                {
                    int enemy_type_index           = random_.Next(0, 5);
                    EnemyData.EnemyType enemy_type = EnemyData.EnemyType.Scout + enemy_type_index;
                    AddEnemy(EnemyData.EnemyType.Bomber, random_.Next(0, Mathf.Max(1, ground_data.region.width - 1)));
                }

                last_is_high_ground = this_is_high_ground;
            }

            map_data.blocks = builder_.BuildBlocks();
            yield return(map_data);
        }
Example #4
0
 public static MapRect FromPoint(MapVector point)
 {
     return(new MapRect(point.x, point.y, 0, 0));
 }