• <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>

            天行健 君子當(dāng)自強(qiáng)而不息

            Controlling Players and Characters(34)

            Once it is determined what action each character wants to perform, that action
            must be validated. Characters moving around can’t walk through other players
            (except for PCs, who can walk through other PCs). Also, depending on your levels,
            you use a function to determine character-to-map collisions. These two validation
            functions are as follows:

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

            bool cCharController::check_move(sCharacter* character, float* x_move, float* y_move, float* z_move)
            {    
                
            if(character == NULL)
                    
            return false;

                
            float pos_x = character->pos_x + (*x_move);
                
            float pos_y = character->pos_y + (*y_move);
                
            float pos_z = character->pos_z + (*z_move);

                
            float min_x, min_z, max_x, max_z;

                character->
            object.get_bounds(&min_x, NULL, &min_z, &max_x, NULL, &max_z, NULL);
                
            float radius1 = max(max_x - min_x, max_z - min_z) * 0.5;

                
            // check movement against other characters
                for(sCharacter* char_ptr = m_root_char; char_ptr != NULL; char_ptr = char_ptr->next)
                {
                    
            // do not check against self or disabled characters
                    if(character != char_ptr && char_ptr->update_enable)
                    {
                        
            // do not check against other PC characters
                        if(character->type == CHAR_PC && char_ptr->type == CHAR_PC)
                            
            break;

                        
            // get distance between characters
                        float x_diff = fabs(pos_x - char_ptr->pos_x);
                        
            float y_diff = fabs(pos_y - char_ptr->pos_y);
                        
            float z_diff = fabs(pos_z - char_ptr->pos_z);

                        
            float dist = x_diff * x_diff + y_diff * y_diff + z_diff * z_diff;

                        char_ptr->
            object.get_bounds(&min_x, NULL, &min_z, &max_x, NULL, &max_z, NULL);
                        
            float radius2 = max(max_x - min_x, max_z - min_z) * 0.5f;

                        
            // do not allow movement if intersecting
                        if(dist <= (radius1 * radius1 + radius2 * radius2))
                            
            return false;
                    }        
                }

                
            // check custom collisions (map, etc)
                return validate_move(character, x_move, y_move, z_move);
            }

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

            virtual bool validate_move(sCharacter* character, float* x_move, float* y_move, float* z_move)
            {
                    
            // validate for outside bounds checking against character movements.

                    
            return true;
            }

            Both of the preceding functions (check_move and validate_move) take a pointer to the
            character being updated, as well as the character’s intended amount of movement
            in each direction. Each function modifies these values appropriately. When the
            character’s moves and actions have been validated, another function wraps up the
            actions and actually updates the character positions and actions.


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

            void cCharController::process_update(sCharacter* character, float x_move, float y_move, float z_move)
            {
                
            // move character
                character->pos_x += x_move;
                character->pos_y += y_move;
                character->pos_z += z_move;        

                
            // move object and point in direction
                character->object.move(character->pos_x, character->pos_y, character->pos_z);
                character->
            object.rotate(0.0f, character->direction, 0.0f);

                
            // set new animation
                if(character->last_anim != character->action)
                {
                    character->last_anim = character->action;

                    
            if(m_num_char_anim != 0 && m_char_anim)
                    {
                        character->last_anim_time = timeGetTime() / 30;

                        character->
            object.set_anim_set(
                            &m_mesh_anim[character->char_def.mesh_index].anim,
                            m_char_anim[character->action].name,
                            character->last_anim_time);
                    }
                }
            }

            Whenever characters start battling it out, some are sure to die. The controller can
            quickly handle dying NPCs and monsters by removing their respective structures
            from the list. As for PCs though, death can mean the end of the game, so it’s up to
            the main application to handle them. That’s the reasoning behind pc_death, which
            takes a single argument, the pointer to the dying PC:

            virtual void pc_death(sCharacter* character)
            {
            }

            Speaking of characters dying, any time a monster dies, it has a chance of dropping
            an item, as well as all the money it is carrying. Because your main application handles
            all items in the maps, it’s your job to determine when a monster drops an item
            or gold and to add the appropriate item to the map’s list of items. Overriding the
            following two functions will help you out anytime a monster drops something by
            giving you the exact coordinates where the monster perished, the item dropped,
            and the amount of money dropped.

            virtual bool drop_money(float pos_x, float pos_y, float pos_z, long quantity)
            {
              return true;
            }

            virtual bool drop_item(float pos_x, float pos_y, float pos_z, long item_index)
            {
              return true;
            }


            posted on 2007-12-04 16:47 lovedday 閱讀(220) 評論(0)  編輯 收藏 引用

            公告

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關(guān)鏈接

            搜索

            最新評論

            久久国产色av免费看| 亚洲Av无码国产情品久久| 亚洲色婷婷综合久久| 久久综合亚洲欧美成人| 99久久99久久久精品齐齐| 精品久久久久久无码中文野结衣 | 久久精品无码一区二区三区免费| 欧美久久亚洲精品| 亚洲AV日韩精品久久久久久| 久久777国产线看观看精品| 久久精品国产亚洲精品| 久久精品人人做人人爽97| 国产一区二区精品久久岳| 欧美国产成人久久精品| 免费观看成人久久网免费观看| 欧美无乱码久久久免费午夜一区二区三区中文字幕 | 国产Av激情久久无码天堂| 亚洲狠狠综合久久| 久久精品国产日本波多野结衣| 久久综合欧美成人| 精品国产乱码久久久久久呢 | 国产精品美女久久久久网| 深夜久久AAAAA级毛片免费看| 久久精品国产亚洲77777| 热久久最新网站获取| 很黄很污的网站久久mimi色| 久久天堂AV综合合色蜜桃网 | 亚洲欧美国产精品专区久久| 99精品久久精品| 久久精品夜夜夜夜夜久久| 久久无码国产专区精品| 天天综合久久一二三区| 久久99热这里只有精品国产| 久久91精品国产91久久小草| 国内精品九九久久久精品| 午夜欧美精品久久久久久久| 香蕉久久夜色精品国产2020| 亚洲v国产v天堂a无码久久| 国产精品女同一区二区久久| 久久99国产精品99久久| 7国产欧美日韩综合天堂中文久久久久|