标签:
今天开始同组员一起开发技能方面的内容,但还未出成果,所以内容较少。
修改了一个小小的bug,关于新建账号出生的人物经验不对的bug。
这是人物初始化函数(构造函数),exp代表经验,一开始写成了exp=maxexp,所以经验有问题。
Player::Player() :tj(1.6,0.2, mapmax / 40.0, mapmax / 20.0){ wx = 1.6; wy = 0.2; movenum = 0; setlv(1); hp = maxhp; exp = 0; fightrange = 0.01; }
我还修改了怪物的移动AI。以前是怪物会移动到和玩家重合,现在改成了进入攻击范围就停下了。
效果图如下:
整个movaAI:
void monster::moveAI() { double dx, dy; int pid; int moveto=5; if (GetnearPlayer(&pid, &dx, &dy) > findenemyrange) { if (movefx == 0) { //站在原地 moveto = random(4); movef = 0; } else { //之前在移动 if (movef <=2) { //向移动方向走的步数小于3步,则继续朝这个方向前进 movef++; if (movefx == 4) moveto = 1; else if (movefx == 2) moveto = 0; else if (movefx == 1) moveto = 2; else if (movefx == 3) moveto = 3; else moveto = 4; } else { //否则随机 movef = 0; moveto = random(15); //临时存储 if (moveto <= 6) { //1/2几率继续朝该方向前进 if (movefx == 4) moveto = 1; else if (movefx == 2) moveto = 0; else if (movefx == 1) moveto = 2; else if (movefx == 3) moveto = 3; else moveto = 4; } else { //1/2几率随机方向移动或者停止 moveto = random(6); } } } switch (moveto) { case 0: movedown(movespeed); movefx = 2; break; case 1: moveup(movespeed); movefx = 4; break; case 2: moveleft(movespeed); movefx = 1; break; case 3: moveright(movespeed); movefx = 3; break; default: movefx = 0; sprintf(buffer, "MG %d %d %d %lf %lf %lf", curmap->id, id, 0, wx, wy, hp); GengXinMonster(buffer); break; } } else if (GetnearPlayer(&pid, &dx, &dy) < 0.06) { } else { if (abs(dx) >=abs(dy)) { if (dx < -movespeed) { if (moveleft(movespeed)) { } else { if (dy < -movespeed) { if (movedown(movespeed)) { } } else if (dy >movespeed) { if (moveup(movespeed)) { } } } } else if (dx > movespeed) { if (moveright(movespeed)) { } else { if (dy < -movespeed) { if (movedown(movespeed)) { } } else if (dy >movespeed) { if (moveup(movespeed)) { } } } } } else{ if (dy < -movespeed) { if (movedown(movespeed)) { } else { if (dx < -movespeed) { if (moveleft(movespeed)) { } } else if (dx > movespeed) { if (moveright(movespeed)) { } } } } else if (dy >movespeed) { if (moveup(movespeed)) { } else { if (dx < -movespeed) { if (moveleft(movespeed)) { } } else if (dx > movespeed) { if (moveright(movespeed)) { } } } } } } }
在整个moveAI中加入下面这段,只要距离足够近就啥也不做。
else if (GetnearPlayer(&pid, &dx, &dy) < 0.06) { }
标签:
原文地址:http://www.cnblogs.com/Dmmuistirci/p/5641223.html