• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天行健 君子當自強而不息

            Working with Maps and Levels(1)

            Placing Characters on the Map

            While going through the examples, I placed characters on the map in
            a direct, hard-coded manner. However, remember that hard-coding game data is a
            no-no. You need to have as much flexibility as possible when designing your maps,
            and this includes placement of characters in a level.

            Two methods for placing characters in maps that provide the flexibility you want
            involve character map lists and scripts.

             

            Character Map Lists

            In numerous chapters, “Implementing Scripts,” I use external
            data files that store a list of numbers and text. Those data files are loaded and
            parsed into some useful information to the engine loading the data. Action templates,
            for example, contain the action text plus the entry data for each action, all
            in one easy-to-read-and-edit file.

            To adhere to the simple nature of using text data files, you can create lists of characters
            to place within a map when the map is loaded. Because players are placed in
            a map using only a set of coordinates and a direction to face, this data file might
            look something like the following:

            0 100.0 0.0 450.0 0.0
            21 0.0 0.0 -82.0 1.57
            18 640.0 10.0 0.0 3.14

            At first appearance, the preceding three lines of numbers are just that—a list of
            numbers—but the trained eye sees that each number represents something. Starting
            with the first number on each line, you have the following:

            ■ The character’s type (for example: 0=Main Character, 21=Ogre, 18=Child)
            ■ The X-coordinate, Y-coordinate, and Z-coordinate
            ■ The angle that the character is facing (in radians)

            Now knowing what each number means, you can see that I defined three characters
            and placed them through the map at their respective locations and pointed
            them in a certain direction. This data is compact, easy to edit, and can be loaded
            and processed quickly.

             

            Loading Character Map Lists

            To process the data files as just described, you need only two functions.
            These functions are as follows:

            long get_next_long_2(FILE* fp)
            {
                
            char buf[1024];
                
            long pos = 0;    
                
                
            for(;;)
                {
                    
            int c = fgetc(fp);

                    
            if(c == EOF || c == '\n' || (c == ' ' && pos) || pos == sizeof(buf)-1)
                        
            break;

                    
            if((c >= '0' && c <= '9') || c == '.' || c == '-')
                        buf[pos++] = (
            char)c;
                }

                
            if(pos == 0)  // if there is no long value in file
                    return -1;

                buf[pos] = 0;

                
            return atol(buf);
            }

            /////////////////////////////////////////////////////////////////////////////////////////////

            float get_next_float_2(FILE* fp)
            {
                
            char buf[1024];
                
            long pos = 0;    

                
            for(;;) 
                {
                    
            int c = fgetc(fp);

                    
            if(c == EOF || c == '\n' || (c == ' ' && pos) || pos == sizeof(buf)-1)
                        
            break;

                    
            if((c >= '0' && c <= '9') || c == '.' || c == '-')
                        buf[pos++] = (
            char)c;
                }

                buf[pos] = 0;

                
            return (float)atof(buf);
            }

            Both functions take a file pointer (fp) as an argument and return the next long type
            number or float type number found in the specified file. You arrange the character
            map list data file so that the first number (the character type) is a long, although
            the remaining numbers are float.

            Using get_next_long_2 and get_next_float_2, you can parse an entire character map list as follows:

            // fp = file pointer to open character map data file
            long Type; // Character type to load
            float XPos, YPos, ZPos, Direction;
            long NumCharactersLoaded = 0; // # characters loaded

            while(1)
            {
              // Break if no more characters to process
              if((Type = get_next_long_2 (fp)) == -1)
                break;

              // Get coordinates and angle
              XPos = get_next_float_2(fp);
              YPos = get_next_float_2(fp);
              ZPos = get_next_float_2(fp);
              Direction = get_next_float_2(fp);

              // Do something with data - insert a character
              NumCharactersLoaded++; // Increase # characters loaded
            }

            // Done loading NumCharactersLoaded # of characters

             

            posted on 2007-12-09 13:42 lovedday 閱讀(198) 評論(0)  編輯 收藏 引用

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            久久天天躁狠狠躁夜夜av浪潮 | 伊人久久大香线蕉影院95| 亚洲欧美日韩久久精品第一区| 久久人妻无码中文字幕| 久久精品国产久精国产思思 | 亚洲欧美日韩中文久久| 99久久国语露脸精品国产| 97久久超碰成人精品网站| 国产精品免费久久久久久久久| 少妇被又大又粗又爽毛片久久黑人| 精品熟女少妇AV免费久久| 久久婷婷成人综合色综合| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 久久亚洲精品成人av无码网站| 久久天天躁狠狠躁夜夜avapp| 伊人久久精品线影院| 亚洲成色www久久网站夜月| 久久久精品视频免费观看| 久久精品人人做人人爽电影| 精品久久久久久中文字幕人妻最新| 久久综合视频网站| 中文字幕亚洲综合久久| 久久久亚洲欧洲日产国码是AV| 热综合一本伊人久久精品| 国产精品久久久久9999| 欧美日韩精品久久久久| 国产精品欧美久久久久天天影视 | 亚洲Av无码国产情品久久| 国内精品久久久久久久亚洲| 中文字幕热久久久久久久| 久久综合日本熟妇| 亚洲国产成人久久精品影视| 久久综合88熟人妻| 无码人妻久久一区二区三区免费| 亚洲伊人久久综合中文成人网| 99久久精品国产一区二区| 国产一级做a爰片久久毛片| 亚洲AV日韩精品久久久久久久| 国内精品人妻无码久久久影院导航| 久久人与动人物a级毛片| 亚洲国产精品嫩草影院久久|