青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當自強而不息

游戲中物件的定義與使用(2)

 

本篇是游戲中物件的定義與使用(1)的續篇。

 

因為每個物件都被分類以便與另外的物件區分開來,所以并不是所有的信息都是必須的,劍具有殺傷力,而護甲則提供保護,因此沒有必要去混合損傷與防御的數據。

需要將每個物件進行分類,以便游戲引擎可以使用它們,每種類別的物件都被加以編號(1是武器,2是護甲,以此類推)。每種類型都有一個相關的價值,如物件的等級指數(攻擊或防御)、特定用途、治愈值或損傷值,以及一個附屬的腳本。是的,物件可以使用腳本增強它們的能力。除了所附屬的腳本外,還可以使用一個變量去表示所有的值,如等級指數、治愈值等。

TIP

You can use an enumerator value to represent the categories in the sItem structure:

enum ItemCategories { WEAPON=0,ARMOR,SHIELD,HEALING,OTHER };

游戲中的每個物件都是有價值的,為每個物件指定一個貨幣價值可以幫助玩家在購買或出售物件時確定它的價格,相同的物件售出的價格通常比購買的價格稍低。

有時并不希望玩家能夠出售某件物品,例如一個非常重要的魔術物件。一個標志位就能夠起到這樣的作用,而且還可以添加其他更多的標志位。

將每個標志表示為一個enum數值(最多32個標志),設置、清除、或檢查一個標志,可以使用隨后的宏(在宏的使用中,v代表物件的標志變量,而f代表了該標志):

enum {
  SELLABLE = 0, // Bit 0
  CANDROP, // Bit 1
  USEONCE, // Bit 2
  UNKNOWN // Bit 3
};

#define SetItemFlag(v,f) (v |= (1 << f))
#define ClearItemFlag(v,f) (v &= ~(1 << f))
#define CheckItemFlag(v,f) (v & (1 << f))

// Example using macros and flags
long ItemFlags = 0;

// Set item flags to sellable and item can be dropped
SetItemFlag(ItemFlags, SELLABLE);
SetItemFlag(ItemFlags, CANDROP);

// Check if the item is dropable and display a message
if(CheckItemFlag(ItemFlags, CANDROP))
  MessageBox(NULL, “Can Drop Item”, “Item”, MB_OK);

ClearItemFlag(ItemFlags, SELLABLE); // Clear sellable flag

 

使用限制

游戲中的某些角色可能不能使用某個特定的物件。例如一個魔法師,他不可能揮舞一把巨大的戰斧,而一個野蠻人則不可能施展法術。在這種情況下,特定的角色只能被允許去使用特定的物件,所以需要指定角色類別的使用限制。

NOTE

A character class is a classification or grouping of characters based on their race or profession. For example,
all humans belong to the same class, but to be more specific, human fighters are considered a
separate class from human wizards (or just fighters and wizards—who says they all have to be human).

To represent the usage restrictions of an item, another variable is introduced to the
sItem structure, one that tracks 32 bits of information. Each bit represents a single
class, which means that you can track up to 32 classes. If an item is usable by a certain
class, that respective bit is set; if an item is restricted in use by the character’s
class, the appropriate bit is cleared.


Here’s the addition to the sItem structure, which handles usage restrictions:


long Usage; // Usage restrictions
// ... other sItem data


To make setting, clearing, and retrieving a usage restriction class bit easier, you can
use the following macros (v represents the flag variable, and c is the class number
ranging from 0 to 31):

#define SetUsageBit(v,c) (v |= (1 << c))
#define ClearUsageBit(v,c) (v &= ((~(1 << c))
#define CheckUsageBit(v,c) (v & (1 << c))

// Examples using macros
long Flags = 0;

SetUsageBit(Flags, 5); // Set class 5 bit

if(CheckUsageBit(Flags, 5)) // Check class 5 bit
      MessageBox(NULL, “Usage Set”, “Bit”, MB_OK);

ClearUsageBit(Flags, 5); // Clear class 5 bit


Using the preceding macros (SetUsageBit, ClearUsageBit, and CheckUsageBit), you can
quickly check whether a character is allowed to use or equip the item based on his
character class. For example, this game places wizards in class 1 and fighters in
class 2. When the wizard tries to equip a broadsword (one that has the class 1 bit
clear), the game engine informs the player that the wizard cannot use the item.

為了使物件能夠更加靈活通用,可以為物件附上腳本。無論是使用療傷藥,或是在戰斗中使用劍,或者玩家啟用了某種特定的物件(例如使用魔杖),每當一個物體被使用時,它的腳本也被觸發。

最終的物件結構定義如下:

enum ItemCategories
{
    MONEY = 0,
    WEAPON,
    ARMOR,
    SHIELD,
    ACCESSORY,
    EDIBLE,
    HEALING,
    COLLECTION,
    TRANSPORTATION,
    CONTAINER,
    OTHER 
};

#define set_bit(v, c)   ((v) |= (1 << (c)))
#define clear_bit(v, c) ((v) &= ~(1 << (c)))
#define check_bit(v, c) ((v) & (1 << (c)))

enum 
{
    SELLABLE = 0,   
// bit 0
    CANDROP,        // bit 1
    USEONCE,        // bit 2
    UNKNOWN         // bit 3
};

typedef 
struct sItem
{
    
char    name[32];               // a short name for the item
    char    desc[128];              // a desciption of item
    float   weight;                 // weight (in lbs.)
    float   size;                   // size (in cubic feet)
    long    category;               // category of item
    long    value;                  // modifier, health increase, etc.
    long    price;                  // buying price of item
    long    flags;                  // item bit flags
    long    usage;                  // usage restrictions

    
char    script_filename[16];    // .mls script filename
    char    mesh_filename[16];      // .x mesh filename
    char    image_filename[16];     // .bmp image filename
} *sItemPtr;

 

With the complete sItem structure in place, it’s time to get back to building the
sword item. Say that the sword item uses a +10 modifier on damage (which means
that you add 10 to the damage factor in combat). The sword normally sells for 200
monetary units in the game, and only fighter classes (class two) can use it:


// Character class definitions
#define WIZARD 1
#define WARRIOR 2

sItem Sword = {
  “Sword”, “A big heavy sword”, // name and description
    5.0f, 4.0f, // weight and size
    WEAPON, 200, SELLABLE | CANDROP, // category, price, and flags
   (1 << WARRIOR), // usage class 2 (warrior)
 “”, “Sword.x”, “Sword.bmp” // Script, mesh, image files
};


Now that the sword item is defined, you can use it in the game. But what good is a single
item? Your game world is going to be packed with items! How can you possibly deal with all
those objects?

 

主物件列表

游戲中的每個物件都需要被定義,同時為了使事情保持簡潔,需要在主物件列表(master item list,MIL)中記錄所有物件的描述。可以將MIL想象成一個物件的目錄,如下圖所示,每個物件都進行編號以便引用,同時每種物件僅顯示一個。

每當需要一個新物件時,或者需要檢索指定物件的屬性特征時,可以搜索MIL。在一個基本的層面上,游戲的MIL可以被存儲為sItem結構的數組,或一個順序文件,它由物件結構的列表所組成,如下圖所示:

 

構造MIL

The following code bit creates a small item structure that contains the item’s name,
weight, and size. You will use this structure to construct a simple MIL:


typedef struct sItem
{
    char Name[32]; // Name of item
    float Weight; // Weight (in lbs.)
    float Size; // Size (in cubic ft.)
};

From here, say that you want to store five items in the MIL, all represented in an
array of sItem structures:

sItem Items[5] = {
   { “Big Sword”, 5.0f, 4.0f },
   { “Small Sword”, 2.0f, 2.0f },
   { “Magic Wand”, 0.5f, 1.0f },
   { “Rock”, 1.0f, 0.5f },
   { “Potion”, 0.5f, 0.5f }
};

Now that you have defined your MIL (using an array of sItem structures), you may want
to save the list out to a file for later retrieval. Such is the case if you are using a separate
program that creates the MIL file for you, much like the program you’ll see in the
upcoming section, “Using the MIL Editor.” As for here, take a look at the following bit
of code that will create a file (called items.mil) and save the Items array to the file:


FILE *fp=fopen(“items.mil”, “wb”);

for(short i=0;i<5;i++)
fwrite(&Items[i], 1, sizeof(sItem), fp);

fclose(fp);

 

Although short and to the point, the preceding example for creating a MIL file
is wholly unusable in a real-world application such as a role-playing game. Item
descriptions need to contain much more information, and you could theoretically
work with thousands of items. Doing all that by hand is a waste of time. What you
need is an item editor to help you create and maintain the MIL . . . and, so, behold
the MIL Editor.


posted on 2007-11-06 00:34 lovedday 閱讀(904) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            黄色国产精品| 最新日韩中文字幕| 国产精品高清在线| 欧美视频日韩视频| 国产精品久久久久久久电影| 99精品视频免费全部在线| 亚洲性图久久| 亚洲男人第一av网站| 欧美一区二区三区另类| 久久久久久久久久久久久久一区| 美日韩精品视频| 亚洲国产精品久久久| 亚洲小少妇裸体bbw| 久久久久91| 欧美日韩在线播放| 欧美jjzz| 国产人成一区二区三区影院| 亚洲精品国偷自产在线99热| 亚洲免费婷婷| 性欧美大战久久久久久久免费观看 | 欧美色视频一区| 亚洲免费一级电影| 久久久精品网| 一本一本久久a久久精品综合妖精| 欧美一区二区播放| 久久久久女教师免费一区| 欧美日韩亚洲一区| 久久久www| 欧美二区在线| 欧美日韩亚洲91| 久久精品国产欧美激情| 一级日韩一区在线观看| 欧美成人高清| 亚洲欧美在线免费观看| 99热免费精品在线观看| 欧美激情综合色综合啪啪| 一区二区三区在线免费观看| 久久国产精品高清| 性欧美办公室18xxxxhd| 99国产精品国产精品久久| 在线亚洲欧美专区二区| 国产精品啊v在线| 亚洲午夜91| 久热精品在线视频| 亚洲国产精品久久| 欧美成人精品在线视频| 亚洲视频中文字幕| 亚洲全黄一级网站| 亚洲欧洲精品一区二区三区不卡 | 欧美日韩欧美一区二区| 久久天天综合| 久久黄色级2电影| 国产一区二区黄| 久久久久综合一区二区三区| 久久国产精品毛片| 香蕉久久一区二区不卡无毒影院| 亚洲一区观看| 国内精品久久久久久久影视蜜臀| 美女黄色成人网| 国产日本欧美一区二区三区在线| 亚洲三级毛片| 欧美新色视频| 亚洲精品美女| 亚洲精品乱码久久久久久久久| 欧美一区二区三区精品电影| 国产专区欧美精品| 欧美一区二区三区视频在线| 午夜精品久久久久久久99樱桃| 欧美日韩成人激情| 欧美一区二区网站| 国产精品中文在线| 亚洲第一区色| 国产精品成人免费视频 | 久久国产精品72免费观看| 欧美午夜精品久久久久久浪潮| 亚洲欧洲一区二区三区久久| 亚洲精品欧美激情| 欧美激情视频网站| 99re6这里只有精品| 国产欧美精品xxxx另类| 亚洲一区中文| 久久久亚洲国产美女国产盗摄| 国产日韩欧美高清免费| 亚洲成人在线网| 国产精品一级在线| 久久国产婷婷国产香蕉| 开元免费观看欧美电视剧网站| 欧美人与性禽动交情品| 久久精品一本久久99精品| 国产视频在线一区二区| 久久九九国产精品| 欧美激情亚洲精品| 国产一区二区三区成人欧美日韩在线观看| 亚洲一级在线观看| 久久久噜噜噜久久久| 91久久精品美女高潮| 欧美网站在线观看| 欧美亚洲免费| 亚洲成人资源网| 亚洲一区日韩在线| 欧美激情一区二区三级高清视频| 亚洲精品国产精品国自产观看浪潮| 在线天堂一区av电影| 久久美女性网| 久久久久久久久蜜桃| 在线观看欧美精品| 久久精品99国产精品酒店日本| 欧美大片网址| 亚洲欧美日韩国产一区| 1769国内精品视频在线播放| 亚洲欧美成人在线| 亚洲一区二区三区精品动漫| 国产亚洲成精品久久| 欧美成人黑人xx视频免费观看| 日韩一级网站| 免费久久99精品国产自| 亚洲视频精选在线| 欧美久色视频| 欧美一区二区三区四区在线观看地址| 欧美成在线视频| 欧美一区二区三区免费观看| 99精品99| 狠狠狠色丁香婷婷综合激情| 欧美午夜免费| 欧美激情精品久久久久久蜜臀| 午夜精品久久久久久久99热浪潮| 亚洲欧美日韩在线观看a三区| 亚洲国产美女| 欧美激情亚洲自拍| 久久精品官网| 亚洲欧美综合精品久久成人| 亚洲精品国精品久久99热一| 免费久久99精品国产自| 久久国产精品色婷婷| 在线亚洲欧美| 亚洲三级影院| 亚洲福利国产| 在线免费日韩片| 国产日韩精品电影| 国产精品久久久久免费a∨| 亚洲欧美日韩精品久久亚洲区 | 99精品国产99久久久久久福利| 欧美激情按摩在线| 免费一级欧美片在线播放| 久久久久久久尹人综合网亚洲| 亚洲男人天堂2024| 亚洲视频第一页| 在线亚洲欧美专区二区| 一本色道久久综合精品竹菊 | 欧美午夜精品久久久久久人妖| 欧美激情第9页| 欧美国产另类| 欧美国产激情二区三区| 欧美国产视频一区二区| 欧美77777| 欧美成人免费视频| 欧美激情一区二区三区全黄| 欧美电影在线播放| 欧美日韩国产综合网 | 久久国产色av| 久久精品日产第一区二区| 久久福利电影| 另类天堂视频在线观看| 欧美成人精品在线播放| 欧美肥婆bbw| 欧美精品激情| 国产精品第一区| 国产精品日韩| 美女日韩在线中文字幕| 亚洲一区二区三区成人在线视频精品| 亚洲一区二区伦理| 久久激情五月丁香伊人| 免费欧美日韩| 欧美日韩在线观看视频| 国产精品影视天天线| 黄色成人av网| 亚洲免费激情| 亚洲高清av在线| 99精品国产在热久久婷婷| 亚洲欧美成人| 欧美影院视频| 欧美激情亚洲另类| 亚洲私人影院| 久久亚洲精选| 欧美午夜精品久久久久久人妖 | 欧美激情综合亚洲一二区| 欧美日产国产成人免费图片| 国产精品一区二区黑丝| 亚洲国产精品尤物yw在线观看| 中国av一区| 久久婷婷久久| 9i看片成人免费高清| 久久久亚洲欧洲日产国码αv | 久久综合色播五月| 国产精品久久久久久久久久免费| 国产日韩欧美精品| 亚洲婷婷在线| 欧美肥婆bbw| 性久久久久久久| 欧美日韩国产精品一区二区亚洲|