作者Jedic (什麼都玩什麼都不學壞)
看板Flash
標題Re: [問題] 關於設計遊戲敵人的AI
時間Fri Jul 1 17:23:21 2005
※ 引述《chigayaptt (牧楓蝶)》之銘言:
: 標題: Re: [問題] 關於設計遊戲敵人的AI
: 如果反過來做呢0.0
: 假如主角的攻擊函數
: 會增加一把劍砍人
:
: 那在敵人的身上 寫上 碰到劍後 就自動消失如何
: 平時的主角就不讓他拿武器...
:
: --
: ※ 發信站: 批踢踢實業坊(ptt.cc)
: ◆ From: 222.250.72.7
: 推 kokacal:但是敵人很多的話 不就要寫很多hitTest了嗎?? 218.174.245.222 07/01
: 推 Jedic:敵人應該是用語法產生的,敵人身上的"方法"也同樣是 61.62.226.170 07/01
: → Jedic:例如敵人都用attachMovie("ene","ene"+i,i+10); 61.62.226.170 07/01
: 推 Jedic:可以把hitTest後的function寫在敵人元件裡 61.66.87.212 07/01
今天挺閒所以做了個檔案
我偷懶所以人物用滑鼠拖曳的
http://my.so-net.net.tw/idance/testHittestFunction.fla
http://my.so-net.net.tw/idance/testHittestFunction.swf
語法說明:
//貼上人物
attachMovie("man", "man", 10);
//拖曳功能
man.onPress = function() {
startDrag(this);
};
man.onRelease = function() {
stopDrag();
};
//殺怪分數
killScore = 0;
//怪物流水編號
foeNum = 1;
//產生怪物函式
sendArmy = function () {
_root.attachMovie("foe", "foe"+foeNum, foeNum+10);
//隨機初始座標
_root["foe"+foeNum]._x = 10+random(380);
_root["foe"+foeNum]._y = 10+random(280);
//賦予水平及垂直移動方向參數
_root["foe"+foeNum].xDir = 0;
_root["foe"+foeNum].yDir = 0;
//計數、用來等候
_root["foe"+foeNum].count = 0;
//怪物本身的函式
_root["foe"+foeNum].onEnterFrame = function() {
count += 1;
if (count>=16) {
//隨機決定移動方向
this.xDir = random(2);
this.yDir = random(2);
//化為可計算的數字
if (this.xDir == 0) {
this.xDir = -1;
}
if (this.yDir == 0) {
this.yDir = -1;
}
//歸零
count = 0;
}
//怪物移動
this._x = this._x+this.xDir;
this._y = this._y+this.yDir;
//碰撞偵測
if (this.hitTest(_root.man)) {
//貼上刀閃光
this.attachMovie("flashLight", "flashLight", 1);
this.flashLight._x = -5;
this.flashLight._y = -5;
//播放被斬開畫面
this.gotoAndPlay(2);
//刀閃光本身的函式
this.flashLight.onEnterFrame = function() {
//將父層的怪物alpha值遞減,也會影響到自己
this._parent._alpha-=10;
//判斷自己是否播到最後一格,是則移除怪物
if (this._currentframe>=this._totalframes) {
this._parent.removeMovieClip();
}
};
//殺怪加分
_root.killScore += 1;
//100分就停止生怪
if (_root.killScore>=100) {
clearInterval(AInterval);
}
//碰撞發生過一次之後就刪除掉怪物本身所帶有的函式
//以免重複作反應
delete this.onEnterFrame;
}
//怪物的流水編號加一,實體名稱才不會重複
foeNum += 1;
};
};
//開始依間隔時間執行生怪函式
AInterval = setInterval(sendArmy, 1000);
--
宮本武藏的必勝心法:
一、誠心為思想之本。二、忘我以求道。三、遍習諸藝。
四、廣涉百業之道。五、了解諸事的利弊得失。六、培養辨別事物的眼光。
七、洞悉肉眼不可見之事。八、留心細節小事。九、不做無功效之事。
※ 編輯: Jedic 來自: 61.66.87.212 (07/01 17:46)
推 chigayaptt:推文1號...把一些動作遊戲的要領都寫出來了 211.23.218.203 07/01
推 ppcat:推文2號...暑假來研究研究^_^" 140.116.117.1 07/01
推 kokacal:感恩再感恩 馬上來研究一下!218.174.245.222 07/01
推 youkou:好文,推 218.175.195.41 07/01
推 joeful6:帥呀! 推~ 140.117.201.11 07/03
推 gpmm:推薦這篇文章! 219.84.154.155 07/03
推 allenwang15:偶然找到的 這篇真棒! 09/05 11:30