当前位置: 首页>>代码示例>>C#>>正文


C# Platform.get_lower_extremity方法代码示例

本文整理汇总了C#中Platform.get_lower_extremity方法的典型用法代码示例。如果您正苦于以下问题:C# Platform.get_lower_extremity方法的具体用法?C# Platform.get_lower_extremity怎么用?C# Platform.get_lower_extremity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Platform的用法示例。


在下文中一共展示了Platform.get_lower_extremity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

    //FIX GENERATION BUGS
    //VERIFY THAT GRAPH CAN BE REMOVED
    //ADD CODE TO MARK THE START AND END PLATFORMS
    //IMPROVE LEVEL GENERATION RULES
    //VERIFY CASES WHEN LIST ENDS ARE REACHED
    //VERIFY THE CORECTNESS FOR ALL EVENTS
    void Start()
    {
        active_platforms = new List<Transform>();
        inactive_platforms = new Queue<Transform>();
        all_platforms = new List<Platform>();
        //TEST THE COMPARATOR
        right_extremities = new SortedList<float,int>(new Duplicate_key_comparer<float>());
        left_extremities = new SortedList<float,int>(new Duplicate_key_comparer<float>());
        upper_extremities = new SortedList<float,int>(new Duplicate_key_comparer<float>());
        lower_extremities = new SortedList<float,int>(new Duplicate_key_comparer<float>());
        platform_graph = new Graph();

        //instantiate up to the number of allowed platforms
        for (int a=0; a<TOTAL_INSTANCIATED_PLATFORMS; a++) {
            Transform platform = (Transform)Instantiate(prefab);
            inactive_platforms.Enqueue(platform);
        }

        //place the start platform
        Vector3 start_scale = new Vector3(4, 0.36f, 1);
        Platform start_platform = new Platform(start_pos, start_scale);
        all_platforms.Add(start_platform);
        right_extremities.Add(start_platform.get_right_extremity(), 0);
        left_extremities.Add(start_platform.get_left_extremity(), 0);
        upper_extremities.Add(start_platform.get_upper_extremity(), 0);
        lower_extremities.Add(start_platform.get_lower_extremity(), 0);

        System.Random rnd = new System.Random();
        //for each remaining platform to be created
        for (int a=1; a<TOTAL_PLATFORMS; ++a){
            bool is_overlapping = true;

            //randomly select an existing platform from which the new platform should be reachable
            int index = rnd.Next(all_platforms.Count);
            int placement_attempts = 0;

            //try up to 3 times to create and place the new platform
            Platform platform = new Platform();
            while (is_overlapping && placement_attempts < 3){
                ++placement_attempts;

                //select a random width for the new platform
                int platform_width = rnd.Next(2, 10);
                Vector3 platform_scale = new Vector3(platform_width, 0.36f, 1);

                //select a random location for the platform within a reachable proximity of the selected platform
                int platform_x = rnd.Next((int)(all_platforms[index].get_left_extremity() - platform_horizontal_gap), (int)(all_platforms[index].get_right_extremity() + platform_horizontal_gap));
                int platform_y = rnd.Next((int)(all_platforms[index].get_lower_extremity() - platform_downwards_gap), (int)(all_platforms[index].get_upper_extremity() + platform_upwards_gap));
                Vector3 platform_pos = new Vector3(platform_x, platform_y, 1);

                platform = new Platform(platform_pos, platform_scale);
                float left_extremity = platform.get_left_extremity();
                float right_extremity = platform.get_right_extremity();
                float upper_buffer = platform.get_upper_extremity() + VERTICAL_BUFFER;
                float lower_buffer = platform.get_lower_extremity() - VERTICAL_BUFFER;

                //determine the index of the first platform fully to the right of hte new platform
                int stop_index = 0;
                foreach (KeyValuePair<float, int> extremity in left_extremities){
                    if (extremity.Key >= right_extremity){
                        stop_index = extremity.Value;
                        break;
                    }
                }

                bool is_potential_overlap = false;
                is_overlapping = false;

                //walk through the existing platforms in order of their right extremities
                foreach (KeyValuePair<float, int> extremity in right_extremities){
                    //start checking for overlapping platforms once the first platform with its right extremity to the left of the left extremity of the new platform is reached
                    if (extremity.Key >= left_extremity)
                        is_potential_overlap = true;

                    //if the stop index has been reached, do not check any more platforms
                    if (extremity.Value == stop_index)
                        break;

                    //if the current platform overlaps on the x-axis with the new platform
                    if (is_potential_overlap){
                        //if the current platform falls within the vertical buffer of the new platform, an overlap has occured
                        if (!(all_platforms[extremity.Value].get_lower_extremity() > upper_buffer  || all_platforms[extremity.Value].get_upper_extremity() < lower_buffer)){
                            is_overlapping = true;
                            break;
                        }
                    }
                }
            }

            //MARK FIRST PLATFORM AS FULL AND EXLCUDE FROM FUTURE ADDITIONS?
            //if the new platform is still overlapping, do not place it - decrement the iteration number to try again from a new platform to reach from
            if (is_overlapping)
                --a;
            //otherwise, place the platform
//.........这里部分代码省略.........
开发者ID:GameMakers,项目名称:GameInMaking,代码行数:101,代码来源:LevelGenerator.cs


注:本文中的Platform.get_lower_extremity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。