創作內容

0 GP

一次製作151個怪物(親子關係)

作者:moNo│2009-02-08 11:02:55│巴幣:0│人氣:643
如果說你要做一個大型的遊戲

那麼你可能會需要做151隻以上的怪物

一隻隻的設定,實在是很恐怖的一件事情

或許有人可以靠script(腳本)解決這個問題.

不過,你可能不會使用很複雜的script.

那該怎麼辦呢?


不好意思,請你手動把他們全部設定吧(揍


以上是廢話.

總之,如果有太多的object(物件)要使用類似的事件.

那麼把它們設定親子關係是滿方便的.

這段說明截取自說明書:

Every object can have a parent object. When an object has a parent, it inherits the behavior of the parent. Stated differently, the object is a sort of special case of the parent object. For example, if you have 4 different balls, named ball1, ball2, ball3 and ball4, which all behave the same but have a different sprite, you can make ball1 the parent of the other three. Now you only need to specify events for ball1. The others will inherit the events and behave exactly the same way. Also, when you apply actions to instances of the parent object they will also be applied to the children. So, for example, if you destroy all ball1 instances the ball2, ball3, and ball4 instances will also be destroyed. This saves a lot of work.
Often, objects should behave almost identically but there will be some small differences. For example, one monster might move up and down and the other left and right. For the rest they have exactly the same behavior. In this case almost all events should have the same actions but one or two might be different. Again we can make one object the parent of the other. But in this case we also define certain events for the child object. These events "override" the parent events. So whenever an event for the child object contains actions, these are executed instead of the event of the parent. If you also want to execute the parent event you can call the so-called "inherited" event using the appropriate action.

It is actually good practice in such cases to create one base object. This base object contains all the default behavior but is never used in the game. All actual objects have this base object as parent. Parent objects can again have parents, and so on. (Obviously you are not allowed to create cycles.) In this way you can create an object hierarchy. This is extremely useful to keep your game structured and you are strongly advised to learn to use this mechanism.

There is also a second use of the parent object. It also inherits the collision behavior for other objects. Let us explain this with an example. Assume you have four different floor objects. When a ball hits the floor it must change direction. This has to be specified in the collision event of the ball with the floor. Because there are four different floors we need to put the code on four different collision events of the ball. But when you make one base floor object and make this one the parent of the four actual floor objects, you only need to specify the collision event with this base floor. The other collisions will perform the same event. Again, this saves a lot of copying.

As indicated, wherever you use an object, this also implies the descendants. This happens when, in an action, you indicate that the action must be applied to instances of a certain object. It also happens when you use the with() statement in code (see below). And it works when you call functions like instance_position, instance_number, etc. Finally, it works when you refer to variables in other objects. In the example above when you set ball1.speed to 10 this also applies to ball2, ball3 and ball4.


看不懂怎麼辦?沒關係我也看不懂(揍

這裡是別人的翻譯:

(父物件=parent object 子圖組=sprites 圖例=instance)

每一個物件能有一父物件。當一物件有一父物件,它就繼承這父物件的行為模式。另一種不同的說法,這物件是一種特別的父物件。譬如,假如你有4種不同的球,名叫ball1,ball2,ball3 和ball4,全部有相同的行為但是子圖組不同,你可以將ball1製作成其他的三物件的父物件,現在你只須為ball1設定事件,其他的物件將繼承這事件並會有相同的行為表現。

同樣地,當你把動作加到這父親物件的圖例上的同時,他們也將被加在子物件上,所以,譬如,假如你摧毀全部ball1 的圖例,這ball2,ball3,和ball4 圖例也將被摧毀,這樣節省許多的工作。通常,不同物件總是會有相同的表現,但在一些地方會有小差別,譬如,一怪物可能上下移動,其他怪物則左右移動,除此之外他們有相同行為。在這例子中幾乎全部的事件有相同的動作,只有一兩個可能不同,再一次我們能製作一其他物件的父物件,但是在這個例子,我們也為了這子物件定義了特定的事件,這些事件"覆蓋"這父親事件,那麼當子物件的事件中包含動作時,是代替這父物件的事件來執行這些動作。假如你也想要執行這父事件,使用適當的動作讓你能呼叫所謂的"繼承"事件。父物件能又有父物件,以此類推(很明顯地你不能製造物件循環),這麼來你能創造一物件階層。這是相當有用以保持你的遊戲結構化,強烈建議你學習使用這功能。

父物件還有第二種用法,它也繼承了碰撞行為到其他的物件上。讓我舉一例子來解釋,假定你有四個不同的地板物件,

當一個球擊中這地板則它必須改變方向,在球與地板的碰撞事件中必須詳盡地規定,因為有四種不同地板,故我們需要把程式碼放在球物件中四個碰撞事件內。但是當你使一地板物件成為其他的三地板的父物件時,你只須規定這一地板物件(父物件)的碰撞事件就好了,其他(與不同地板)的碰撞將執行這相同事件。再一次,又節省了許多的複製。

如同前述,無論何時當你使用一物件,也暗指了子物件。在一動作中,這發生於當你指定一個動作必須用在特定的物件圖例中。它也發生於當你在程式碼中使用這with ()敘述式 (看下面)。當你呼叫函式如instance_position,instance_number,等等同樣是有效的。最後,它能被用在當你在其他的物件中指定變數。在上述例子裏,當你設定ball1。速度為10,同樣地ball2,ball3 和ball4也得到相同速度。


總之重點是:
每個object都可以有一個parent object.當一個object有親物件的時候,他會繼承所有親物件的行為.


所以可以用這種方法來做出比較簡單的設定.

假設你要設定151隻怪物

那你只要用一個親子關係把151隻怪物給連結

就可以讓他們都有類似的行為了.

剩下的就是微調能力差異就好.


以上
引用網址:https://home.gamer.com.tw/TrackBack.php?sn=607336
All rights reserved. 版權所有,保留一切權利

相關創作

同標籤作品搜尋:|遊戲設計|

留言共 4 篇留言

白 ㄘ
我頭要炸開了XD

05-04 21:13

moNo
呵呵,真抱歉

有空會把它整理的比較簡單易懂.502705-11 14:18
假認真魔人
基本上,一個遊戲需要151種怪物,本身就已經是有點失敗的設定了

即使是大型MMORPG,會磨人到這種程度的,也不多,更不可能把151支都丟給一個人設計

05-23 16:20

口舌無益
神奇寶貝是失敗的設定嗎ˊˋ

05-27 08:25

夜下月
弄懂OO的概念就知道怎麼設計了
首先可以定義怪物這個Basic類別必定有的行為(ex. 移動,攻擊),
再來設計不同類別的怪物(ex.會飛的, 水中的, 陸上的), 一樣賦予這些類別群組各自的必要行為,
最後設計類群組中的結果(ex. 怪物-陸上-史萊姆, 怪物-水中-大章魚)

依照這樣的設計方法, 要做出上千種怪物, 其實也很簡單.

而回應上面"一個遊戲需要151種怪物,本身就已經是有點失敗的設定了"
對遊戲的世界觀來說, 怪物只是反映這個世界的產物, 而越豐富的世界, 怪物種類自然越多.
並且大型MMORPG也常常會超過151種怪物,只是他們會用相似怪物去增加怪物種類(ex. 黃金史萊姆/臭酸史萊姆)

而如何設計一個好的怪物結構,就是企畫與程式人員必須思考的了:)

07-09 04:06

我要留言提醒:您尚未登入,請先登入再留言

喜歡★a020118409 可決定是否刪除您的留言,請勿發表違反站規文字。

前一篇:英文有毒....?(不重... 後一篇:使用控制物件(翻譯版)...

追蹤私訊切換新版閱覽

作品資料夾

mine0rain各位好!!
耶穌的店?God damn!看更多我要大聲說昨天18:55


face基於日前微軟官方表示 Internet Explorer 不再支援新的網路標準,可能無法使用新的應用程式來呈現網站內容,在瀏覽器支援度及網站安全性的雙重考量下,為了讓巴友們有更好的使用體驗,巴哈姆特即將於 2019年9月2日 停止支援 Internet Explorer 瀏覽器的頁面呈現和功能。
屆時建議您使用下述瀏覽器來瀏覽巴哈姆特:
。Google Chrome(推薦)
。Mozilla Firefox
。Microsoft Edge(Windows10以上的作業系統版本才可使用)

face我們了解您不想看到廣告的心情⋯ 若您願意支持巴哈姆特永續經營,請將 gamer.com.tw 加入廣告阻擋工具的白名單中,謝謝 !【教學】