1、运动模式Pattern MovementoThe 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标准算法Standard AlgorithmoThe standard pattern movement
2、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.标准运动模式算法用预先编好的指令或控制指令存于列表或数组,能够指导计算机控制的人物如何在游戏循环中移动每一步。控制指令数据结构 control instructions data structureControlData double turnRight;/右转 d
3、ouble turnLeft;/左转 double stepForward;/前进 double stepBackward;/后退变量说明turnRight,turnLeft /the number of degrees 角度stepForward,stepBackward /the number of distance units or tiled 长度模式初始化Pattern initializationPattern0.turnRight=0;Pattern0.turnLeft=0;Pattern0.stepForward=2;Pattern0.stepBackward=0;处理模式数组
4、Processing the pattern arrayVoid GameLoop(void)Object.orientation+=PatternCurrentIndex.turnRight;Object.orientation-=PatternCurrentIndex.turnLeft;Object.x+=PatternCurrentIndex.stepForward;Object.x-=PatternCurrentIndex.stepBackward;CurrentIndex+;基于方块的模式运动Pattern Movement in tile-based environmentsoPa
5、ths will be made up of line segments.路径是由一些线段组成。oEach line is only a segment of the overall pattern.每一条线段是整个运动模式的一部分。初始化路径数组Initialize path arraysVoid InitializePathArrays(void)int i;for(i=0;ikMaxPathLength;i+)pathRowi=-1;pathColi=-1;Calculate line segmentVoid ai_Entity:BuildPathSegment(void)int i;i
6、nt nextCol=col;int nextRow=row;int deltaRow=endRow-row;int deltaCol=endCol-col;int stepCol;int stepRow;int currentStep;int fraction;int i;for(i=0;ikMaxPathLength;i+)if(pathRowi=-1)&(pathColi=-1)currentStep=i;break;if(deltaRow0)stepRow=-1;else stepRow=1;if(deltaCol=kMaxPathLength)return;if(deltaColde
7、ltaRow)fraction=deltaRow*2-deltaCol;while(nextCol!=endCol)if(fraction=0)nextRow+=stepRow;fraction=fraction-deltaCol;nextCol=nextCol+stepCol;fraction=fraction+deltaRow;pathRowcurrentStep=nextRow;pathColcurrentStep=nextCol;currentStep+;if(currentStep=kMaxPathLength)return;else fraction=deltaCol*2-delt
8、aRow;while(nextRow!=endRow)if(fraction=0)nextCol=nextCol+stepCol;fraction=fraction-deltaRow;nextRow=nextRow+stepRow;fraction=fraction+deltaCol;pathRowcurrentStep=nextRow;pathColcurrentStep=nextCol;currentStep+;if(currentStep=kMaxPathLength)return;矩形模式Rectangular patternentityList1.InitializaPathArra
9、ys();entityList1.BuildPathSegment(10,3,18,3);entityList1.BuildPathSegment(18,3,18,12);entityList1.BuildPathSegment(18,12,10,12);entityList1.BuildPathSegment(10,12,10,3);entityList1.NormalizePattern();entityList1.patternRowOffet=5;entityList1.patternColOffet=2;Rectangular pattern movementNormalizePat
10、tern functionvoid ai_Entity:NormalizePattern(void)int i;int rowOrigin=pathRow0;int colOrigin=pathCol0;for(i=0;ikMaxPathLength;i+)if(pathRowi=-1)&(pathColi=-1)pathSize=i-1;break;for(i=0;i=pathSize;i+)pathRowi=pathRowi-rowOrigin;pathColi=pathColi-colOrigin;Simple patrolling patternentityList1.Initiali
11、zePathArrays();entityList1.BuildPathSegment(10,3,18,3);entityList1.BuildPathSegment(18,3,10,3);entityList1.NormalizePattern();entityList1.patternRowOffset=5;entityList1.patternColOffset=2;Complex patrolling patternentityList1.BuildPathSegment(4,2,4,11);entityList1.BuildPathSegment(4,11,2,24);entityL
12、ist1.BuildPathSegment(2,24,13,27);entityList1.BuildPathSegment(13,27,16,24);entityList1.BuildPathSegment(16,24,13,17);entityList1.BuildPathSegment(13,17,13,13);entityList1.BuildPathSegment(13,13,17,5);entityList1.BuildPathSegment(17,5,4,2);entityList1.NormalizePattern();entityList1.patternRowOffset=
13、5;entityList1.patternColOffset=2;Complex tile pattern movement初始化模式矩阵Initialize pattern matrixfor(i=0;ikMaxRows;i+)for(j=0;jkMaxCols;j+)patternij=0;Pattern SetupBuildPatternSegment(3,2,16,2);BuildPatternSegment(16,2,16,11);BuildPatternSegment(16,11,9,11);BuildPatternSegment(9,11,9,6);BuildPatternSeg
14、ment(9,6,3,6);BuildPatternSegment(3,6,3,2);Follow pattern matrixvoid ai_Entity:FollowPattern(void)int i,j;int possibleRowPath8=0,0,0,0,0,0,0,0;int possibleColPath8=0,0,0,0,0,0,0,0;int rowOffset8=-1,-1,-1,0,0,1,1,1;int colOffset8=-1,0,1,-1,1,-1,0,1;关于rowOffset,colOffset说明-1,-1-1,0-1,10,-1当前点(row,col)
15、0,11,-11,01,1 j=0;for(i=0;i8;i+)if(patternrow+rowOffseticol+colOffseti=1)if(!(row+rowOffseti)=previousRow)&(col+colOffseti)=previousCol)possibleRowPathj=row+rowOffseti;possibleColPathj=col+colOffseti;j+;i=Rnd(0,j-1);/随机函数 previousRow=row;previousCol=col;row=possibleRowPathi;col=possibleColPathi;实验2 说明o本次实验可以完成上次的实验内容。o已完成上次实验,可以设计运动模式。如矩形、圆或其他模式。编写实验报告。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1