C++ 移动代码

我正在用C++和DirectX制作一个游戏。我已经绘制了一个基本的AI。我想让AI在一个正方形中移动,例如:

  • AI沿Z轴向上移动,直到达到25,
  • 然后AI沿X轴移动25,
  • 然后沿Z轴向下移动25,
  • 然后沿X轴向后移动,直到它完成一个正方形的完整移动。

这是我目前拥有的代码;它可以让AI在Z轴上向上移动25,然后在Z轴上向下移动25,重复此过程。

if (ghost_moves_forward == true){    ghost_Z -= ghost_movement;}else if (ghost_moves_forward == false){    ghost_Z += ghost_movement;}if (ghost_Z >= 25){    ghost_moves_forward = true;}if (ghost_Z <= -25){    ghost_moves_forward = false;}

提前感谢。


编辑:

float ghost_X = 0; //使AI沿x轴移动float ghost_Z = 0; // 使AI沿Z轴移动int ghost_movement = 1; // AI移动的速度bool ghost_moves_forward = true; // 当AI向前移动时为true,当其横向移动时为falsebool ghost_moves_sideways = true;// 横向移动时为true,向前移动时为false

我使用 ghost_Xghost_Z 作为AI的平移位置。

D3DXMatrixTranslation( &g_matLocal, ghost_X, 0, ghost_Z );

回答:

假设幽灵从位置 startx, startz 开始

static int square_state = 0;// 从左下角到左上角已完成if(z <= startz-25 && square_state == 0)    square_state = 1;// 从左上角到右上角已完成if(x >= startx+25 && square_state == 1)    square_state = 2;// 从右上角到右下角已完成if(z >= startz && square_state == 2)    square_state = 3;// 从右下角到左下角已完成if(x <= startx && square_state == 3)    square_state = 0;switch(square_state){case 0: // 从左下角到左上角    z -= movement;      break;case 1: // 从左上角到右上角    x += movement;    break;case 2: // 从右上角到右下角    z += movement;    break;case 3: // 从右下角到左下角    x -= movement;    break;}

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注