C 太空入侵者运动
C++ Space Invaders Movement
我真的是C 的新手,而且很糟糕,但我正在为我的大学项目制作太空入侵者游戏。我在外星人运动系统方面遇到了麻烦,以及如何使外星人在一条线上产卵(一旦他们到达屏幕的一面,它们就向下移动,然后越过)。
首先,这是我用来移动外星人运动的代码
if (currentSpritePos.x < 975 || currentSpritePos.x > 0)
{
this->AlienVelocity.x = this->AlienVelocity.x*-1;
}
if (currentSpritePos.x == 0)
{
cout << "Im at the wall wooo and going to move down";
//AlievVelocity.x*+1;
setSpritePos({ 0, 75 });
}
我可以让外星人向左移动并向下移动,但是由于某些原因,我没有向右移动,我评论了" Alienvelocity.x* 1",我认为这会让它们变得正确,因为" -1"使他们向左走...
要让外星人在一条线上产生我制作的数组并设置了两个外星人,因此仅用于测试目的。
for (int aly = 0; aly < 2; aly++) // Change the 35 to number of desired aliens
{
theAliens.push_back(new cAliens);
theAliens[aly]->setSpritePos({ (100, 50) + 200 });
theAliens[aly]->setSpriteTranslation({ 0, 0 });
theAliens[aly]->setTexture(theTextureManager->getTexture("alien"));
theAliens[aly]->setSpriteDimensions(theTextureManager->getTexture("ship")->getTWidth(), theTextureManager->getTexture("alien")->getTHeight());
}
在侧面的第二行上,我将" 200 "放置在语句中,因为我认为这只会将下一个外星人 200点放置,但显然不是。我不确定如何解决此问题...
if (currentSpritePos.x < 975 || currentSpritePos.x > 0)
{
this->AlienVelocity.x = this->AlienVelocity.x*-1;
}
此代码说,每当外星人在0到975之间以扭转速度。我相信这与您想要的完全相反。这意味着他们应该来回走动,永远不要在屏幕上移动。交换比较符号。
为了向下移动,占据当前的位置并将行长添加到其上,应在速度相反时进行此操作 - 在同一if语句中。
。从这些更改开始,看看您是否可以找出其余的。
相关文章:
- 粒子系统:所有粒子都朝同一方向运动
- 如何组合许多连续的图像来模拟逼真的运动模糊?
- 太空入侵者 – 2D 矢量运动算法
- 在虚幻引擎中使用运动控制器组件,C++而不是蓝图
- OpenCV的卡尔曼滤波器过渡矩阵如何处理时间(如t和t^2)进行运动预测?
- 如何使用OpenCV作为运动检测器(而不是寻找视频输出)
- 一维阵列的运动检测(神经网络或其他选项?
- 使用带有 PIR 传感器的米利斯检测连续运动
- 在 GTKMM 中捕捉鼠标运动
- C++编译错误是由于使用 std::move 时运动构造函数与其他非运动构造函数之间的冲突
- 在何处更改参考代码以从 HEVC 编码的视频中提取运动矢量
- C++ SFML 精灵运动无法按预期工作
- 编码域中的DCT系数和运动矢量提取
- 视觉C SDL2圆形运动
- setCursor()有时在鼠标快速运动中失败
- 用C++睡眠特定的鼠标运动
- SDL 乒乓球运动错误
- SFML意外的SF ::顶点运动
- 地牢爬网游戏,运动机械问题
- C 太空入侵者运动