作者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)
1F:推 chigayaptt:推文1号...把一些动作游戏的要领都写出来了 211.23.218.203 07/01
2F:推 ppcat:推文2号...暑假来研究研究^_^" 140.116.117.1 07/01
3F:推 kokacal:感恩再感恩 马上来研究一下!218.174.245.222 07/01
4F:推 youkou:好文,推 218.175.195.41 07/01
5F:推 joeful6:帅呀! 推~ 140.117.201.11 07/03
6F:推 gpmm:推荐这篇文章! 219.84.154.155 07/03
7F:推 allenwang15:偶然找到的 这篇真棒! 09/05 11:30