- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
关于rowOffset,colOffset说明
-1,-1 -1,0 -1,1
0,-1
当前点 (row,col)
1,0
0,1
1,-1
1,1
j=0; for(i=0;i<8;i++) if(pattern[row+rowOffset[i]][col+colOffset[i]]==1) if(!(((row+rowOffset[i])==previousRow)&& ((col+colOffset[i])==previousCol))) { possibleRowPath[j]=row+rowOffset[i]; possibleColPath[j]=col+colOffset[i]; j++; } i=Rnd(0,j-1); //随机函数 previousRow=row; previousCol=col; row=possibleRowPath[i]; col=possibleColPath[i]; }
基于方块的模式运动 Pattern Movement in tile-based environments
Paths will be made up of line segments. 路径是由一些线段组成。 Each line is only a segment of the overall pattern. 每一条线段是整个运动模式的一部分。
if(currentStep>=kMaxPathLength) return; if(deltaCol>deltaRow) { fraction=deltaRow*2-deltaCol; while(nextCol!=endCol) { if(fraction>=0) { nextRow+=stepRow; fraction=fraction-deltaCol; }
处理模式数组 Processing the pattern array
Void GameLoop(void) { … Object.orientation+=Pattern[CurrentIndex].turnRight; Object.orientation-=Pattern[CurrentIndex].turnLeft; Object.x+=Pattern[CurrentIndex].stepForward; Object.x-=Pattern[CurrentIndex].stepBackward; CurrentIndex++; … }
Rectangular pattern movement
(10,3) (10,12)
(18,3)
(18,12)
NormalizePattern function
void ai_Entity::NormalizePattern(void) { int i; int rowOrigin=pathRow[0]; int colOrigin=pathCol[0]; for(i=0; i<kMaxPathLength; i++) if((pathRow[i]==-1)&&(pathCol[i]==-1)) { pathSize=i-1; ; break; } for(i=0; i<=pathSize; i++) { pathRow[i]=pathRow[i]-rowOrigin; pathCol[i]=pathCol[i]-colOrigin; } }
Complex patrolling pattern
entityList[1].BuildPathSegment(4,2,4,11); entityList[1].BuildPathSegment(4,11,2,24); entityList[1].BuildPathSegment(2,24,13,27); entityList[1].BuildPathSegment(13,27,16,24); entityList[1].BuildPathSegment(16,24,13,17); entityList[1].BuildPathSegment(13,17,13,13); entityList[1].BuildPathSegment(13,13,17,5); entityList[1].BuildPathSegment(17,5,4,2); entityList[1].NormalizePattern(); entityList[1].patternRowOffset=5; entityList[1].patternColOffset=2;
运动模式 Pattern Movement
The computer-controlled characters move according to some predefined pattern that makes it appear as though they are performing complex, thought-out maneuvers. 计算机控制的人物按照某种预定的运动模式 移动,好像他们执行复杂的、预先想好的策 略执行。 circle、square、zigzag、curve
Follow pattern matrix
void ai_Entity::FollowPattern(void) { int i,j; int possibleRowPath[8]={0,0,0,0,0,0,0,0}; int possibleColPath[8]={0,0,0,0,0,0,0,0}; int rowOffset[8]={-1,-1,-1,0,0,1,1,1}; int colOffset[8]={-1,0,1,-1,1,-1,0,1};
控制指令数据结构 control instructions data structure
ControlData { double turnRight; //右转 double turnLeft; //左转 double stepForward; //前进 double stepBackward; //后退 }
初始化路径数组 Initialize path arrays
Void InitializePathArrays(void) { int iห้องสมุดไป่ตู้ for(i=0; i<kMaxPathLength; i++) { pathRow[i]=-1; pathCol[i]=-1; } }
Calculate line segment
标准算法 Standard Algorithm
The standard pattern movement algorithm uses lists or arrays of encoded instructions, or control instructions, that tell the computer-controlled character how to move each step through the game loop. 标准运动模式算法用预先编好的指令或控制指 令存于列表或数组,能够指导计算机控制的人 物如何在游戏循环中移动每一步。
nextCol=nextCol+stepCol; fraction=fraction+deltaRow; pathRow[currentStep]=nextRow; pathCol[currentStep]=nextCol; currentStep++; if(currentStep>=kMaxPathLength) return; } }
变量说明
turnRight, turnLeft //the number of degrees 角度 stepForward, stepBackward //the number of distance units or tiled 长度
模式初始化 Pattern initialization
Pattern[0].turnRight=0; Pattern[0].turnLeft=0; Pattern[0].stepForward=2; Pattern[0].stepBackward=0;
for(i=0;i<kMaxPathLength;i++) if((pathRow[i]==-1)&&(pathCol[i]==-1)) { currentStep=i; break; } if(deltaRow<0) stepRow=-1; else stepRow=1; if(deltaCol<0) steoCol=-1; else stepCol=1; deltaRow=abs(deltaRow*2); deltaCol=abs(deltaCol*2); pathRow[currentStep]=nextRow; pathCol[currentStep]=nextCol; currentStep++;
else { fraction=deltaCol*2-deltaRow; while(nextRow!=endRow) { if(fraction>=0) { nextCol=nextCol+stepCol; fraction=fraction-deltaRow; }
nextRow=nextRow+stepRow; fraction=fraction+deltaCol; pathRow[currentStep]=nextRow; pathCol[currentStep]=nextCol; currentStep++; if(currentStep>=kMaxPathLength) return; } } }